opentok / opentok-ios-sdk-samples-swift

Sample applications using the OpenTok iOS SDK in Swift
https://tokbox.com/
MIT License
137 stars 65 forks source link

VIDCS-2620: Camera access is not released by the iOS SDK after disconnecting from the session #219

Closed IGitGotIt closed 2 months ago

IGitGotIt commented 2 months ago

Code changes:

  1. Make publisher an optional and nil out in cleanup, so camera access is given up
  2. Session disconnect callback also cleans up Publisher and subscribers

As per OTSession SDK documentation a session publish action "adds" a publisher and an unpublish action "removes" a publisher from the session object. Since the session does not "create" a publisher , it will also not "destroy" it on unpublish. Hence an explicit "nil" assignment is needed in cleanupPublisher function so that camera access is given up in "this" app. Think of adding and removing an object to an array in any programming language code. The removed object is not destroyed implicitly.

If your app re-uses the publisher immediately or it is used to hold onto its view, there is no need to "nil" it out. You can recycle the same publisher object in the next new session.