Vonage Video API Node SDK

The Node SDK provides methods for:

NPM helps manage dependencies for node projects. Find more info here: http://npmjs.org

Run this command to install the package and adding it to your package.json:

Usage

Initializing

Import the module to get a constructor function for a video object, then call it with new to instantiate a video object with your own App ID and private key.

Creating Sessions

To create a session, use the createSession(properties) method. The properties parameter is an optional object used to specify whether the session uses the Media Router, to specify a location hint, and to specify whether the session will be automatically archived or . The session returned is an instance of session. Session objects have a sessionId property that is useful to be saved to a persistent store (such as a database).

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 by calling the generateClientToken(sessionId) method.

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.

Working with archives

You can start the recording of a session using the startArchive(sessionId, options) method. The options parameter is an optional object used to set the name of the Archive. The archive returned is an instance of Archive.

Note that you can only start an archive on a Session with connected clients.

You can also disable audio or video recording by setting the hasAudio or hasVideo property of the options parameter to false:

By default, all streams are recorded to a single (composed) file. You can record the different streams in the session to individual files (instead of a single composed file) by setting the outputMode option to 'individual' when you call the startArchive() method:

You can stop the recording of a started Archive using the stopArchive(archiveId) method. The archive returned in the callback is an instance of Archive.

To get an Archive instance (and all the information about it) from an archiveId, use the getArchive(archiveId) method.

You can inspect the properties of the archive for more details.

To delete an Archive, you can call the deleteArchive(archiveId) method.

You can also get a list of all the Archives you've created (up to 1000) with your App ID. This is done using the searchArchives(filter) method. The parameter filter is an optional object used to specify a sessionId, offset and count to help you paginate through the results.

The archives returned is an array of Archive instances. The totalCount returned from the callback is the total number of archives your App ID has generated.

Note that you can also create an automatically archived session, by passing in 'always' as the archiveMode option when you call the createSession() method (see "Creating Sessions," above).

For composed archives, you can set change the layout dynamically, using the updateArchiveLayout(archiveId, layout) 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 generateToken() method. And you can change the layout classes for streams in a session by calling the setStreamClassLists(sessionId, classListArray) method.

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 archiving developer guide.

See the API reference for details on the options parameter.

On success, a Broadcast object is passed into the callback function as the second parameter. The Broadcast object has properties that define the broadcast, including a broadcastUrls property, which has URLs for the broadcast streams. See the API reference for details.

Call the OpenTok.stopBroadcast() method to stop a live streaming broadcast pass in the broadcast ID (the id property of the Broadcast object) as the first parameter. The second parameter is the callback function:

You can also call the stop() method of the Broadcast object to stop a broadcast.

Call the Opentok.getBroadcast() method, passing in a broadcast ID, to get a Broadcast object.

You can also get a list of all the Broadcasts you've created (up to 1000) with your API Key. This is done using the OpenTok.listBroadcasts(options, callback) method. The parameter options is an optional object used to specify an offset, count, and sessionId to help you paginate through the results. The callback has a signature function(err, broadcasts, totalCount). The broadcasts returned from the callback is an array of Broadcast instances. The totalCount returned from the callback is the total number of broadcasts your App ID has generated.

To change the broadcast layout, call the OpenTok.setBroadcastLayout() method, passing in the broadcast ID and the layout type.

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 OpenTok.generateToken() method. And you can change the layout classes for streams in a session by calling the OpenTok.setStreamClassLists(sessionId, classListArray, callback) method.

Setting the layout of a live streaming broadcast is optional. By default, live streaming broadcasts use the "best fit" layout. -->

Sending signals

You can send a signal to all participants in a session by calling the sendSignal(payload, sessionId, connectionId) method and setting the connectionId parameter to null:

Or send a signal to a specific participant in the session by calling the sendSignal(payload, sessionId, connectionId) method and setting all parameters, including connectionId:

This is the server-side equivalent to the sendSignal() method in the client SDKs. See signaling developer guide .

Disconnecting participants

You can disconnect participants from a session using the disconnectClient(sessionId, connectionId) method.

Forcing clients in a session to mute published audio

You can force the publisher of a specific stream to stop publishing audio using the muteStream(sessionId, streamId)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() method. You can then disable the mute state of the session by calling the disableForceMute() method.

Getting Stream Info

You can get information on an active stream in a session:

Pass a session ID and stream ID to the getStreamInfo() method. On successful completion, the stream object containing properties of the stream.

Requirements

You need a Vonage App ID and private key, which you can obtain by logging into your Vonage Video API account.

The Node SDK requires Node.js 6 or higher. It may work on older versions but they are no longer tested.

Release Notes

See the Releases page on GitHub for details about each release.