Suggestions

close search

OpenTokSDK.OpenTok

Public Member Functions

 OpenTok (int apiKey, string apiSecret)
 OpenTok (int apiKey, string apiSecret, string apiUrl)
Session CreateSession (string location="", MediaMode mediaMode=MediaMode.RELAYED, ArchiveMode archiveMode=ArchiveMode.MANUAL)
string GenerateToken (string sessionId, Role role=Role.PUBLISHER, double expireTime=0, string data=null)
Archive StartArchive (string sessionId, string name="", bool hasVideo=true, bool hasAudio=true, OutputMode outputMode=OutputMode.COMPOSED)
Archive StopArchive (string archiveId)
ArchiveList ListArchives ()
ArchiveList ListArchives (int offset, int count)
Archive GetArchive (string archiveId)
void DeleteArchive (string archiveId)

Properties

int ApiKey [get, set]
string ApiSecret [get, set]
HttpClient Client [get, set]

Detailed Description

Contains methods for creating OpenTok sessions, generating tokens, and working with archives.

To create a new OpenTok object, call the OpenTok API key and the API secret from OpenTok constructor (only on your web server) to create OpenTok sessions.

Constructor & Destructor Documentation

OpenTokSDK.OpenTok.OpenTok ( int  apiKey,
string  apiSecret 
)

Creates an OpenTok object.

Parameters
apiKeyYour OpenTok API key. (See the OpenTok dashboard page.)
apiSecretYour OpenTok API secret. (See the OpenTok dashboard page.)
OpenTokSDK.OpenTok.OpenTok ( int  apiKey,
string  apiSecret,
string  apiUrl 
)

For TokBox internal use.

Member Function Documentation

Session OpenTokSDK.OpenTok.CreateSession ( string  location = "",
MediaMode  mediaMode = MediaMode.RELAYED,
ArchiveMode  archiveMode = ArchiveMode.MANUAL 
)

Creates a new OpenTok session.

OpenTok sessions do not expire. However, authentication tokens do expire (see the generateToken() method). Also note that sessions cannot explicitly be destroyed.

A session ID string can be up to 255 characters long.

Calling this method results in an OpenTokException in the event of an error. Check the error message for details.

You can also create a session using the OpenTok REST API or the OpenTok dashboard.

Parameters
location(String) An IP address that the OpenTok servers will use to situate the session in its global network. If you do not set a location hint, the OpenTok servers will be based on the first client connecting to the session.
mediaModeWhether the session will transmit streams using the OpenTok Media Router (MediaMode.ROUTED) or not (MediaMode.RELAYED). By default, the setting is MediaMode.RELAYED.

With the mediaMode parameter set to MediaMode.RELAYED, the session will attempt to transmit streams directly between clients. If clients cannot connect due to firewall restrictions, the session uses the OpenTok TURN server to relay streams.

The OpenTok Media Router provides the following benefits:

  • The OpenTok Media Router can decrease bandwidth usage in multiparty sessions. (When the mediaMode parameter is set to MediaMode.ROUTED, each client must send a separate audio-video stream to each client subscribing to it.)
  • The OpenTok Media Router can improve the quality of the user experience through audio fallback and video recovery. With these features, if a client's connectivity degrades to a degree that it does not support video for a stream it's subscribing to, the video is dropped on that client (without affecting other clients), and the client receives audio only. If the client's connectivity improves, the video returns.
  • The OpenTok Media Router supports the OpenTok sessions.
Parameters
archiveModeWhether the session is automatically archived (ArchiveMode.ALWAYS) or not (ArchiveMode.MANUAL). By default, the setting is ArchiveMode.MANUAL, and you must call the OpenTok object to start archiving. To archive the session (either automatically or not), you must set the mediaMode parameter to MediaMode.ROUTED.
Returns
A OpenTok session).
void OpenTokSDK.OpenTok.DeleteArchive ( string  archiveId)

Deletes an OpenTok archive.

You can only delete an archive which has a status of "available" or "uploaded". Deleting an archive removes its record from the list of archives. For an "available" archive, it also removes the archive file, making it unavailable for download.

Parameters
archiveIdThe archive ID of the archive you want to delete.
string OpenTokSDK.OpenTok.GenerateToken ( string  sessionId,
Role  role = Role.PUBLISHER,
double  expireTime = 0,
string  data = null 
)

