How to use @twilio/webrtc - 10 common examples

To help you get started, we’ve selected a few @twilio/webrtc 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 twilio / twilio-video.js / test / lib / defaults.js View on Github external
enumerable: true,
      value: env[option]
    });
  }
  return defaults;
}, {
  dominantSpeaker: true,
  networkQuality: true,
  topology: 'peer-to-peer',
  testStability: 'all' // other choices: 'stable', 'unstable'
});

// NOTE(mroberts): Firefox, since it doesn't support "max-bundle", really slows
// down with the number of ICE candidates it has to gather; therefore, in our
// tests, we disable ICE servers and trust our host candidates work out.
if (guessBrowser() === 'firefox') {
  defaults.iceServers = [];
}

module.exports = Object.seal(defaults);
github twilio / twilio-video.js / lib / connect.js View on Github external
}
  options.log = log;

  // NOTE(mmalavalli): Print the "dscpTagging" deprecation warning once if the log-level
  // is at least "warn", i.e. neither "error" nor "off".
  if (shouldPrintDscpTaggingWarning && log.level !== 'error' && log.level !== 'off') {
    didPrintDscpTaggingWarning = true;
    log.warn([
      'The ConnectOptions flag "dscpTagging" is deprecated and scheduled for removal.',
      'Please use "enableDscp" instead.'
    ].join(' '));
  }

  // NOTE(mroberts): Print the Safari warning once if the log-level is at least
  // "warn", i.e. neither "error" nor "off".
  if (guessBrowser() === 'safari'
    && !didPrintSafariWarning
    && (log.logLevel !== 'error' && log.logLevel !== 'off')) {
    didPrintSafariWarning = true;
    log.warn([
      'This release of twilio-video.js includes experimental support for',
      'Safari 11 and newer. Support for Safari is "experimental" because,',
      'at the time of writing, Safari does not support VP8. This means you',
      'may experience codec issues in Group Rooms. You may also experience',
      'codec issues in Peer-to-Peer (P2P) Rooms containing Android- or',
      'iOS-based Participants who do not support H.264. However, P2P Rooms',
      'with browser-based Participants should work. Please test this release',
      'and report any issues to https://github.com/twilio/twilio-video.js'
    ].join(' '));
  }

  if (typeof token !== 'string') {
github twilio / twilio-video.js / lib / createlocaltracks.js View on Github external
'use strict';

const asLocalTrack = require('./util').asLocalTrack;
const buildLogLevels = require('./util').buildLogLevels;
const getUserMedia = require('@twilio/webrtc').getUserMedia;
const LocalAudioTrack = require('./media/track/es5/localaudiotrack');
const LocalDataTrack = require('./media/track/es5/localdatatrack');
const LocalVideoTrack = require('./media/track/es5/localvideotrack');
const MediaStreamTrack = require('@twilio/webrtc').MediaStreamTrack;
const Log = require('./util/log');
const DEFAULT_LOG_LEVEL = require('./util/constants').DEFAULT_LOG_LEVEL;
const workaround180748 = require('./webaudio/workaround180748');

// This is used to make out which createLocalTracks() call a particular Log
// statement belongs to. Each call to createLocalTracks() increments this
// counter.
let createLocalTrackCalls = 0;

/**
 * Request {@link LocalTrack}s. By default, it requests a
 * {@link LocalAudioTrack} and a {@link LocalVideoTrack}.
 * @param {CreateLocalTracksOptions} [options]
 * @returns {Promise>}
 * @example
 * var Video = require('twilio-video');
github twilio / twilio-video.js / lib / createlocaltracks.js View on Github external
'use strict';

const asLocalTrack = require('./util').asLocalTrack;
const buildLogLevels = require('./util').buildLogLevels;
const getUserMedia = require('@twilio/webrtc').getUserMedia;
const LocalAudioTrack = require('./media/track/es5/localaudiotrack');
const LocalDataTrack = require('./media/track/es5/localdatatrack');
const LocalVideoTrack = require('./media/track/es5/localvideotrack');
const MediaStreamTrack = require('@twilio/webrtc').MediaStreamTrack;
const Log = require('./util/log');
const DEFAULT_LOG_LEVEL = require('./util/constants').DEFAULT_LOG_LEVEL;
const workaround180748 = require('./webaudio/workaround180748');

// This is used to make out which createLocalTracks() call a particular Log
// statement belongs to. Each call to createLocalTracks() increments this
// counter.
let createLocalTrackCalls = 0;

/**
 * Request {@link LocalTrack}s. By default, it requests a
 * {@link LocalAudioTrack} and a {@link LocalVideoTrack}.
github twilio / twilio-video.js / test / unit / spec / util / sdp / issue8329.js View on Github external
it('still works', () => {
      const input = new RTCSessionDescription({ type: 'offer', sdp: validSdp2 });
      const output = workaround(input).sdp;
      assert(!output.match(/\r\n\r\n/));
    });
  });
github twilio / twilio-video.js / test / integration / spec / util / simulcast.js View on Github external
'use strict';

const assert = require('assert');
const { guessBrowser } = require('@twilio/webrtc/lib/util');
const { getSdpFormat } = require('@twilio/webrtc/lib/util/sdp');
const { getMediaSections, setSimulcast } = require('../../../../lib/util/sdp');
const { RTCPeerConnection, RTCSessionDescription } = require('@twilio/webrtc');
const { DEFAULT_CHROME_SDP_SEMANTICS } = require('../../../../lib/util/constants');

const isChrome = guessBrowser() === 'chrome';
const sdpFormat = getSdpFormat(DEFAULT_CHROME_SDP_SEMANTICS);

describe('setSimulcast', () => {
  let answer1;
  let answer2;
  let offer1;
  let offer2;
  let pc1;
  let pc2;
  let stream;
  let trackIdsToAttributes;

  if (!isChrome) {
    it('should not run the setSimulcast integration tests', () => {});
    return;
  }
github twilio / twilio-video.js / test / integration / spec / util / simulcast.js View on Github external
'use strict';

const assert = require('assert');
const { guessBrowser } = require('@twilio/webrtc/lib/util');
const { getSdpFormat } = require('@twilio/webrtc/lib/util/sdp');
const { getMediaSections, setSimulcast } = require('../../../../lib/util/sdp');
const { RTCPeerConnection, RTCSessionDescription } = require('@twilio/webrtc');
const { DEFAULT_CHROME_SDP_SEMANTICS } = require('../../../../lib/util/constants');

const isChrome = guessBrowser() === 'chrome';
const sdpFormat = getSdpFormat(DEFAULT_CHROME_SDP_SEMANTICS);

describe('setSimulcast', () => {
  let answer1;
  let answer2;
  let offer1;
  let offer2;
  let pc1;
  let pc2;
  let stream;
  let trackIdsToAttributes;

  if (!isChrome) {
    it('should not run the setSimulcast integration tests', () => {});
    return;
  }
github twilio / twilio-video.js / test / integration / spec / util / simulcast.js View on Github external
before(async () => {
        const constraints = { audio: true, video: true };
        stream = await makeStream(constraints);
        pc1 = new RTCPeerConnection({ iceServers: [] });
        pc1.addStream(stream);
        pc2 = new RTCPeerConnection({ iceServers: [] });
        pc2.addStream(stream);
        trackIdsToAttributes = new Map();

        const offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
        const offer = await pc1.createOffer(offerOptions);

        offer1 = createSdp === 'createOffer' ? new RTCSessionDescription({
          type: offer.type,
          sdp: setSimulcast(offer.sdp, sdpFormat, trackIdsToAttributes)
        }) : offer;

        await pc1.setLocalDescription(offer1);
        await pc2.setRemoteDescription(offer1);
        const answer = await pc2.createAnswer();

        answer1 = createSdp === 'createAnswer' ? new RTCSessionDescription({
          type: answer.type,
          sdp: setSimulcast(answer.sdp, sdpFormat, trackIdsToAttributes)
        }) : answer;

        await pc2.setLocalDescription(answer1);
        await pc1.setRemoteDescription(answer1);
        const _offer = await pc1.createOffer(offerOptions);
github twilio / twilio-video.js / test / integration / spec / util / simulcast.js View on Github external
pc1.addStream(stream);
      trackIdsToAttributes = new Map();

      const offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
      const offer = await pc1.createOffer(offerOptions);

      offer1 = new RTCSessionDescription({
        type: offer.type,
        sdp: setSimulcast(offer.sdp, sdpFormat, trackIdsToAttributes)
      });

      await pc1.setLocalDescription(offer1);
      assert.equal(pc1.signalingState, 'have-local-offer');
      const _offer = await pc1.createOffer(offerOptions);

      offer2 = new RTCSessionDescription({
        type: _offer.type,
        sdp: setSimulcast(_offer.sdp, sdpFormat, trackIdsToAttributes)
      });
    });
github twilio / twilio-video.js / test / integration / spec / util / simulcast.js View on Github external
before(async () => {
      const constraints = { audio: true, video: true };
      stream = await makeStream(constraints);
      pc1 = new RTCPeerConnection({ iceServers: [] });
      pc1.addStream(stream);
      trackIdsToAttributes = new Map();

      const offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
      const offer = await pc1.createOffer(offerOptions);

      offer1 = new RTCSessionDescription({
        type: offer.type,
        sdp: setSimulcast(offer.sdp, sdpFormat, trackIdsToAttributes)
      });

      await pc1.setLocalDescription(offer1);
      assert.equal(pc1.signalingState, 'have-local-offer');
      const _offer = await pc1.createOffer(offerOptions);

      offer2 = new RTCSessionDescription({
        type: _offer.type,
        sdp: setSimulcast(_offer.sdp, sdpFormat, trackIdsToAttributes)
      });
    });