session.h

This file includes the type definition for an OpenTok session along with several function declarations useful when dealing with a session.

Data structures: otc_session_capabilities, otc_custom_ice_config, otc_signal_options, otc_session_callbacks

Includes: capabilities.h, config.h, publisher.h, subscriber.h, stream.h

#define ENCRYPTION_SECRET_MINIMUM_LENGTH

#define ENCRYPTION_SECRET_MINIMUM_LENGTH 8

#define ENCRYPTION_SECRET_MAXIMUM_LENGTH

#define ENCRYPTION_SECRET_MAXIMUM_LENGTH 256

typedef otc_session

OpenTok session type definition.

typedef struct otc_session otc_session;

typedef otc_session_settings

OpenTok session settings type definition.

typedef struct otc_session_settings otc_session_settings;

enum otc_session_error_code

Error code enumeration for OpenTok sessions.

This enumeration represents several error codes associated with a session.

Name Value Description
OTC_SESSION_AUTHORIZATION_FAILURE 1004 An invalid API key or token was provided.
OTC_SESSION_BLOCKED_COUNTRY 1026 Unable to connect to the session. Terms of service violation: export compliance.
OTC_SESSION_CONNECTION_DROPPED 1022 The connection to the OpenTok messaging server was dropped.
OTC_SESSION_CONNECTION_FAILED 1006 Connecting to the session failed.
OTC_SESSION_CONNECTION_LIMIT_EXCEEDED 1027 The client tried to connect to a session that has exceeded the limit for simultaneous connections.
OTC_SESSION_CONNECTION_REFUSED 1023 A socket could not be opened to the messaging server. Check that outbound ports 443 and 8080 are accessible.
OTC_SESSION_CONNECTION_TIMED_OUT 1021 The connection timed out while attempting to connect to the session
OTC_SESSION_FORCE_UNPUBLISH_OR_INVALID_STREAM 1535 Invalid stream.
OTC_SESSION_ILLEGAL_STATE 1015 A method has been invoked at an illegal or inappropriate time for this session. For example, attempting to connect an already connected session will return this error.
OTC_SESSION_INTERNAL_ERROR 2000 Thread dispatch failure, out of memory, parse error, etc.
OTC_SESSION_INVALID_SESSION 1005 An invalid session ID was provided.
OTC_SESSION_INVALID_SIGNAL_TYPE 1461 You attempted to send a signal with an invalid type.
OTC_SESSION_NOT_CONNECTED 1010 The session is not connected, and the requested action requires an active session connection.
OTC_SESSION_NO_MESSAGING_SERVER 1503 No messaging server is available for this session.
OTC_SESSION_NULL_OR_INVALID_PARAMETER 1011 A parameter passed in is null or invalid.
OTC_SESSION_PUBLISHER_NOT_FOUND 1113 The publisher is unknown to this session. This is usually the result of attempting to unpublish a publisher that is not associated with the session.
OTC_SESSION_SIGNAL_DATA_TOO_LONG 1413 You attempted to send a signal with a data string that is greater than the maximum length (8KB).
OTC_SESSION_SIGNAL_TYPE_TOO_LONG 1414 You attempted to send a signal with a type string that is greater than the maximum length.
OTC_SESSION_UNABLE_TO_SEND_SIGNAL 1550 Unable to successfully send signal, perhaps because of missing permissions (e.g., a publisher-only token).
OTC_SESSION_STATE_FAILED 1020 The connection timed out while attempting to get the session’s state.
OTC_SESSION_SUBSCRIBER_NOT_FOUND 1112 The subscriber is unknown to this session. This is usually the result of attempting to unsubscribe a subscriber that is not associated with the session.
OTC_SESSION_UNEXPECTED_GET_SESSION_INFO_REPONSE 2001 Unexpected response.
OTC_SESSION_ENCRYPTION_SECRET_MISSING 6000 Tried to join an end-to-end encrypted session without an encryption secret.
OTC_SESSION_INVALID_ENCRYPTION_SECRET 6004 The encryption secret provided to otc_session_set_encryption_secret is invalid.
OTC_SESSION_ENCRYPTION_NOT_ENABLED 6007 An encryption secret was set (see otc_session_set_encryption_secret), but the session was not configured as end-to-end encrypted.

Functions

