How to use twilio-video - 10 common examples

To help you get started, we’ve selected a few twilio-video examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / twilio-video / twilio-video-tests.ts View on Github external
low: {
            height: 500,
            width: null
          }
        }
      }
    }
  });
  await Video.connect('$TOKEN', {
    networkQuality: {
      local: 3,
      remote: 1
    }
  });
  // Create local video track from default input
  localVideoTrack = await Video.createLocalVideoTrack({ name: 'camera' });
  // Create local audio track from default input
  localAudioTrack = await Video.createLocalAudioTrack({ name: 'microphone' });
  // Publish audio track
  room.localParticipant.publishTrack(localAudioTrack);
  // Subscribe to remote participant tracks
  room.participants.forEach(participantConnected);
  // Set up listeners
  room.on('participantConnected', participantConnected);
  room.on('participantDisconnected', participantDisconnected);
  room.once('disconnected', (room: Video.Room, error: Video.TwilioError) => {
    room.participants.forEach(participantDisconnected);
    room.localParticipant.tracks.forEach((publication: Video.LocalTrackPublication) => {
      publication.unpublish();
      if (publication.track.kind !== 'data') trackUnsubscribed(publication.track);
    });
  });
github DefinitelyTyped / DefinitelyTyped / types / twilio-video / twilio-video-tests.ts View on Github external
width: null
          }
        }
      }
    }
  });
  await Video.connect('$TOKEN', {
    networkQuality: {
      local: 3,
      remote: 1
    }
  });
  // Create local video track from default input
  localVideoTrack = await Video.createLocalVideoTrack({ name: 'camera' });
  // Create local audio track from default input
  localAudioTrack = await Video.createLocalAudioTrack({ name: 'microphone' });
  // Publish audio track
  room.localParticipant.publishTrack(localAudioTrack);
  // Subscribe to remote participant tracks
  room.participants.forEach(participantConnected);
  // Set up listeners
  room.on('participantConnected', participantConnected);
  room.on('participantDisconnected', participantDisconnected);
  room.once('disconnected', (room: Video.Room, error: Video.TwilioError) => {
    room.participants.forEach(participantDisconnected);
    room.localParticipant.tracks.forEach((publication: Video.LocalTrackPublication) => {
      publication.unpublish();
      if (publication.track.kind !== 'data') trackUnsubscribed(publication.track);
    });
  });
}
github TwilioDevEd / api-snippets / video / getting-started / setup-local-media / setup-local-media.js View on Github external
const {
  createLocalTracks,
  createLocalAudioTrack,
  createLocalVideoTrack
} = require('twilio-video');

var localTracks;

// Create default local audio and video tracks
createLocalTracks().then(localTracks => {
  console.log('Got default audio and video tracks:', localTracks);
});

// Create default local track of a particular kind
createLocalAudioTrack().then(audioTrack => {
  console.log('Got default local audio track:', audioTrack);
});

createLocalVideoTrack().then(videoTrack => {
  console.log('Got default local video track:', videoTrack);
});
github TwilioDevEd / api-snippets / video / rooms / specify-constraints / specify-constraints.js View on Github external
const { connect, createLocalTracks } = require('twilio-video');

// Option 1
createLocalTracks({
  audio: true,
  video: { width: 640 }
}).then(localTracks => {
  return connect('$TOKEN', {
    name: 'my-room-name',
    tracks: localTracks
  });
}).then(room => {
  console.log('Connected to Room:', room.name);
});

// Option 2
connect('$TOKEN', {
  audio: true,
  name: 'my-room-name',
  video: { width: 640 }
github TwilioDevEd / api-snippets / video / getting-started / setup-local-media / setup-local-media.js View on Github external
createLocalVideoTrack
} = require('twilio-video');

var localTracks;

// Create default local audio and video tracks
createLocalTracks().then(localTracks => {
  console.log('Got default audio and video tracks:', localTracks);
});

// Create default local track of a particular kind
createLocalAudioTrack().then(audioTrack => {
  console.log('Got default local audio track:', audioTrack);
});

createLocalVideoTrack().then(videoTrack => {
  console.log('Got default local video track:', videoTrack);
});
github TwilioDevEd / api-snippets / video / getting-started / setup-local-media / setup-local-media.js View on Github external
const {
  createLocalTracks,
  createLocalAudioTrack,
  createLocalVideoTrack
} = require('twilio-video');

var localTracks;

// Create default local audio and video tracks
createLocalTracks().then(localTracks => {
  console.log('Got default audio and video tracks:', localTracks);
});

// Create default local track of a particular kind
createLocalAudioTrack().then(audioTrack => {
  console.log('Got default local audio track:', audioTrack);
});

createLocalVideoTrack().then(videoTrack => {
  console.log('Got default local video track:', videoTrack);
});
github twilio / video-quickstart-js / quickstart / src / index.js View on Github external
return;
    }

    log("Joining room '" + roomName + "'...");
    var connectOptions = {
      name: roomName,
      logLevel: 'debug'
    };

    if (previewTracks) {
      connectOptions.tracks = previewTracks;
    }

    // Join the Room with the token from the server and the
    // LocalParticipant's Tracks.
    Video.connect(data.token, connectOptions).then(roomJoined, function(error) {
      log('Could not connect to Twilio: ' + error.message);
    });
  };
github philnash / screen-capture / video-chat / src / index.js View on Github external
return;
      }

      log("Joining room '" + roomName + "'...");
      var connectOptions = {
        name: roomName,
        logLevel: 'debug'
      };

      if (previewTracks) {
        connectOptions.tracks = previewTracks;
      }

      // Join the Room with the token from the server and the
      // LocalParticipant's Tracks.
      Video.connect(data.token, connectOptions).then(roomJoined, function(
        error
      ) {
        log('Could not connect to Twilio: ' + error.message);
      });
    };
github philnash / mediadevices-camera-selection / video-chat / quickstart / src / index.js View on Github external
return;
    }

    log("Joining room '" + roomName + "'...");
    var connectOptions = {
      name: roomName,
      logLevel: 'debug'
    };

    if (previewTracks) {
      connectOptions.tracks = previewTracks;
    }

    // Join the Room with the token from the server and the
    // LocalParticipant's Tracks.
    Video.connect(data.token, connectOptions).then(roomJoined, function(error) {
      log('Could not connect to Twilio: ' + error.message);
    });
  };
github twilio / video-quickstart-js / examples / codecpreferences / src / index.js View on Github external
(async function() {
  // Load the code snippet.
  const snippet = await getSnippet('./helpers.js');
  const pre = document.querySelector('pre.language-javascript');
  pre.innerHTML = Prism.highlight(snippet, Prism.languages.javascript);

  // Set listener to the connect or disconnect button.
  connectOrDisconnect.onclick = connectToOrDisconnectFromRoom;

  // Get the credentials to connect to the Room.
  const creds = await getRoomCredentials();

  // Connect to a random Room with no media. This Participant will
  // display the media of the second Participant that will enter
  // the Room with preferred codecs.
  const someRoom = await Video.connect(creds.token, { tracks: [] });

  // Disconnect from the Room on page unload.
  window.onbeforeunload = function() {
    if (room) {
      room.disconnect();
      room = null;
    }
    someRoom.disconnect();
  };

  // Set the name of the Room to which the Participant that shares
  // media should join.
  roomName = someRoom.name;

  // Attach the newly subscribed Track to the DOM.
  someRoom.on('trackSubscribed', attachTrack.bind(