Suggestions

close search

Add Messaging, Voice, and Authentication to your apps with Vonage Communications APIs

Visit the Vonage API Developer Portal

OpenTok.Session

Represents an Vonage Video API session in which the client is participating. More...

Inherits IDisposable.

Classes

class  ArchiveStartedEventArgs
 Defines arguments for the ArchiveStarted event. More...
class  ArchiveStoppedEventArgs
 Defines arguments for the ArchiveStopped event. More...
class  Builder
 Used to create a Session instance. More...
class  ConnectionEventArgs
 Defines arguments for the ConnectionCreated and ConnectionDroppedevents. More...
class  ErrorEventArgs
 Defines arguments for the Error event. More...
class  MuteForcedEventArgs
 Defines arguments for the MuteForced event. More...
class  SignalEventArgs
 Defines arguments for the Session.Signal event. More...
class  StreamEventArgs
 Defines arguments for the StreamReceived and StreamDropped events. More...

Public Member Functions

 Session (Context context, string apiKey, string sessionId, bool connectionEventsSuppressed=false, Uri apiUrl=null, bool ipWhitelist=false, Uri proxyUrl=null, IceConfig iceConfig=null)
 Creates a Session instance. More...
void Dispose ()
 Disposes of the Session object's resources. More...
void Connect (string token)
 Connects to the Vonage Video API session provided in the Session constructor, using the provided authentication token. More...
void Disconnect ()
 Disconnects from this session. All Subscriber and Publisher instances will be disconnected. More...
void SendSignal (string type, string data, Connection connection=null, bool retryAfterReconnect=true)
 Sends a signal to all clients in the session. More...
void Subscribe (Subscriber subscriber)
 Start receiving and rendering audio-video stream data for the specified subscriber. More...
void Unsubscribe (Subscriber subscriber)
 Stops subscribing (receiving a stream) to a specified subscriber in the session. More...
void Publish (Publisher publisher)
 Starts a Publisher streaming to the session. More...
void Unpublish (Publisher publisher)
 Disconnects the Publisher from the session. More...
void ForceMuteAll (IEnumerable< Stream > excludedStreams=null)
 Forces all publishers in the session (except for those publishing excluded streams) to mute audio. More...
void DisableForceMute ()
 Disables the active mute state of the session. After you call this method, new streams published to the session will no longer have audio muted. More...
void ForceMuteStream (Stream stream)
 Forces the publisher of a specified stream to mute its audio. More...
void SetEncryptionSecret (string secret)
 Sets the end-to-end encryption secret used by all publishers and subscribers. More...

Protected Member Functions

virtual void Dispose (bool disposing)

Properties

Connection Connection [get]
 Returns the Connection corresponding to this client's connection to this Session. More...
Capabilities Capabilities [get]
 Whether the client can only subscribe to streams, or both publish and subscribe to streams, based on the role assigned to the token used to connect to the session. More...

Events

EventHandler Connected
 Sent when the client connects to the Vonage Video API session. More...
EventHandler Disconnected
 Sent when the client disconnects from the Vonage Video API session. More...
EventHandler< ConnectionEventArgsConnectionCreated
 Sent when another client connects to the session. More...
EventHandler< ConnectionEventArgsConnectionDropped
 Sent when another client leaves the session. More...
EventHandler< StreamEventArgsStreamReceived
 Sent when a there is a new stream published by another client in this Vonage Video API session. More...
EventHandler< StreamEventArgsStreamDropped
 Sent when another client stops publishing a stream to this Vonage Video API session. More...
EventHandler< ErrorEventArgsError
 Sent when something goes wrong when connecting or connected to the session. More...
EventHandler< SignalEventArgsSignal
 Called when a signal is received in the session. More...
EventHandler< StreamEventArgsStreamHasCaptionsChanged
 Called when a stream in the session changes between having captions and not having captions. More...
EventHandler< StreamEventArgsStreamHasAudioChanged
 Called when a stream in the session changes between having audio and not having audio. The StreamEventArgs.Stream object represents a snapshot of stream at the time of the callback. More...
EventHandler< StreamEventArgsStreamHasVideoChanged
 Called when a stream in the session changes between having video and not having video. The StreamEventArgs.Stream object represents a snapshot of stream at the time of the callback. More...
EventHandler< StreamEventArgsStreamDimensionsChanged
 Called when the video dimensions of a stream in the session change. The StreamEventArgs.Stream object represents a snapshot of stream at the time of the callback. More...
