Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
});
});
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);
});
});
}
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);
});
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 }
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);
});
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);
});
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);
});
};
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);
});
};
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);
});
};
(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(