Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twilio-video

Package Overview
Dependencies
Maintainers
1
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twilio-video - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

2

bower.json
{
"name": "twilio-video",
"version": "1.4.0",
"version": "1.5.0",
"description": "Twilio Video JavaScript library",

@@ -5,0 +5,0 @@ "license": "BSD",

@@ -0,1 +1,86 @@

1.5.0 (October 9, 2017)
=======================
New Features
------------
- You can now specify Track names. Refer to the Track name guide below for more
information.
Bug Fixes
---------
- Fixed bug where RemoteTrack's "unsubscribed" event and RemoteParticipant's
"trackUnsubscribed" event fired before the RemoteTrack was removed from the
RemoteParticipant's `tracks` collections instead of after.
Track Name Guide
----------------
### Setting Track names
There are a few different ways you can specify Track names. For example, you can
specify `name` as an `audio` or `video` constraint when calling any of
`createLocalTracks`, `createLocalAudioTrack`, `createLocalVideoTrack`, or
`connect`:
```js
createLocalTracks({
audio: { name: 'microphone' },
video: { name: 'camera' }
});
createLocalAudioTrack({ name: 'microphone' });
createLocalVideoTrack({ name: 'camera' });
connect(token, {
audio: { name: 'microphone' },
video: { name: 'camera' }
});
```
These will create a LocalAudioTrack and a LocalVideoTrack with the names
"microphone" and "camera", respectively. If you have a reference to a
MediaStreamTrack, you can also pass the `name` to the LocalAudioTrack or
LocalVideoTrack constructor:
```js
const localAudioTrack = new LocalAudioTrack(mediaStreamTrack1, { name: 'microphone' });
const localVideoTrack = new LocalVideoTrack(mediaStreamTrack2, { name: 'camera' });
```
Similarly, for LocalDataTracks:
```js
const localDataTrack = new LocalDataTrack({ name: 'data' });
```
You can even pass these values if you use the MediaStreamTrack override for
`publishTrack`. For example:
```js
room.localParticipant.publishTrack(mediaStreamTrack, { name: 'my-track' });
```
Please keep in mind:
* If you do not specify a Track name, the Track's name will default to the
LocalTrack ID.
* A single Participant cannot have two Tracks published with the same name at a
time.
### Getting Track names
You can check a LocalTrack or RemoteTrack's name by querying it's `name`
property. For example,
```js
participant.on('trackSubscribed', track => {
console.log('Subscribed to Track "' + track.name + '"');
});
```
This can be useful, for example, for distinguishing between a RemoteVideoTrack
named "camera" and a RemoteVideoTrack named "screenshare".
1.4.0 (October 2, 2017)

@@ -2,0 +87,0 @@ =======================

@@ -100,2 +100,16 @@ 'use strict';

* });
* @example
* 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');
* });
* });
*/

@@ -129,4 +143,6 @@ function connect(token, options) {

var logComponentName = '[connect #' + ++connectCalls + ']';
var log;
try {
var log = new Log('default', logComponentName, logLevels);
log = new Log('default', logComponentName, logLevels);
} catch (error) {

@@ -159,2 +175,8 @@ return CancelablePromise.reject(error);

// NOTE(mmalavalli): The Room "name" in "options" was being used
// as the LocalTrack name in asLocalTrack(). So we pass a copy of
// "options" without the "name".
var localTrackOptions = Object.assign({}, options);
delete localTrackOptions.name;
if ('tracks' in options) {

@@ -167,3 +189,3 @@ if (!Array.isArray(options.tracks)) {

options.tracks = options.tracks.map(function(track) {
return util.asLocalTrack(track, options);
return util.asLocalTrack(track, localTrackOptions);
});

@@ -231,3 +253,3 @@ } catch (error) {

* @typedef {object} ConnectOptions
* @property {boolean|MediaTrackConstraints} [audio=true] - Whether or not to
* @property {boolean|CreateLocalTrackOptions} [audio=true] - Whether or not to
* get local audio with <code>getUserMedia</code> when <code>tracks</code>

@@ -267,3 +289,3 @@ * are not provided.

* obtained by calling <code>getUserMedia()</code>.
* @property {boolean|MediaTrackConstraints} [video=true] - Whether or not to
* @property {boolean|CreateLocalTrackOptions} [video=true] - Whether or not to
* get local video with <code>getUserMedia</code> when <code>tracks</code>

@@ -270,0 +292,0 @@ * are not provided.

@@ -41,3 +41,3 @@ 'use strict';

* Video.connect('my-token', {
* name: 'my-room-name',
* name: 'my-cool-room',
* video: true

@@ -50,2 +50,9 @@ * }).then(function(room) {

* });
* @example
* 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'
* });
*/

@@ -65,3 +72,3 @@ function createLocalAudioTrack(options) {

* Video.connect('my-token', {
* name: 'my-room-name',
* name: 'my-cool-room',
* audio: true

@@ -74,2 +81,9 @@ * }).then(function(room) {

* });
* @example
* 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'
* });
*/

@@ -84,2 +98,4 @@ function createLocalVideoTrack(options) {

* @property {LogLevel|LogLevels} logLevel
* @property {string} [name] - The {@link LocalTrack}'s name; by default,
* it is set to the {@link LocalTrack}'s ID.
*/

@@ -86,0 +102,0 @@

@@ -37,6 +37,17 @@ 'use strict';

* return Video.connect('my-token', {
* name: 'my-room-name',
* name: 'my-cool-room',
* tracks: localTracks
* });
* });
* @example
* 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);
* });
* });
*/