EventHandler ReconnectionStart
 Sent when the local client has lost its connection to an Vonage Video API session and is trying to reconnect. This results from a loss in network connectivity. More...
EventHandler ReconnectionSuccess
 Invoked when the local client has reconnected to the Vonage Video API session after its network connection was lost temporarily. More...
EventHandler< ArchiveStartedEventArgsArchiveStarted
 Called when an archive of the session starts recording. In response to this method, you may want to add a user interface notification (such as an icon in the Publisher view) that indicates the session is being recorded. More...
EventHandler< ArchiveStoppedEventArgsArchiveStopped
 Called when an archive of the session stops being recorded. In response to this method, you may want to remove a user interface notification (such as an icon in the Publisher view) the session recording has stopped. More...
EventHandler< MuteForcedEventArgsMuteForced
 Called when a moderator forces clients publishing streams to the session to mute audio (the IsActive property of the MuteForcedEventArgs object is set to true), or when a moderator disables the mute audio state in the session (the IsActive property of the MuteForcedEventArgs object is set to false). More...

Detailed Description

Represents an Vonage Video API session in which the client is participating.

The first step in using the Vonage Video API Windows SDK is to instantiate a Session object using the Session.Builder class.

The Session class implements the System.IDisposable interface. Be sure to call the Dispose() method of the Session object to release its resources when you no longer need the object (for example, when the app or window is closing).

See also Session Creation and Token Creation.

Constructor & Destructor Documentation

◆ Session()

OpenTok.Session.Session ( Context  context,
string  apiKey,
string  sessionId,
bool  connectionEventsSuppressed = false,
Uri  apiUrl = null,
bool  ipWhitelist = false,
Uri  proxyUrl = null,
IceConfig  iceConfig = null 
)

Creates a Session instance.

