Swift

Configure the Vonage Session for Screen Sharing

In your session/video manager:

  1. Create a view to be able to see screensharing working real-time we'll use a simple timer
final class VonageVideoManager: NSObject, ObservableObject {
    @Published var timeStamp: String = "00:00:00.00"
        
    fileprivate let formatter: DateFormatter = {
        let dateFormatter = DateFormatter()
        dateFormatter.dateStyle = .short
        dateFormatter.timeStyle = .long
        return dateFormatter
    }()

    public func setup() {
        Timer.scheduledTimer(withTimeInterval: TimeInterval(1), repeats: true) { [weak self] _ in
            guard let self else { return }
            self.timeStamp = self.formatter.string(from: Date())
        }
        doConnect()
    }
    
    // ...

then assign it in View:

struct ContentView: View {
    @ObservedObject var videoManager = VonageVideoManager()
    
    var body: some View {
        VStack {
            Text(videoManager.timeStamp)
                .background(.red)
                .frame(width: 200, height: 200, alignment: .center)
                .cornerRadius(5.0)
        }
        .task {
            videoManager.setup()
        }
    }
}
  1. Create an OTPublisher with videoType = .screen and audioFallbackEnabled = false.
  2. Assign the custom capturer before publishing:
publisher.videoType = .screen
publisher.audioFallbackEnabled = false

let rootView = UIApplication.shared.rootViewController?.view ?? UIView()
capturer = ScreenCapturer(withView: rootView)
publisher.videoCapture = capturer
publisher.videoCapture?.videoContentHint = .text

session.publish(publisher, error: &error)
  1. Publish the publisher – the screen share stream will be sent to the session.