Module: twilio-video

Properties:
Name Type Description
isSupported boolean

true if the current browser is officially supported by twilio-video.js; In this context, "supported" means that twilio-video.js has been extensively tested with this browser; This <a href='https://www.twilio.com/docs/video/javascript#supported-browsers target="_blank">table specifies the list of officially supported browsers.

version string

current version of twilio-video.js.

Methods


<static> connect(token [, options])

Connect to a Room.

By default, this will automatically acquire an array containing a LocalAudioTrack and LocalVideoTrack before connecting to the Room. These will be stopped when you disconnect from the Room.

You can override the default behavior by specifying options. For example, rather than acquiring a LocalAudioTrack and LocalVideoTrack automatically, you can pass your own array which you can stop yourself. See ConnectOptions for more information.

Parameters:
Name Type Argument Description
token string

The Access Token string

options ConnectOptions <optional>

Options to override the default behavior

Throws:
Returns:
Type
CancelablePromise.<Room>
Examples
var Video = require('twilio-video');
var token = getAccessToken();
Video.connect(token, {
  name: 'my-cool-room'
}).then(function(room) {
  room.on('participantConnected', function(participant) {
    console.log(participant.identity + ' has connected');
  });
  room.once('disconnected', function() {
    console.log('You left the Room:', room.name);
  });
}).catch(error => {
  console.log('Could not connect to the Room:', error.message);
});
var Video = require('twilio-video');
var token = getAccessToken();

// Connect with audio-only
Video.connect(token, {
  name: 'my-cool-room',
  audio: true
}).then(function(room) {
  room.on('participantConnected', function(participant) {
    console.log(participant.identity + ' has connected');
  });

  room.once('disconnected', function() {
    console.log('You left the Room:', room.name);
  });
}).catch(error => {
  console.log('Could not connect to the Room:', error.message);
});
var Video = require('twilio-video');
var token = getAccessToken();

// Connect with media acquired using getUserMedia()
navigator.mediaDevices.getUserMedia({
  audio: true,
  video: true
}).then(function(mediaStream) {
  return Video.connect(token, {
    name: 'my-cool-room',
    tracks: mediaStream.getTracks()
  });
}).then(function(room) {
  room.on('participantConnected', function(participant) {
    console.log(participant.identity + ' has connected');
  });

  room.once('disconnected', function() {
    console.log('You left the Room:', room.name);
  });
}).catch(error => {
  console.log('Could not connect to the Room:', error.message);
});
var Video = require('twilio-video');
var token = getAccessToken();

// Connect with custom names for LocalAudioTrack and LocalVideoTrack
Video.connect(token, {
  name: 'my-cool-room'
  audio: { name: 'microphone' },
  video: { name: 'camera' }
}).then(function(room) {
  room.localParticipants.trackPublications.forEach(function(publication) {
    console.log('The LocalTrack "' + publication.trackName + '" was successfully published');
  });
}).catch(error => {
  console.log('Could not connect to the Room:', error.message);
});

<static> createLocalAudioTrack( [options])

Request a LocalAudioTrack.

Parameters:
Name Type Argument Description
options CreateLocalTrackOptions <optional>

Options for requesting a LocalAudioTrack

Returns:
Type
Promise.<LocalAudioTrack>
Examples
var Video = require('twilio-video');

// Connect to the Room with just video
Video.connect('my-token', {
  name: 'my-cool-room',
  video: true
}).then(function(room) {
  // Add audio after connecting to the Room
  Video.createLocalAudioTrack().then(function(localTrack) {
    room.localParticipant.publishTrack(localTrack);
  });
});
var Video = require('twilio-video');

// Request the default LocalAudioTrack with a custom name
Video.createLocalAudioTrack({ name: 'microphone' }).then(function(localTrack) {
  console.log(localTrack.name); // 'microphone'
});

<static> createLocalTracks( [options])

Request LocalTracks. By default, it requests a LocalAudioTrack and a LocalVideoTrack.

Parameters:
Name Type Argument Description
options CreateLocalTracksOptions <optional>
Returns:
Type
Promise.<Array.<LocalTrack>>
Examples
var Video = require('twilio-video');
// Request audio and video tracks
Video.createLocalTracks().then(function(localTracks) {
  var localMediaContainer = document.getElementById('local-media-container-id');
  localTracks.forEach(function(track) {
    localMediaContainer.appendChild(track.attach());
  });
});
var Video = require('twilio-video');
// Request just the default audio track
Video.createLocalTracks({ audio: true }).then(function(localTracks) {
  return Video.connect('my-token', {
    name: 'my-cool-room',
    tracks: localTracks
  });
});
var Video = require('twilio-video');
// Request the audio and video tracks with custom names
Video.createLocalTracks({
  audio: { name: 'microphone' },
  video: { name: 'camera' }
}).then(function(localTracks) {
  localTracks.forEach(function(localTrack) {
    console.log(localTrack.name);
  });
});

<static> createLocalVideoTrack( [options])

Request a LocalVideoTrack.

Parameters:
Name Type Argument Description
options CreateLocalTrackOptions <optional>

Options for requesting a LocalVideoTrack

Returns:
Type
Promise.<LocalVideoTrack>
Examples
var Video = require('twilio-video');

// Connect to the Room with just audio
Video.connect('my-token', {
  name: 'my-cool-room',
  audio: true
}).then(function(room) {
  // Add video after connecting to the Room
  Video.createLocalVideoTrack().then(function(localTrack) {
    room.localParticipant.publishTrack(localTrack);
  });
});
var Video = require('twilio-video');

// Request the default LocalVideoTrack with a custom name
Video.createLocalVideoTrack({ name: 'camera' }).then(function(localTrack) {
  console.log(localTrack.name); // 'camera'
});