Make publisher an optional and nil out in cleanup, so camera access is given up
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.
Code changes:
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.