# \OpenTokOpenTok

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

To create a new OpenTok object, call the OpenTok() constructor with your OpenTok API key and the API secret from the OpenTok dashboard. Do not publicly share your API secret. You will use it with the OpenTok() constructor (only on your web server) to create OpenTok sessions.

Be sure to include the entire OpenTok server SDK on your web server.

## Summary

Methods
Properties
Constants
generateToken()
createSession()
startArchive()
stopArchive()
getArchive()
deleteArchive()
listArchives()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

File
  OpenTok.php
Package
Class hierarchy
  \OpenTok\OpenTok

## Tags

todo |

## Methods

### generateToken()

    generateToken(string $sessionId, array $options) : string

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

string | $sessionId | The session ID corresponding to the session to which the user will connect.
array | $options | This array defines options for the token. This array include the following keys, all of which are optional: `'role'` (string) — One of the constants defined in the RoleConstants class. The default role is publisher `'expireTime'` (int) — The timestamp for when the token expires, in milliseconds since the Unix epoch. The default expiration time is 24 hours after the token creation time. The maximum expiration time is 30 days after the token creation time. `'data'` (string) — A 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

string —

The token string.

#

## Tags

todo |

### createSession()

    createSession(array $options) : string

Creates a new OpenTok session and returns the session ID, which uniquely identifies the session.

For example, when using the OpenTok JavaScript library, use the session ID when calling the OT.initSession() method (to initialize an 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

array | $options | (Optional) This array defines options for the session. The array includes the following keys (all of which are optional): `'mediaMode'` (String) — Whether the session will transmit streams using the OpenTok Media Router (`MediaMode.ROUTED`) or not (`MediaMode.RELAYED`). By default, the `mediaMode` property is set to `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 audio-video 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 Intelligent Quality Control. With Intelligent Quality Control, 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 archiving feature, which lets you record, save, and retrieve OpenTok sessions. `'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.

#### Returns

string —

A session ID for the new session. For example, when using the OpenTok.js library, use this session ID when calling the `OT.initSession()` method.

#

## Tags

todo |

### startArchive()

    startArchive(String $sessionId, String $name) : \OpenTok\Archive

Starts archiving an OpenTok 2.0 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 use the OpenTok Media Router (sessions with the media mode set to routed); you cannot archive sessions with the media mode set to relayed.

#### Parameters

String | $sessionId | The session ID of the OpenTok session to archive.
String | $name | The name of the archive. You can use this name to identify the archive. It is a property of the Archive object, and it is a property of archive-related events in the OpenTok JavaScript SDK.

#### Returns

\OpenTok\Archive —

The Archive object, which includes properties defining the archive, including the archive ID.

#

## Tags

todo |

### stopArchive()

    stopArchive(String $archiveId) : \OpenTok\Archive

Stops an OpenTok archive that is being recorded.

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

#### Parameters

String | $archiveId | The archive ID of the archive you want to stop recording.

#### Returns

\OpenTok\Archive —

The Archive object corresponding to the archive being stopped.

#

## Tags

todo |

### getArchive()

    getArchive(String $archiveId) : \OpenTok\Archive

Gets an Archive object for the given archive ID.

#### Parameters

String | $archiveId | The archive ID.

#### Throws

\OpenTok\ArchiveException

  There is no archive with the specified ID.

\OpenTok\OpenTokArgumentException

  The archive ID provided is null or an empty string.

#### Returns

\OpenTok\Archive —

The Archive object.

#

## Tags

todo |

### deleteArchive()

    deleteArchive(String $archiveId) : Boolean

Deletes an OpenTok archive.

You can only delete an archive which has a status of "available", "uploaded", or "deleted". 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. For a "deleted" archive, the archive remains deleted.

#### Parameters

String | $archiveId | The archive ID of the archive you want to delete.

#### Throws

\OpenTok\ArchiveException

  There archive status is not "available", "updated", or "deleted".

#### Returns

Boolean —

Returns true on success.

#

## Tags

todo |

### listArchives()

    listArchives(integer $offset, integer $count) : \OpenTok\ArchiveList

Returns an ArchiveList. The <code>items()</code> method of this object returns a list of archives that are completed and in-progress, for your API key.

#### Parameters

integer | $offset | Optional. The 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. If you do not specify an offset, 0 is used.
integer | $count | Optional. The number of archives to be returned. The maximum number of archives returned is 1000.

#### Returns

\OpenTok\ArchiveList —

An ArchiveList object. Call the items() method of the ArchiveList object to return an array of Archive objects.

#

## Tags

todo |

### OpenTok.php