Vonage Video API PHP SDK
The Vonage Video PHP SDK provides methods for:
- Creating sessions.
- Generating tokens
- Working with streams
- Working with archives
- Disconnecting clients from sessions
- Forcing clients in a session to disconnect or mute published audio
- Sending signals to clients connected to a session
Installation
Requirements
You need to create a Vonage Application with Video capabilities. You will then use the private key and application ID to configure the API client. You can create the application by logging into your Vonage Video API account.
The Vonage Video PHP SDK requires PHP 8.0 or higher.
Composer (recommended)
Composer helps manage dependencies for PHP projects. Find more info here: http://getcomposer.org
Add this package (vonage/video) to your composer.json file, or run the following at the command line:
This package requires the vonage/client-core package to work. Make sure that is also installed:
Usage
Initializing
This package follows the PSR-4 autoloading standard. If you are composer requires the generated autoloader:
Once the files of the SDK are loaded, you can create a Vonage API client using the private key and application ID associated with your Vonage Video application. You can then access the Video SDK itself by calling $client->video().
Initialization Options
The Vonage Video client allows for some overrides of values when special needs arise, such as needing to point to a different datacenter or change the timeout of the underlying HTTP client. For these situations, you can pass an array of additional options as the third parameter.
We allow the following additional options for the Video SDK:
base_video_url- Change the domain that the SDK points to. Useful when needing to select a specific datacenter or point to a mock version of the API for testing
Creating Sessions
To create a Session, use the createSession($options) method of the Vonage Video client. The $options parameter is an optional array used to specify the following:
Setting whether the session will use the Media Router or attempt to send streams directly between clients.
Setting whether the session will automatically create archives (implies use of routed session)
Specifying a location hint.
The getSessionId() method returns the session ID, which you use to identify the session in the Vonage Video client libraries.
For more information on sessions, see the sessions developer guide.
Generating Tokens
Once a Session is created, you can start generating Tokens for clients to use when connecting to it. You can generate a token either by calling the generateClientToken($sessionId, $options) method on the video client.
The $options parameter is an optional array used to set the role, how long until the token expires, and connection data of the Token. For layout control in archives and broadcasts, the initial layout class list of streams published from connections using this token can be set as well.
For more information on Tokens, see the Create Token developer guide.
Working with Streams
You can get information about a stream by calling the getStream($sessionId, $streamId) method of the Vonage Video client.
You can get information about all the streams in a session by calling the listStreams($sessionId) method of the Vonage Video client.
Working with Archives
You can only archive sessions that use the Vonage Video Media Router (sessions with the media mode set to routed).
You can start the recording of a Vonage Video Session using the startArchive($archiveConfig) method of the Vonage Video client. This will return an Vonage\Video\Archive instance.
The parameter $archiveConfig is an configuration object and is used to determine the session ID, assign a name, whether to record audio and/or video, the desired output mode for the Archive, and the desired resolution if applicable. Note that you can only start an Archive on a Session that has clients connected.
If you set the outputMode option to ArchiveConfig::OUTPUT_MODE_INDIVIDUAL, it causes each stream in the archive to be recorded to its own individual file. Please note that you cannot specify the resolution when you set the outputMode option to ArchiveConfig::OUTPUT_MODE_INDIVIDUAL. The ArchiveConfig::OUTPUT_MODE_COMPOSED setting (the default) causes all streams in the archive to be recorded to a single (composed) file.
Note that you can also create an automatically archived session, by passing in ArchiveMode::ALWAYS as the archiveMode key of the options parameter passed into the $client->video()->createSession() method (see "Creating Sessions," above).
You can stop the recording of a started archive using the stopArchive($archiveId) method of the Vonage Video client.
To get an Vonage\Video\Archive instance (and all the information about it) from an archive ID, use the getArchive($archiveId) method of the Vonage Video client.
To delete an Archive, you can call the deleteArchive($archiveId) method of the Vonage Video client.
You can also get a list of all the Archives you've created (up to 1000) with your API Key. This is done using the listArchives($filter) method of the Vonage Video Client.
You can pass a KeyValueFilter object with offset, count, or sessionId options. The filter is optional and can help you subset results. Note that the list will automatically return the next page of results, so you do not need to manually call an offset or count unless specifically needed.
For composed archives, you can change the layout dynamically, using the updateArchiveLayout($archiveId, $layoutType) method:
You can set the initial layout class for a client's streams by setting the layout option when you create the token for the client, using the generateClientToken().
Setting the layout of composed archives is optional. By default, composed archives use the "best fit" layout (see Customizing the video layout for composed archives).
For more information on archiving, see the Vonage Video archiving developer guide.
Force a Client to Disconnect
Your application server can disconnect a client from a Vonage Video session by calling the disconnectClient($sessionId, $connectionId) method of the Vonage Video client.
Forcing clients in a session mute published audio
You can force the publisher of a specific stream to stop publishing audio using the forceMuteStream($sessionId, $stream) method.
You can force the publisher of all streams in a session (except for an optional list of streams) to stop publishing audio using the forceMuteAll($sessionId, $excludedStreamIds) method. You can then disable the mute state of the session by calling the disableForceMute(sessionId) method.
Sending Signals
Once a Session is created, you can send signals to everyone in the session or to a specific connection. You can send a signal by calling the signal($sessionId, $type, $data, $connectionId) method of the Vonage Video client.
The $sessionId parameter is the session ID of the session.
The $data (string) is a data string for the signal. You can send a maximum of 8kB.
The $type (string) is the type string for the signal. You can send a maximum of 128 characters, and only the following characters are allowed: A-Z, a-z, numbers (0-9), '-', '_', and '~'.
The $connectionId parameter is an optional string used to specify the connection ID of a client connected to the session. If you specify this value, the signal is sent to the specified client. Otherwise, the signal is sent to all clients connected to the session.
For more information, see the Vonage Video signaling developer guide.
Release Notes
See the Releases page for details.