Name Description
otc_session_new(apikey, session_id, callbacks) → {otc_session *} Creates a new otc_session struct instance.
otc_session_settings_new() → {otc_session_settings *} Creates a new otc_session_settings instance, used to set up advanced session settings.
otc_session_settings_set_connection_events_suppressed(settings, suppress) → {otc_status} Prevent connection events, to support large interactive video sessions.
otc_session_settings_set_custom_ice_config(settings, custom_ice_config) → {otc_status} Enables custom ICE sever configuration.
otc_session_settings_set_proxy_url(settings, proxy_url) → {otc_status} Sets the IP proxy URL.
otc_session_settings_set_ip_whitelist(settings, ip_whitelist) → {otc_status} Pass in OTC_TRUE to have the client use the IP address white list.
otc_session_settings_set_single_peer_connection(settings, enable) → {otc_status} Single Peer Connection (SPC) is a feature that encapsulates all subscriber connections to a single peer connection.
otc_session_settings_set_session_migration(settings, enable) → {otc_status} Enables the session migration feature, allowing the client to remain connected during server rotation.
otc_session_settings_delete(settings) → {otc_status} Deletes an otc_session_settings instance.
otc_session_new_with_settings(apikey, session_id, callbacks, settings) → {otc_session *} Creates a new OpenTok session with advanced settings.
otc_session_delete(session) → {otc_status} Releases resources associated with the session.
otc_session_connect(session, token) → {otc_status} Connects the client to an OpenTok session.
otc_session_disconnect(session) → {otc_status} Disconnects the client from this session.
otc_session_publish(session, publisher) → {otc_status} Starts a publisher streaming to the session.
otc_session_unpublish(session, publisher) → {otc_status} Causes a publisher from a session (causing its stream to stop).
otc_session_subscribe(session, subscriber) → {otc_status} Starts subscribing to (receiving a stream for) a subscriber's audio-video stream in this session.
otc_session_unsubscribe(session, subscriber) → {otc_status} Stops subscribing to (receiving a stream for) a specified subscriber in the session.
otc_session_send_signal(session, type, signal) → {otc_status} Sends a signal to all clients connected to the session.
otc_session_force_mute_all(session, excluded_streams_ids, excluded_streams_len) → {otc_status} Forces all publishers in the session (except for those publishing excluded streams) to mute audio.
otc_session_disable_force_mute(session) → {otc_status} Disables the active mute state of the session.
otc_session_force_mute_stream(session, stream_id_to_mute) → {otc_status} Forces the publisher of a specified stream to mute its audio.
otc_session_force_disconnect(session, connection) → {otc_status} Forces a client to disconnect from the session.
otc_session_send_signal_to_connection(session, type, signal, connection) → {otc_status} Sends a signal to a specific client connected to the session.
otc_session_send_signal_with_options(session, type, signal, signal_options) → {otc_status} Sends a signal to all clients connected to the session, with specified options.
otc_session_send_signal_to_connection_with_options(session, type, signal, connection, signal_options) → {otc_status} Sends a signal to a specific client, with specified options.
otc_session_report_issue(session, issue_description, issue_id) → {otc_status} Report that your app experienced an issue.
otc_session_get_id(session) → {char *} Gets the unique session ID for this session.
otc_session_get_connection(session) → {otc_connection *} Gets the connection object associated with this session.
otc_session_get_capabilities(session) → {struct otc_session_capabilities} Gets the capabilities of the client connecxted to the session.
otc_session_get_user_data(session) → {void *} Gets the user data associated with the session.
otc_session_set_encryption_secret(session, secret) → {otc_status} See the End-to-end encryption developer guide.

otc_session_new(apikey, session_id, callbacks) → {otc_session *}

Creates a new otc_session struct instance. Pass this into the otc_session_connect function to connect to the OpenTok session.

See also otc_session_new_with_settings for initializing a otc_session struct with advanced options.

Important: If you are using the Video API with a Vonage application (instead of an OpenTok project), pass in the application ID (not an OpenTok API key) for this parameter.

Parameters:
Name Type Description
apikey const char * The API key for the OpenTok project. See See your Vonage Video API account page.
session_id const char * The session ID.
callbacks const struct otc_session_callbacks * The otc_session_callbacks structure containing callback functions for events related to the session.
Returns:

The otc_session struct, representing the OpenTok session.

otc_session_settings_new() → {otc_session_settings *}

Creates a new otc_session_settings instance, used to set up advanced session settings. Call the following functions to configure these settings before calling the otc_session_new_with_settings function to create a session with these settings:

  • otc_session_settings_set_connection_events_suppressed — Suppress connection events.
  • otc_session_settings_set_custom_ice_config &mdash Use custom TURN servers.
  • otc_session_settings_set_proxy_url — Configure the IP proxy feature.
  • otc_session_settings_set_ip_whitelist — Enable the IP whitelist feature.
  • otc_session_settings_set_single_peer_connection — Enable the Single Peer Connection feature.
  • otc_session_settings_set_session_migration — Enable the Session Migration feature.