Creates a token for connecting to an OpenTok session. In order to authenticate a user connecting to an OpenTok session, the client passes a token when connecting to the session.

For testing, you can also use the OpenTok dashboard page to generate test tokens.

Parameters
sessionIdThe session ID corresponding to the session to which the user will connect.
roleThe role for the token. Valid values are defined in the Role enum:
  • Role.SUBSCRIBER — A subscriber can only subscribe to streams.

  • Role.PUBLISHER — A publisher can publish streams, subscribe to streams, and signal. (This is the default value if you do not specify a role.)

  • Role.MODERATOR — In addition to the privileges granted to a publisher, in clients using the OpenTok.js 2.2 library, a moderator can call the forceUnpublish() and forceDisconnect() method of the Session object.
expireTimeThe expiration time of the token, in seconds since the UNIX epoch. Pass in 0 to use the default expiration time of 24 hours after the token creation time. The maximum expiration time is 30 days after the creation time.
dataA string containing connection metadata describing the end-user. For example, you can pass the user ID, name, or other data describing the end-user. The length of the string is limited to 1000 characters. This data cannot be updated once it is set.
Returns
The token string.
Archive OpenTokSDK.OpenTok.GetArchive ( string  archiveId)

Gets an Archive object for the given archive ID.

Parameters
archiveIdThe archive ID.
Returns
The Archive object.
ArchiveList OpenTokSDK.OpenTok.ListArchives ( )

Returns a List of Archive objects, representing archives that are both both completed and in-progress, for your API key. This list is limited to 1000 archives starting with the first archive recorded. For a specific range of archives, call listArchives(int offset, int count).

Returns
A List of Archive objects.
ArchiveList OpenTokSDK.OpenTok.ListArchives ( int  offset,
int  count 
)

Returns a List of Archive objects, representing archives that are both both completed and in-progress, for your API key.

Parameters
offsetThe index offset of the first archive. 0 is offset of the most recently started archive. 1 is the offset of the archive that started prior to the most recent archive.
countThe number of archives to be returned. The maximum number of archives returned is 1000.
Returns
A List of Archive objects.
Archive OpenTokSDK.OpenTok.StartArchive ( string  sessionId,
string  name = "",
bool  hasVideo = true,
bool  hasAudio = true,
OutputMode  outputMode = OutputMode.COMPOSED 
)

Starts archiving an OpenTok session.

Clients must be actively connected to the OpenTok session for you to successfully start recording an archive.

You can only record one archive at a time for a given session. You can only record archives of sessions that uses the OpenTok Media Router (sessions with the media mode set to routed); you cannot archive sessions with the media mode set to relayed.

Note that you can have the session be automatically archived by setting the archiveMode parameter of the OpenTok.CreateSession() method to ArchiveMode.ALWAYS.

Parameters
sessionIdThe session ID of the OpenTok session to archive.
nameThe name of the archive. You can use this name to identify the archive. It is a property of the OpenTok client libraries.
hasVideoWhether the archive will record video (true) or not (false). The default value is true (video is recorded). If you set both hasAudio and hasVideo to false, the call to the StartArchive() method results in an error.
hasAudioWhether the archive will record audio (true) or not (false). The default value is true (audio is recorded). If you set both hasAudio and hasVideo to false, the call to the StartArchive() method results in an error.
outputModeWhether all streams in the archive are recorded to a single file (OutputMode.COMPOSED, the default) or to individual files (OutputMode.INDIVIDUAL).
Returns
The Archive object. This object includes properties defining the archive, including the archive ID.
Archive OpenTokSDK.OpenTok.StopArchive ( string  archiveId)

Stops an OpenTok archive that is being recorded.

Archives automatically stop recording after 120 minutes or when all clients have disconnected from the session being archived.

Parameters
archiveIdThe archive ID of the archive you want to stop recording.
Returns
The Archive object corresponding to the archive being STOPPED.

Property Documentation

int OpenTokSDK.OpenTok.ApiKey

The OpenTok API key passed into the OpenTok() constructor.

string OpenTokSDK.OpenTok.ApiSecret

The OpenTok API secret passed into the OpenTok() constructor.

HttpClient OpenTokSDK.OpenTok.Client

For internal use.