Detect when streams are created in a session
In this section you will learn how to actively listen for new streams within your Vonage video application.
The Session object dispatches a streamCreated event when a new stream (other than your own) is created in a session. A stream is created when a client publishes a stream to the session. The streamCreated event is also dispatched for each existing stream in the session when you first connect. This event is defined by the StreamEvent, which has a stream property, representing stream that was created:
You can subscribe to any stream. See the next section.
The onStreamReceived(Session session, Stream stream) method of the Session.SessionListener object is called when a stream published by another client is created in a session. (A stream is created when a client publishes a stream to the session or if the stream exists when you connect to the session.)
Add a listener object for this event by calling the setSessionListener(Session.SessionListener listener) method of the Session object:
The OTSessionDelegate session(_ 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 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 the[OTSubscriberKit 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'sOTSubscriberKit.subscribeToVideoproperty.
If the video stream resumes, the [OTSubscriberKit 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 NO.
The Session object sends an StreamReceived event when a stream published by another client is created in a session. (A stream is created when a client publishes a stream to the session or if the stream exists when you connect to the session.)
The on_stream_received callback function of the otc_session_callbacks struct is called when a stream published by another client is created in a session. (A stream is created when a client publishes a stream to the session or if the stream exists when you connect to the session.) See Instantiating an otc_session instance and session-related callbacks.