DalaDev.ScreenCapture (dala_dev v0.0.8)

Copy Markdown View Source

Capture screenshots and record screen video from mobile devices.

Supports:

  • Android devices (via adb screencap / screenrecord)
  • iOS simulators (via xcrun simctl io)
  • iOS physical devices (via idevicescreenshot / idevicerecord)
  • Live screen preview via WebSocket to dala.server

Examples

# Take a screenshot
{:ok, png_data} = DalaDev.ScreenCapture.capture(:"dala_qa@192.168.1.5")
{:ok, path} = DalaDev.ScreenCapture.capture(device, save_as: "screenshot.png")

# Record video (Android: max 3 min, iOS sim: no limit)
{:ok, path} = DalaDev.ScreenCapture.record(device, duration: 30)

# Live preview in browser
DalaDev.ScreenCapture.live_preview(device, port: 5050)

Summary

Functions

Capture a screenshot from a device.

Start a live screen preview stream.

Record screen video from a device.

Types

capture_opts()

@type capture_opts() :: keyword()

device_ref()

@type device_ref() :: DalaDev.Device.t() | node() | String.t()

record_opts()

@type record_opts() :: keyword()

Functions

capture(device_ref, opts \\ [])

@spec capture(device_ref(), capture_opts()) ::
  {:ok, binary() | Path.t()} | {:error, term()}

Capture a screenshot from a device.

Options:

  • :save_as - Path to save the PNG file (returns path instead of binary)
  • :format - :png (default) or :jpeg
  • :scale - Scale factor (0.5 = half size, default: 1.0)

Returns {:ok, png_binary} or {:ok, path} if :save_as is given.

live_preview(device_ref, opts \\ [])

@spec live_preview(
  device_ref(),
  keyword()
) :: {:ok, pid()} | {:error, term()}

Start a live screen preview stream.

Opens a WebSocket server that streams MJPEG frames to connected browsers. The preview URL is printed to the console.

Options:

  • :port - HTTP/WebSocket port (default: 5050)
  • :fps - Frames per second (default: 15)
  • :scale - Scale factor for bandwidth (default: 0.5)

Returns {:ok, pid} of the preview server process.

record(device_ref, opts \\ [])

@spec record(device_ref(), record_opts()) :: {:ok, Path.t()} | {:error, term()}

Record screen video from a device.

Options:

  • :duration - Recording duration in seconds (default: 30)
  • :save_as - Path to save the MP4 file
  • :bitrate - Video bitrate (Android only, default: 4Mbps)

Android limitation: screenrecord has a 3-minute maximum. iOS physical devices: requires idevicerecord from libimobiledevice.