Returns:

otc_session_settings *

otc_session_settings_set_connection_events_suppressed(settings, suppress) → {otc_status}

Prevent connection events, to support large interactive video sessions. This prevents otc_session_callbacks.on_connection_created and otc_session_callbacks.on_connection_dropped callback functions from being invoked when other clients connect to or disconnect from the session. (Also, the OpenTok server does not send these events to the client.) For more information, see Suppressing connection events in the OpenTok developer guides.

Parameters:
Name Type Description
settings otc_session_settings *
suppress otc_bool
Returns:

otc_status

otc_session_settings_set_custom_ice_config(settings, custom_ice_config) → {otc_status}

Enables custom ICE sever configuration. This is part of the configurable TURN feature.

Parameters:
Name Type Description
settings otc_session_settings *
custom_ice_config const struct otc_custom_ice_config *
Returns:

otc_status

otc_session_settings_set_proxy_url(settings, proxy_url) → {otc_status}

Sets the IP proxy URL. See the IP Proxy developer guide.

Parameters:
Name Type Description
settings otc_session_settings *
proxy_url const char *
Returns:

otc_status

otc_session_settings_set_ip_whitelist(settings, ip_whitelist) → {otc_status}

Pass in OTC_TRUE to have the client use the IP address white list. This feature is available as an add-on feature.

Parameters:
Name Type Description
settings otc_session_settings *
ip_whitelist otc_bool
Returns:

otc_status

otc_session_settings_set_single_peer_connection(settings, enable) → {otc_status}

Single Peer Connection (SPC) is a feature that encapsulates all subscriber connections to a single peer connection. The benefits of enabling SPC include reduced OS resource consumption, improved rate control, and, in case of mobile native devices, support for larger sessions.

SPC is disabled by default. When disabled, the session will use Multiple Peer Connection (MPC), where a separate peer connection is established between each endpoint.

Parameters:
Name Type Description
settings otc_session_settings * Pointer to the session settings object.
enable otc_bool Boolean flag to enable (OTC_TRUE) or disable (OTC_FALSE) SPC.
Returns:

otc_status Returns the status of the operation.

otc_session_settings_set_session_migration(settings, enable) → {otc_status}

Enables the session migration feature, allowing the client to remain connected during server rotation. The default value is false (session migration is not enabled). For more information, see Server Rotation and Session Migration.

Parameters:
Name Type Description
settings otc_session_settings * Pointer to the session settings object.
enable otc_bool Boolean flag to enable (OTC_TRUE) or disable (OTC_FALSE) Session Migration.
Returns:

otc_status Returns the status of the operation.

otc_session_settings_delete(settings) → {otc_status}

Deletes an otc_session_settings instance.

Parameters:
Name Type Description
settings otc_session_settings *
Returns:

otc_status

otc_session_new_with_settings(apikey, session_id, callbacks, settings) → {otc_session *}

Creates a new OpenTok session with advanced settings. These include settings for suppressing connection events, custom TURN servers, the IP proxy feature, and the IP whitelist feature.

Parameters:
Name Type Description
apikey const char * The API key for the OpenTok project. See See your Vonage Video API account page.
session_id const char * The session ID.
callbacks const struct otc_session_callbacks * The otc_session_callbacks structure containing callback functions for events related to the session.
settings otc_session_settings * The otc_session_settings struct With advanced settings for the session.

See: : - otc_session_new.

Returns:

The struct, representing the OpenTok session.

otc_session_delete(session) → {otc_status}

Releases resources associated with the session. No callbacks in otc_session_callbacks will be invoked as a result of invoking this method (or afterwards).

Parameters:
Name Type Description
session otc_session * The otc_session instance.
Returns:

otc_status

otc_session_connect(session, token) → {otc_status}

Connects the client to an OpenTok session.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session to connect to.
token const char * The client token for connecting to the session. See Token Creation Overview.
Returns:

Return value indicating either error or success.

otc_session_disconnect(session) → {otc_status}

Disconnects the client from this session. All of the client's subscribers and publishers will also be will be disconnected from the session. As a best practice, before calling this function, call the otc_session_unpublish function for all publishers and wait for the otc_publisher_callbacks#on_stream_destroyed callback. 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.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session to disconnect from.
Returns:

Return value indicating either error or success.

otc_session_publish(session, publisher) → {otc_status}

Starts a publisher streaming to the session.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session to publish to.
publisher otc_publisher * The otc_publisher struct representing the publisher.
Returns:

Return value indicating either error or success.

otc_session_unpublish(session, publisher) → {otc_status}

Causes a publisher from a session (causing its stream to stop).

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session to unpublish from.
publisher otc_publisher * The otc_publisher struct representing the publisher.
Returns:

Return value indicating either error or success.

otc_session_subscribe(session, subscriber) → {otc_status}

Starts subscribing to (receiving a stream for) a subscriber's audio-video stream in this session.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session containing the subscriber's stream.
subscriber otc_subscriber * The otc_subscriber struct representing the subscriber.
Returns:

Return value indicating either error or success.

otc_session_unsubscribe(session, subscriber) → {otc_status}

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

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session containing the subscriber's stream.
subscriber otc_subscriber * The otc_subscriber struct representing the subscriber.
Returns:

Return value indicating either error or success.

otc_session_send_signal(session, type, signal) → {otc_status}

Sends a signal to all clients connected to the session. See otc_session_send_signal_with_options, otc_session_send_signal_to_connection, and otc_session_send_signal_to_connection_with_options. Also see the Signaling overview.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session.
type const char * The optional type string value for the signal.
signal const char * The optional data string value for the signal.
Returns:

Return value indicating either error or success.

otc_session_force_mute_all(session, excluded_streams_ids, excluded_streams_len) → {otc_status}

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 otc_session_force_mute_all function are published with audio muted. You can remove the mute state of a session by calling the otc_session_disable_force_mute function. After you call the otc_session_disable_force_mute function, new streams published to the session will no longer have audio muted.

Calling this function causes the otc_session_callback.on_mute_forced() callback function to be called in each client connected to the session, with the active property of the otc_on_mute_forced_info struct passed into the function set to OTC_TRUE. Also, the otc_publisher_callbacks.on_publisher_mute_forced() callback function is called in each client publishing a muted stream.

Call the otc_session_get_capabilities function to see if the client 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 (see the Token creation overview.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session.
excluded_streams_ids const char * * A pointer to an array of stream ID strings for the streams to be muted. Set this to nullptr to mute all streams in the session (including those published by the local client).
excluded_streams_len const int The length of the excluded stream array.
Returns:

Return value indicating either error or success.

otc_session_disable_force_mute(session) → {otc_status}

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 otc_session_force_mute_all() function (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 otc_session_disable_force_mute function to remove the mute state of a session (so that new published streams are not automatically muted).

Calling this function causes the otc_session_callback.on_mute_forced() callback function to be called in each client connected to the session, with the active property of the otc_on_mute_forced_info struct passed into the function set to OTC_FALSE.

Call the otc_session_get_capabilities function to see if the client 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.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session.
Returns:

Return value indicating either error or success.

otc_session_force_mute_stream(session, stream_id_to_mute) → {otc_status}

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

Calling this function causes the otc_publisher_callbacks.on_publisher_mute_forced() callback function to be called in the client publishing the muted stream.

Call the otc_session_get_capabilities function to see if the client 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 (see the Token creation overview.

Parameters:
Name Type Description
session const otc_session * The otc_session struct representing the OpenTok session.
stream_id_to_mute const char * The stream ID string for the stream to be muted.
Returns:

Return value indicating either error or success.

otc_session_force_disconnect(session, connection) → {otc_status}

Forces a client to disconnect from the session.

While you can use this function to terminate your own connection, calling otc_session_disconnect is simpler. An error is returned if the client's role does not include permissions required to force other users to disconnect. You define a client's role when you create the user token. When a connection is terminated using this function, otc_session_callbacks#on_connection_dropped and otc_publisher_callbacks#on_stream_destroyed callbacks are dispatched in the same way as they would be if the connection had terminated itself using otc_session_disconnect.

Parameters:
Name Type Description
session const otc_session * The otc_session that the connection is part of
connection const otc_connection * The connection to disconnect
Returns:

An error in the event of an error otherwise OTC_SUCCESS

otc_session_send_signal_to_connection(session, type, signal, connection) → {otc_status}

Sends a signal to a specific client connected to the session. See otc_session_send_signal_to_connection_with_options, otc_session_send_signal, and otc_session_send_signal_with_options. Also see the Signaling overview.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session.
type const char * The optional type string value for the signal.
signal const char * The optional data string value for the signal.
connection const otc_connection * The otc_connection struct corresponding to the client to receive the signal.
Returns:

Return value indicating either error or success.

otc_session_send_signal_with_options(session, type, signal, signal_options) → {otc_status}

Sends a signal to all clients connected to the session, with specified options. See otc_session_send_signal, otc_session_send_signal_to_connection, and otc_session_send_signal_to_connection_with_options. Also see the Signaling overview.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session.
type const char * The optional type string value for the signal.
signal const char * The optional data string value for the signal.
signal_options struct otc_signal_options The otc_signal_options struct with options for the signal.
Returns:

Return value indicating either error or success.

otc_session_send_signal_to_connection_with_options(session, type, signal, connection, signal_options) → {otc_status}

Sends a signal to a specific client, with specified options. See otc_session_send_signal, otc_session_send_signal_to_connection, and otc_session_send_signal_with_options. Also see the Signaling overview.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session.
type const char * The optional type string value for the signal.
signal const char * The optional data string value for the signal.
connection const otc_connection * The otc_connection struct corresponding to the client to receive the signal.
signal_options struct otc_signal_options The otc_signal_options struct with options for the signal.
Returns:

Return value indicating either error or success.

otc_session_report_issue(session, issue_description, issue_id) → {otc_status}

Report that your app experienced an issue. You can use the issue ID with the Inspector tool or when discussing an issue with the Vonage Video API support team.

Parameters:
Name Type Description
session struct otc_session * The otc_session struct representing the OpenTok session.
issue_description const char * A description string.
issue_id char * * A pointer to a string that will be set the unique identifier for the reported issue.
Returns:

Return value indicating either error or success.

otc_session_get_id(session) → {char *}

Gets the unique session ID for this session.

Parameters:
Name Type Description
session const otc_session *
Returns:

char *

otc_session_get_connection(session) → {otc_connection *}

Gets the connection object associated with this session.

Parameters:
Name Type Description
session const otc_session * The otc_session struct representing the OpenTok session.
Returns:

The otc_connection instance.

otc_session_get_capabilities(session) → {struct otc_session_capabilities}

Gets the capabilities of the client connecxted to the session. All otc_session_capabilities members are undefined until otc_session_callbacks.on_connected has been called.

Parameters:
Name Type Description
session const otc_session * The otc_session struct representing the OpenTok session.
Returns:

The otc_session_capabilities instance.

otc_session_get_user_data(session) → {void *}

Gets the user data associated with the session. See otc_session_callbacks.user_data.

Parameters:
Name Type Description
session const otc_session * The otc_session struct representing the OpenTok session.
Returns:

A pointer to the user data.

otc_session_set_encryption_secret(session, secret) → {otc_status}

See the End-to-end encryption developer guide.

The session must have been configured as end-to-end encrypted using the server SDK. Whether end-to-end encryption is enabled is only known once the session configuration has been received from the server.

If the session is already known not to be end-to-end encrypted when this function is called, it returns OTC_SESSION_ENCRYPTION_NOT_ENABLED synchronously. In that case any existing publishers and subscribers also receive the corresponding error through their error callbacks and are dropped.

If whether end-to-end encryption is enabled is not yet known (for example, when the secret is set before the session connects), this function succeeds. If the session later turns out not to be end-to-end encrypted, the OTC_SESSION_ENCRYPTION_NOT_ENABLED error is returned synchronously from the subsequent otc_session_publish or otc_session_subscribe call (reported as OTC_PUBLISHER_ENCRYPTION_NOT_ENABLED / OTC_SUBSCRIBER_ENCRYPTION_NOT_ENABLED respectively).

Passing NULL or an empty string as the secret resets (clears) the previously set encryption secret. Resetting the secret is always allowed, even on a session that is known not to be end-to-end encrypted.

Any other secret must be between ENCRYPTION_SECRET_MINIMUM_LENGTH and ENCRYPTION_SECRET_MAXIMUM_LENGTH bytes long when UTF-8 encoded; otherwise OTC_SESSION_INVALID_ENCRYPTION_SECRET is returned.

A new secret takes effect for the publishers and subscribers that are already running, as well as for those created afterwards. Resetting the secret, however, only takes effect for publishers and subscribers created afterwards: those that are already running keep encrypting and decrypting with the previous secret until they are recreated.

Parameters:
Name Type Description
session otc_session * The otc_session struct representing the OpenTok session.
secret const char * Value for the encryption secret, or NULL or an empty string to reset the previously set encryption secret.
Returns:

Return value indicating either error or success. Returns OTC_SESSION_INVALID_ENCRYPTION_SECRET if the secret is neither a reset (NULL or empty) nor of a valid length, and OTC_SESSION_ENCRYPTION_NOT_ENABLED if a non-empty secret is set on a session that is already known not to be end-to-end encrypted.