Detecting when streams end and a subscriber's video is disabled
In this guide you will learn to detect when a stream ends. This allows you to perform any clean ups within your application as well as show your user any secondary screen, notifications etc.
When a subscriber's video is disabled, the OTSubscriber object dispatches a videoDisabled event:
When the Media Router disables the video of a subscriber, you may want to adjust the user interface related to the subscriber.
The reason property of the videoDisabled event object defines the reason the video was disabled. This can be set to one of the following values:
"PublisherPropertyChanged"— The publisher stopped publishing video."QualityChanged"— The Media Router stopped sending video to the subscriber based on stream quality changes. This feature of the Media Router has a subscriber drop the video stream when connectivity degrades. (The subscriber continues to receive the audio stream, if there is one.)
Before sending this event, when the subscriber's stream quality deteriorates to a level that is low enough that the video stream is at risk of being disabled, the OTSubscriber objet dispatches a videoDisableWarning event.
If connectivity improves to support video again, the OTSubscriber object dispatches a videoEnabled event, and the subscriber resumes receiving video.
This feature is only available in sessions that use the Media Router (sessions with the media mode set to routed), not in sessions with the media mode set to relayed.
When you publish a stream, you can prevent it from having its video disabled due to stream quality. Set audioFallbackEnabled to false in the properties prop pass into the OTPublisher component.
"SubscriberPropertyChanged"— The subscriber started or stopped subscribing to video, by setting subscribeToVideo to false in the properties prop passed into theOTSubscribercomponent."CodecNotSupported"— The subscriber stopped subscribing to video due to an incompatible codec (see the Video codecs developer guide).
The OTSubscriber object dispatches videoEnabled event when video resumes:
The reason property of the videoEnabled event object defines the reason the video was enabled. This can be set to one of the following values:
"PublisherPropertyChanged"— The publisher resumed publishing video."QualityChanged"— The Media Router resumed sending video to the subscriber based on stream quality changes. This feature of the Media Router has a subscriber drop the video stream when connectivity degrades and then resume the video stream if the stream quality improves.
This feature is only available in sessions that use the Media Router (sessions with the media mode set to routed), not in sessions with the media mode set to relayed.
"SubscriberPropertyChanged"— The subscriber started or stopped subscribing to video, by settingsubscribeToVideoto false in the properties prop passed into the OTSubscriber component."CodecNotSupported"— The subscriber video was enabled after a codec change from an incompatible codec (see the Video codecs developer guide).
When a stream, other than your own, leaves a session the Session object dispatches a streamDestroyed event:
When a stream you publish leaves a session the Publisher object dispatches a streamDestroyed event:
The streamDestroyed event is defined by the StreamEvent class. The event includes a reason property, which details why the stream ended. These reasons include "clientDisconnected", "forceDisconnected", "forceUnpublished", or "networkDisconnected". For details, see StreamEvent.
By default, when a streamDestroyed event is dispatched for a stream you are subscribed to, the corresponding Subscriber objects (there could be more than one) are destroyed and removed from the HTML DOM. You can prevent this default behavior by calling the preventDefault() method of the StreamEvent object:
Note that the getSubscribersForStream() method of a Session object returns all of the Subscriber objects for a Stream.
You may want to prevent the default behavior, and retain the Subscriber, if you want to adjust related DOM elements before deleting the Subscriber yourself. You can then delete the Subscriber object (and its DOM element) by calling the destroy() method of the Subscriber object.
A Subscriber object dispatches a destroyed event when the object has been removed from the HTML DOM. In response to this event, you may choose to adjust (or remove) DOM elements related to the subscriber that was removed.
When streams published by other clients leave a session, the onStreamDropped(Session session, Stream stream) method of the Session.SessionListener object is called. When a stream is dropped, the view for any Subscriber object for the stream is removed from its superview.
Detecting when a subscriber's video is disabled
The Vonage Video Media Router stops sending video to the subscriber when it detects that connectivity degrades. The subscriber continues to receive the audio stream, if there is one. The onVideoDisabled(subscriber, subscriber) method of the SubscriberKit.VideoListener object is called when the Vonage Video Media Router stops sending video:
The reason parameter identifies the reason the subscriber stopped streaming video.
When the Vonage Video Media Router disables the video of a subscriber, you may want to adjust the user interface related to the subscriber.
The onVideoEnabled(subscriber, reason) method of the SubscriberKit.VideoListener object is called when the video resumes:
The reason parameter identifies the reason the subscriber's video resumed.
When you publish a stream, you can prevent it from having its video disabled due to stream quality. Before calling the Session.publish(publisher) method, call the setAudioFallbackEnabled(boolean enabled) method of the Publisher object (or PublisherKit object) and pass in false.
When streams leave a session, the OTSession session(_:streamDestroyed:) message is sent. When a stream is dropped, the view for any OTSubscriber object for the stream is removed from its superview. Check if the stream is not published by your own client, and remove its view from its superview.
Detecting when a subscriber's video is disabled
The subscriber's delegate sends the OTSubscriberDelegate subscriberVideoDisabled(_:reason:) message when the subscriber's video is disabled:
The reason parameter can be set to one of the following constants defined in the OTSubscriberVideoEventReason enum:
OTSubscriberVideoEventPublisherPropertyChanged— The video event was caused by the stream's publisher stopping the video stream.OTSubscriberVideoEventQualityChanged— The video event was caused by a change to the video stream quality. Stream quality may change due to network conditions or CPU usage on either the subscriber or publisher. This reason is only used in sessions that have the media mode set to "routed". (See The Vonage Video Media Router and media modes.) This feature of the Vonage Video Media Router has a subscriber drop the video stream when the video stream quality degrades, and the message is sent. When conditions improve, the video stream resumes, and theOTSubscriberDelegate subscriberVideoEnabled(_:reason:)message is sent. When the video stream is dropped, the subscriber continues to receive the audio stream, if there is one.OTSubscriberVideoEventSubscriberPropertyChanged— The video event was caused by a change to this subscriber'sOTSubscriber subscribeToVideoproperty.
If the video stream resumes, the OTSubscriberDelegate subscriberVideoEnabled(_:reason:) message is sent.
When you publish a stream, you can prevent it from having its video disabled due to stream quality. Before calling the OTSession publish(_:error:) method, set the audioFallbackEnabled property of the Publisher object (or PublisherKit object) to false.
The [OTSessionDelegate session:streamCreated:] message is sent when a new stream is created in a session. (A stream is created when a client publishes a stream to the session.) The OTStream object has properties that define the stream. Compare the connection property of the OTStream object with the connection property of the OTSession object to determine whether the stream is one that your client published:
When streams published by other clients leave a session, the the Session object sends a StreamDropped event:
The event arguments object passed into this are defined by the OpenTok.Session.StreamEventArgs class. This class includes a Stream property. Compare this Stream object to the Stream property of each Subscriber object to identify the subscriber for the stream.
Detecting when a subscriber's video is disabled
The Vonage Video Media Router stops sending video to the subscriber when it detects that connectivity degrades. The subscriber continues to receive the audio stream, if there is one. When the Vonage Video Media Router stops sending video, the Subscriber object sends a VideoDisabled event:
When the Vonage Video Media Router disables the video of a subscriber, you may want to adjust the user interface related to the subscriber.
The Subscriber object sends a VideoDisabled event when video resumes:
The on_stream_dropped callback function of the otc_session_callbacks struct is called when another client's stream is dropped from the Vonage Video session. The stream parameter passed into this function is a pointer to an otc_stream struct for the stream. Call the otc_stream_get_id() method, passing in the otc_stream struct, to get the stream ID.
Detecting when a stream's video is disabled
The on_stream_has_video_changed callback function of the otc_session_callbacks struct is called when another client's stream is dropped from the Vonage Video session. The stream parameter passed into this function is a pointer to an otc_stream struct for the stream. Call the otc_stream_get_id() method, passing in the otc_stream struct, to get the stream ID.