@@ -63,2 +74,8 @@ function createLocalTracks(options) {

// NOTE(mmalavalli): The Room "name" in "options" was being used
// as the LocalTrack name in asLocalTrack(). So we pass a copy of
// "options" without the "name".
var localTrackOptions = Object.assign({ log: log }, options);
delete localTrackOptions.name;
if (options.audio === false && options.video === false) {

@@ -75,2 +92,18 @@ log.info('Neither audio nor video requested, so returning empty LocalTracks');

var localTrackNameOptions = {
audio: options.audio && options.audio.name
? { name: options.audio.name }
: {},
video: options.video && options.video.name
? { name: options.video.name }
: {}
};
if (options.audio) {
delete options.audio.name;
}
if (options.video) {
delete options.video.name;
}
return options.getUserMedia({

@@ -86,3 +119,4 @@ audio: options.audio,

return mediaStreamTracks.map(function(mediaStreamTrack) {
return asLocalTrack(mediaStreamTrack, Object.assign({ log: log }, options));
return asLocalTrack(mediaStreamTrack, Object.assign(
localTrackNameOptions[mediaStreamTrack.kind], localTrackOptions));
});

@@ -98,3 +132,3 @@ }, function(error) {

* @typedef {object} CreateLocalTracksOptions
* @property {boolean|MediaTrackConstraints} [audio=true] - Whether or not to
* @property {boolean|CreateLocalTrackOptions} [audio=true] - Whether or not to
* get local audio with <code>getUserMedia</code> when <code>tracks</code>

@@ -106,3 +140,3 @@ * are not provided.

* levels.
* @property {boolean|MediaTrackConstraints} [video=true] - Whether or not to
* @property {boolean|CreateLocalTrackOptions} [video=true] - Whether or not to
* get local video with <code>getUserMedia</code> when <code>tracks</code>

@@ -109,0 +143,0 @@ * are not provided.

@@ -144,3 +144,4 @@ 'use strict';

function localTrackAdded(localTrack) {
signaling.addTrack(localTrack._dataTrackSender || localTrack.mediaStreamTrack);
var mediaStreamTrackOrDataTrackSender = localTrack._dataTrackSender || localTrack.mediaStreamTrack;
signaling.addTrack(mediaStreamTrackOrDataTrackSender, localTrack.name);
log.info('Added a new ' + util.trackClass(localTrack, true) + ':', localTrack.id);

@@ -175,3 +176,5 @@ log.debug(util.trackClass(localTrack, true) + ':', localTrack);

localTrackAdded(track);
this._getOrCreateLocalTrackPublication(track);
this._getOrCreateLocalTrackPublication(track).catch(function() {
// Do nothing for now.
});
}, this);

@@ -315,12 +318,35 @@

* Publishes a {@link LocalTrack} to the {@link Room}.
* @param {LocalTrack|MediaStreamTrack} track - The {@link LocalTrack}
* to publish; if a MediaStreamTrack is provided, and a corresponding
* {@link LocalAudioTrack} or {@link LocalVideoTrack} has not yet been
* published, this method will construct one
* @param {LocalTrack} localTrack - The {@link LocalTrack} to publish
* @returns {Promise<LocalTrackPublication>} - Resolves with the corresponding
* {@link LocalTrackPublication} if successful
* @fires Participant#trackAdded
*/
LocalParticipant.prototype.publishTrack = function publishTrack(track) {
var trackPublication = getTrackPublication(this.trackPublications, track);
*//**
* Publishes a MediaStreamTrack to the {@link Room}.
* @param {MediaStreamTrack} mediaStreamTrack - The MediaStreamTrack
* to publish; if a corresponding {@link LocalAudioTrack} or
* {@link LocalVideoTrack} has not yet been published, this method will
* construct one
* @param {LocalTrackOptions} [options] - The {@link LocalTrackOptions} for
* constructing the MediaStreamTrack's corresponding {@link LocalAudioTrack}
* or {@link LocalVideoTrack}
* @returns {Promise<LocalTrackPublication>} - Resolves with the corresponding
* {@link LocalTrackPublication} if successful
* @fires Participant#trackAdded
* @example
* var Video = require('twilio-video');
*
* Video.connect(token, {
* name: 'my-cool-room',
* audio: true
* }).then(function(room) {
* // Publish a video MediaStreamTrack with a custom name
* return room.localParticipant.publishTrack(mediaStreamTrack, {
* name: 'camera'
* });
* }).then(function(publication) {
* console.log('The LocalTrack "' + publication.trackName + '" was successfully published');
* });
*/
LocalParticipant.prototype.publishTrack = function publishTrack(localTrackOrMediaStreamTrack, options) {
var trackPublication = getTrackPublication(this.trackPublications, localTrackOrMediaStreamTrack);
if (trackPublication) {

@@ -330,11 +356,13 @@ return Promise.resolve(trackPublication);

options = Object.assign({
log: this._log,
LocalAudioTrack: this._LocalAudioTrack,
LocalDataTrack: this._LocalDataTrack,
LocalVideoTrack: this._LocalVideoTrack,
MediaStreamTrack: this._MediaStreamTrack
}, options);
var localTrack;
try {
localTrack = util.asLocalTrack(track, {
log: this._log,
LocalAudioTrack: this._LocalAudioTrack,
LocalDataTrack: this._LocalDataTrack,
LocalVideoTrack: this._LocalVideoTrack,
MediaStreamTrack: this._MediaStreamTrack
});
localTrack = util.asLocalTrack(localTrackOrMediaStreamTrack, options);
} catch (error) {

@@ -344,3 +372,3 @@ return Promise.reject(error);

this._addTrack(localTrack);
localTrack = this._addTrack(localTrack) || this.tracks.get(localTrack.id);
return this._getOrCreateLocalTrackPublication(localTrack);

@@ -347,0 +375,0 @@ };

@@ -13,7 +13,12 @@ 'use strict';

* @param {Track.Kind} kind - The {@link Track}'s kind
* @param {{ log: Log }} options
* @param {{ log: Log, name: ?string }} options
* @property {Track.ID} id - The {@link Track}'s ID
* @property {Track.Kind} kind - The {@link Track}'s kind
* @property {string} name - The {@link Track}'s name
*/
function Track(id, kind, options) {
options = Object.assign({
name: id
}, options);
EventEmitter.call(this);

@@ -34,2 +39,6 @@ Object.defineProperties(this, {

value: kind
},
name: {
enumerable: true,
value: options.name
}

@@ -77,2 +86,4 @@ });

* @property {LogLevel|LogLevels} logLevel - Log level for 'media' modules
* @property {string} [name] - The {@link LocalTrack}'s name; by default,
* it is set to the {@link LocalTrack}'s ID.
*/

@@ -79,0 +90,0 @@

@@ -14,3 +14,3 @@ 'use strict';

* @param {Track.SID} sid - SID assigned to the published {@link LocalTrack}
* @param {LocalTrack} track - the {@Link LocalTrack}
* @param {LocalTrack} track - the {@link LocalTrack}
* @param {function(LocalTrackPublication): void} unpublish - The callback

@@ -21,5 +21,6 @@ * that unpublishes the {@link LocalTrackPublication}

* @property {Track.Kind} kind - kind of the published {@link LocalTrack}
* @property {LocalTrack} track - the {@link LocalTrack}
* @property {string} trackName - the {@link LocalTrack}'s name
* @property {Track.SID} trackSid - SID assigned to the published
* {@link LocalTrack}
* @property {LocalTrack} track - the {@link LocalTrack}
*/

@@ -51,2 +52,6 @@ function LocalTrackPublication(sid, track, unpublish, options) {

},
trackName: {
enumerable: true,
value: track.name
},
trackSid: {

@@ -53,0 +58,0 @@ enumerable: true,

@@ -31,3 +31,4 @@ 'use strict';

options = Object.assign({
logLevel: DEFAULT_LOG_LEVEL
logLevel: DEFAULT_LOG_LEVEL,
name: signaling.name
}, options);

@@ -34,0 +35,0 @@

@@ -24,3 +24,4 @@ 'use strict';

options = Object.assign({
logLevel: DEFAULT_LOG_LEVEL
logLevel: DEFAULT_LOG_LEVEL,
name: signaling.name
}, options);

@@ -27,0 +28,0 @@

@@ -216,7 +216,3 @@ 'use strict';

Participant.prototype._removeTrack = function _removeTrack(track) {
if (!this.tracks.has(track.id)) {
return null;
}
track = this.tracks.get(track.id);
Participant.prototype._deleteTrack = function _deleteTrack(track) {
this.tracks.delete(track.id);

@@ -239,4 +235,11 @@

log.debug(util.trackClass(track) + ':', track);
};
Participant.prototype._removeTrack = function _removeTrack(track) {
if (!this.tracks.has(track.id)) {
return null;
}
track = this.tracks.get(track.id);
this._deleteTrack(track);
this.emit('trackRemoved', track);
return track;

@@ -243,0 +246,0 @@ };

@@ -37,3 +37,3 @@ 'use strict';

Participant.call(this, signaling, options);
this.once('disconnected', this._removeAllSubscribedTracks.bind(this));
this.once('disconnected', this._unsubscribeTracks.bind(this));
}

@@ -57,9 +57,9 @@

RemoteParticipant.prototype._removeAllSubscribedTracks = function _removeAllSubscribedTracks() {
RemoteParticipant.prototype._unsubscribeTracks = function _unsubscribeTracks() {
var tracks = Array.from(this.tracks.values());
tracks.forEach(this._removeSubscribedTrack, this);
tracks.forEach(this._unsubscribeTrack, this);
};
RemoteParticipant.prototype._removeSubscribedTrack = function _removeSubscribedTrack(remoteTrack) {
var unsubscribedTrack = this.tracks.get(remoteTrack.id) || null;
RemoteParticipant.prototype._unsubscribeTrack = function _unsubscribeTrack(remoteTrack) {
var unsubscribedTrack = this.tracks.get(remoteTrack.id);
if (unsubscribedTrack) {

@@ -69,10 +69,15 @@ unsubscribedTrack._unsubscribe();

}
return unsubscribedTrack;
};
RemoteParticipant.prototype._removeTrack = function _removeTrack(remoteTrack) {
var unsubscribedTrack = this._removeSubscribedTrack(remoteTrack);
if (unsubscribedTrack) {
Participant.prototype._removeTrack.call(this, unsubscribedTrack);
var unsubscribedTrack = this.tracks.get(remoteTrack.id);
if (!unsubscribedTrack) {
return null;
}
this._deleteTrack(unsubscribedTrack);
unsubscribedTrack._unsubscribe();
this.emit('trackUnsubscribed', unsubscribedTrack);
this.emit('trackRemoved', unsubscribedTrack);
return unsubscribedTrack;

@@ -79,0 +84,0 @@ };

@@ -352,3 +352,3 @@ 'use strict';

room.participants.forEach(function(participant) {
participant._removeAllSubscribedTracks();
participant._unsubscribeTracks();
});

@@ -355,0 +355,0 @@ log.info('Transitioned to state:', state);

@@ -12,4 +12,5 @@ 'use strict';

* @param {MediaStreamTrack|DataTrackSender} mediaStreamTrackOrDataTrackSender
* @param {string} name
*/
function LocalTrackPublicationSignaling(mediaStreamTrackOrDataTrackSender) {
function LocalTrackPublicationSignaling(mediaStreamTrackOrDataTrackSender, name) {
var enabled = mediaStreamTrackOrDataTrackSender.kind === 'data'

@@ -19,2 +20,3 @@ ? true

TrackSignaling.call(this,
name,
mediaStreamTrackOrDataTrackSender.id,

@@ -21,0 +23,0 @@ mediaStreamTrackOrDataTrackSender.kind,

@@ -12,2 +12,3 @@ 'use strict';

* @param {Track.SID} sid
* @param {string} name
* @param {Track.ID} id

@@ -18,4 +19,4 @@ * @param {Track.Kind} kind

*/
function RemoteTrackSignaling(sid, id, kind, isEnabled) {
TrackSignaling.call(this, id, kind, isEnabled);
function RemoteTrackSignaling(sid, name, id, kind, isEnabled) {
TrackSignaling.call(this, name, id, kind, isEnabled);
Object.defineProperties(this, {

@@ -22,0 +23,0 @@ isSubscribed: {

@@ -11,2 +11,3 @@ 'use strict';

* @classdesc A {@link Track} implementation
* @param {string} name
* @param {Track.ID} id

@@ -21,3 +22,3 @@ * @param {Track.Kind} kind

*/
function TrackSignaling(id, kind, isEnabled) {
function TrackSignaling(name, id, kind, isEnabled) {
EventEmitter.call(this);

@@ -75,2 +76,6 @@ var mediaStreamTrackOrDataTrackTransceiver;

},
name: {
enumerable: true,
value: name
},
sid: {

@@ -77,0 +82,0 @@ enumerable: true,

@@ -81,6 +81,7 @@ 'use strict';

* @param {MediaStreamTrack|DataTrackSender} mediaStreamTrackOrDataTrackSender
* @param {string} name
* @returns {this}
*/
LocalParticipantV2.prototype.addTrack = function addTrack(mediaStreamTrackOrDataTrackSender) {
var localTrackPublicationV2 = new this._LocalTrackPublicationV2(mediaStreamTrackOrDataTrackSender);
LocalParticipantV2.prototype.addTrack = function addTrack(mediaStreamTrackOrDataTrackSender, name) {
var localTrackPublicationV2 = new this._LocalTrackPublicationV2(mediaStreamTrackOrDataTrackSender, name);
return ParticipantSignaling.prototype.addTrack.call(this, localTrackPublicationV2);

@@ -87,0 +88,0 @@ };

@@ -11,8 +11,11 @@ 'use strict';

* @param {MediaStreamTrack|DataTrackSender} mediaStreamTrackOrDataTrackSender
* @param {string} name
*/
function LocalTrackPublicationV2(mediaStreamTrackOrDataTrackSender) {
function LocalTrackPublicationV2(mediaStreamTrackOrDataTrackSender, name) {
if (!(this instanceof LocalTrackPublicationV2)) {
return new LocalTrackPublicationV2(mediaStreamTrackOrDataTrackSender);
return new LocalTrackPublicationV2(mediaStreamTrackOrDataTrackSender, name);
}
LocalTrackPublicationSignaling.call(this, mediaStreamTrackOrDataTrackSender);
LocalTrackPublicationSignaling.call(this,
mediaStreamTrackOrDataTrackSender,
name);
}

@@ -30,3 +33,4 @@

id: this.id,
kind: this.kind
kind: this.kind,
name: this.name
};

@@ -53,2 +57,3 @@ };

* @property {Track.Kind} kind
* @property {string} name
* @property {Track.SID} sid

@@ -55,0 +60,0 @@ */

@@ -408,2 +408,10 @@ 'use strict';

}).then(function(offer) {
var updatedSdp = self._setCodecPreferences(
offer.sdp,
self._preferredAudioCodecs,
self._preferredVideoCodecs);
var updatedOffer = new RTCSessionDescription({
type: 'offer',
sdp: updatedSdp
});
self._shouldOffer = false;

@@ -414,3 +422,3 @@ if (!self._negotiationRole) {

}
return self._setLocalDescription(offer);
return self._setLocalDescription(updatedOffer);
});

@@ -417,0 +425,0 @@ };

@@ -18,2 +18,3 @@ 'use strict';

track.sid,
track.name,
track.id,

@@ -20,0 +21,0 @@ track.kind,

@@ -30,5 +30,4 @@ /* globals mozRTCPeerConnection */

/**
* Create a new {@link LocalTrackPublication} for the given {@link LocalTrack} or
* MediaStreamTrack.
* @param {LocalTrack|MediaStreamTrack} track
* Create a new {@link LocalTrackPublication} for the given {@link LocalTrack}.
* @param {LocalTrack} track
* @param {string} sid

@@ -35,0 +34,0 @@ * @param {function(track: LocalTrackPublication): void} unpublish

@@ -5,3 +5,3 @@ {

"description": "Twilio Video JavaScript library",
"version": "1.4.0",
"version": "1.5.0",
"homepage": "https://twilio.com",

@@ -8,0 +8,0 @@ "author": "Mark Andrus Roberts <mroberts@twilio.com>",

@@ -80,5 +80,5 @@ twilio-video.js

participant.on('trackSubscribed', track => trackAdded(div, track));
participant.on('trackAdded', track => trackAdded(div, track));
participant.tracks.forEach(track => trackAdded(div, track));
participant.on('trackUnsubscribed', trackRemoved);
participant.on('trackRemoved', trackRemoved);

@@ -85,0 +85,0 @@ document.body.appendChild(div);

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc