Swift

Create the Screen Capturer

The Vonage SDK expects a custom video capturer that conforms to OTVideoCapture. Create a new file ScreenCapturer.swift and implement:

  1. Store a reference to the view to capture – even though our app is set up in SwiftUI, the simplest way to do it is with UIView which we will pass to the Capturer, alternatively this can be done with a UIViewRepresentable wrapper.
  2. Render the view periodically – use drawHierarchy(in:afterScreenUpdates:).
  3. Convert to CVPixelBuffer / OTVideoFrame – and pass frames to videoCaptureConsumer.

Capture a view

Copy the full ScreenCapturer.swift implementation from this sample project. It handles:

  • Timer-based capture at ~10 fps
  • Resizing and padding for encoder compatibility
  • CVPixelBuffer creation and OTVideoFrame delivery