I am using opentok for web and my issue is how to disconnect from current session. I wanna know the steps in detail.
Thank you.
TokBox Developer Evangelist here.
You can call disconnect
method on the Session
object which is returned by OT.initSession(apiKey, sessionId)
.
If you are publishing and call disconnect
, the streamDestroyed
event will fire letting other participants in the session know that a stream has been destroyed. After this event, the participants will receive a connectionDestroyed
event letting them know that a person has "left" the session. However, from the perspective of the publisher, the sessionDisconnected
event will also fire when the connection is destroyed.
For the streamDestroyed
event dispatched by the Session
object, the default behavior is that all Subscriber objects that are subscribed to the stream are unsubscribed and removed from the HTML DOM. Each Subscriber
object dispatches a destroyed event when the element is removed from the HTML DOM. If you call the preventDefault()
method in the event listener for the streamDestroyed
event, the default behavior is prevented and you can clean up Subscriber objects using your own code. For more information, please see: https://tokbox.com/developer/sdks/js/reference/StreamEvent.html
If you disconnect, you do not need to call the unpublish
method because the SDK will take care of the tear down for you.