Parameters
contextThe Content object used to manage resources for the Session.
apiKeyYour Vonage Video API key. See the your Vonage Video API account page.
sessionIdThe Vonage Video API session ID this instance should connect to. For test purposes, you can generate test session by logging into your Vonage Video API account. Use the OpenTok server SDKs to generate session IDs in your shipping application.
connectionEventsSuppressedPrevent connection events (such as ConnectionCreated from being dispatched. The default value is false.
apiUrlThis parameter is deprecated. (Its value is ignored.)
ipWhitelistSet this to true if the allowed IP list feature is enabled for your project. (This is available as an add-on feature. The default value is false.
proxyUrlSet this to the URL of the IP proxy server. This is available as an add-on feature. See the OpenTok pricing page and the IP proxy developer guide.
iceConfigThis parameter is used by the configurable TURN feature.

.

See also
Connect(string), Connected

Member Function Documentation

◆ Connect()

void OpenTok.Session.Connect ( string  token)

Connects to the Vonage Video API session provided in the Session constructor, using the provided authentication token.

When the session connects, the Session object sends the Connected event.

If the session fails to connect, the Session object sends the Error event.

Parameters
tokenThe token for the user. See Token Creation Overview.

◆ DisableForceMute()

void OpenTok.Session.DisableForceMute ( )

Disables the active mute state of the session. After you call this method, new streams published to the session will no longer have audio muted.

After you call the ForceMuteAll method (or a moderator in another client makes a call to mute all streams), any streams published after the moderation call are published with audio muted. Call the DisableForceMute() method to remove the mute state of a session (so that new published streams are not automatically muted).

Calling this method causes the Session object in each client connected to the session to send the MuteForced event, with the IsActive property of the MuteForcedEventArgs object to be set to false.

Check the CanForceMute property of the Session.Capabilities object to see if you can call this function successfully. This is reserved for clients that have connected with a token that has been assigned the moderator role (see the Token creation overview).

See Muting the audio of streams in a session.

See also
Capabilities, ForceMuteAll, MuteForced

◆ Disconnect()

void OpenTok.Session.Disconnect ( )

Disconnects from this session. All Subscriber and Publisher instances will be disconnected.

As a best practice, before calling this method, call the Unpublish(Publisher) method for all publishers and wait for the Publisher.StreamDestroyed event. This ensures the complete removal of publishers, especially if network connectivity issues prevent removal due to the reconnection feature, which may keep publisher streams alive for potential reconnection.

When the session disconnects, the Session sends the Disconnected event.

◆ Dispose()

void OpenTok.Session.Dispose ( )

Disposes of the Session object's resources.

◆ ForceMuteAll()

void OpenTok.Session.ForceMuteAll ( IEnumerable< Stream excludedStreams = null)

Forces all publishers in the session (except for those publishing excluded streams) to mute audio.

Also, any streams that are published after the call to the ForceMuteAll() method are published with audio muted. You can remove the mute state of a session by calling the DisableForceMute() method. After you call the DisableForceMute() method, new streams published to the session will no longer have audio muted.

Calling this method causes the Session object in each client connected to the session to send the MuteForced event, with the IsActive property of the MuteForcedEventArgs object to be set to true.

Check the CanForceMute property of the Session.Capabilities object to see if you can call this function successfully. This is reserved for clients that have connected with a token that has been assigned the moderator role (see the Token creation overview).

See Muting the audio of streams in a session.

Parameters
excludedStreamsStreams to be excluded from the mute request. Set this to null (or do not set this parameter) to mute all streams in the session (including those published by the local client).
See also
Capabilities, ForceMuteStream, DisableForceMute(), Session.MuteForced, Publisher.MuteForced

◆ ForceMuteStream()

void OpenTok.Session.ForceMuteStream ( Stream  stream)

Forces the publisher of a specified stream to mute its audio.

Check the CanForceMute property of the Session.Capabilities object to see if you can call this function successfully. This is reserved for clients that have connected with a token that has been assigned the moderator role (see the Token creation overview).

See Muting the audio of streams in a session.

Parameters
streamThe stream to be muted.
See also
Capabilities, ForceMuteAll, Publisher.MuteForced

◆ Publish()

void OpenTok.Session.Publish ( Publisher  publisher)

Starts a Publisher streaming to the session.

Parameters
publisherThe Publisher that you want to stream to the session.

◆ SendSignal()

void OpenTok.Session.SendSignal ( string  type,
string  data,
Connection  connection = null,
bool  retryAfterReconnect = true 
)

Sends a signal to all clients in the session.

Parameters
typeThe type of the signal. The type is set in the SignalEventArgs.Type argument of the Signal event listener.
dataThe data to send. The limit to the size of data is 8kB. The type is set in the SignalEventArgs.Data argument of the Signal event listener.
connection
retryAfterReconnect

◆ SetEncryptionSecret()

void OpenTok.Session.SetEncryptionSecret ( string  secret)

Sets the end-to-end encryption secret used by all publishers and subscribers.

See the End-to-end encryption developer guide.

Parameters
secretValue of the encryption secret.

◆ Subscribe()

void OpenTok.Session.Subscribe ( Subscriber  subscriber)

Start receiving and rendering audio-video stream data for the specified subscriber.

Parameters
subscriberThe subscriber bound to the stream to be received.

◆ Unpublish()

void OpenTok.Session.Unpublish ( Publisher  publisher)

Disconnects the Publisher from the session.

Parameters
publisherThe Publisher to unpublish.

◆ Unsubscribe()

void OpenTok.Session.Unsubscribe ( Subscriber  subscriber)

Stops subscribing (receiving a stream) to a specified subscriber in the session.

Parameters
subscriberThe Subcriber you want to stop subscribing to.

Property Documentation

◆ Capabilities

Capabilities OpenTok.Session.Capabilities

Whether the client can only subscribe to streams, or both publish and subscribe to streams, based on the role assigned to the token used to connect to the session.

◆ Connection

Connection OpenTok.Session.Connection

Returns the Connection corresponding to this client's connection to this Session.

Event Documentation

◆ ArchiveStarted

EventHandler<ArchiveStartedEventArgs> OpenTok.Session.ArchiveStarted

Called when an archive of the session starts recording. In response to this method, you may want to add a user interface notification (such as an icon in the Publisher view) that indicates the session is being recorded.

◆ ArchiveStopped

EventHandler<ArchiveStoppedEventArgs> OpenTok.Session.ArchiveStopped

Called when an archive of the session stops being recorded. In response to this method, you may want to remove a user interface notification (such as an icon in the Publisher view) the session recording has stopped.

◆ Connected

EventHandler OpenTok.Session.Connected

Sent when the client connects to the Vonage Video API session.

◆ ConnectionCreated

EventHandler<ConnectionEventArgs> OpenTok.Session.ConnectionCreated

Sent when another client connects to the session.

The ConnectionEventArgs.Connection object represents the client's connection to the session. Note that this method is invoked when other clients connect to the session. When your own client client connects, the Session sends the Connected event.

◆ ConnectionDropped

EventHandler<ConnectionEventArgs> OpenTok.Session.ConnectionDropped

Sent when another client leaves the session.

The ConnectionEventArgs.Connection object represents the client's previous connection to the session. Note that this method is called when other clients leave the session. When your own client client disconnects, the Session object sends the Connected event.

◆ Disconnected

EventHandler OpenTok.Session.Disconnected

Sent when the client disconnects from the Vonage Video API session.

◆ Error

EventHandler<ErrorEventArgs> OpenTok.Session.Error

Sent when something goes wrong when connecting or connected to the session.

This event is sent if the attempt to connect to the session fails. It is also sent if the connection to the session drops due to an error after a successful connection, and in this case the event is sent just before the Disconnected event is sent.

◆ MuteForced

EventHandler<MuteForcedEventArgs> OpenTok.Session.MuteForced

Called when a moderator forces clients publishing streams to the session to mute audio (the IsActive property of the MuteForcedEventArgs object is set to true), or when a moderator disables the mute audio state in the session (the IsActive property of the MuteForcedEventArgs object is set to false).

◆ ReconnectionStart

EventHandler OpenTok.Session.ReconnectionStart

Sent when the local client has lost its connection to an Vonage Video API session and is trying to reconnect. This results from a loss in network connectivity.

If the client can reconnect to the session, the Session object sends the ReconnectionSuccess event. Otherwise, if the client cannot reconnect, the Session object sends the Disconnected event.

In response to this method being called, you may want to provide a user interface notification, to let the user know that the app is trying to reconnect to the session and that audio-video streams are temporarily disconnected.

See also
ReconnectionSuccess, Disconnected

◆ ReconnectionSuccess

EventHandler OpenTok.Session.ReconnectionSuccess

Invoked when the local client has reconnected to the Vonage Video API session after its network connection was lost temporarily.

When the connection is lost, the Session object sends the Session.ReconnectionStart event, prior to sending the Session.ReconnectionSuccess event. If the client cannot reconnect to the session, the Session object sends the Session.Disconnected event.

Any existing publishers and subscribers are automatically reconnected when the client reconnects and this method is called.

By default, any signals initiated by the local client using the SendSignal(string, string, Connection, bool) method are sent when the client reconnects. To prevent any signals initiated while disconnected from being sent, set the retryAfterReconnect parameter of the SendSignal method to false. (All signals sent by other clients while your client was disconnected are received upon reconnecting.)

See also
ReconnectionStart

◆ Signal

EventHandler<SignalEventArgs> OpenTok.Session.Signal

Called when a signal is received in the session.

◆ StreamDimensionsChanged

EventHandler<StreamEventArgs> OpenTok.Session.StreamDimensionsChanged

Called when the video dimensions of a stream in the session change. The StreamEventArgs.Stream object represents a snapshot of stream at the time of the callback.

◆ StreamDropped

EventHandler<StreamEventArgs> OpenTok.Session.StreamDropped

Sent when another client stops publishing a stream to this Vonage Video API session.

The StreamEventArgs.Stream object represents a snapshot of stream at the time of the callback. It can be used to identify a corresponding Subscriber (if there is one).

◆ StreamHasAudioChanged

EventHandler<StreamEventArgs> OpenTok.Session.StreamHasAudioChanged

Called when a stream in the session changes between having audio and not having audio. The StreamEventArgs.Stream object represents a snapshot of stream at the time of the callback.

◆ StreamHasCaptionsChanged

EventHandler<StreamEventArgs> OpenTok.Session.StreamHasCaptionsChanged

Called when a stream in the session changes between having captions and not having captions.

◆ StreamHasVideoChanged

EventHandler<StreamEventArgs> OpenTok.Session.StreamHasVideoChanged

Called when a stream in the session changes between having video and not having video. The StreamEventArgs.Stream object represents a snapshot of stream at the time of the callback.

◆ StreamReceived

EventHandler<StreamEventArgs> OpenTok.Session.StreamReceived

Sent when a there is a new stream published by another client in this Vonage Video API session.

The StreamEventArgs.Stream object represents a snapshot of stream at the time of the callback. Create a Subscriber and call the Subscribe(Subscriber) method to subscribe to the stream.