swiftopentok

How to stop tokbox screen sharing in SWIFT


I am working on an IOS application(SWIFT) in which i have used tokbox for screensharing, i am able to share the screen but not able to stop screensharing.

This is the code I have used for screensharing.

 publisher?.videoType = .screen
 publisher?.audioFallbackEnabled = false
 let cap = ScreenCapturer(withView:view)
 publisher?.videoCapture = cap
 session?.publish(publisher, error: &error)

Can anyone guide to stop screensharing in swift.


Solution

  • To stop screen sharing will need to stop the publisher from streaming. To do that you can call:

    [OTSession unpublish:error:]

    More info is available on the Video API guides

    For your case, where you are adding screen sharing to an existing call, you will need to create an additional publisher for the screen sharing rather than editing the existing one. To use the existing publisher it will require the publisher to be reinitialised to switch between publishing a camera feed vs a screen which will stop publishing audio too.

    In addition to creating a new publisher, you need to create a new subscriber for the other user, you can do that in the subscriberDidConnect delegate function on the OTSubscriberDelegate.

    Additionally, you will need to handle the destruction of both the new publisher and subscriber. This will be done in the delegate functions are you using already on the OTSessionDelegate and OTPublisherDelegate.

    I have created a demo app which demonstrates this behaviour.