Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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(
Template.body.helpers({
error() {
return Template.instance().error.get();
},
room() {
return Template.instance().room.get();
},
disconnected() {
return Template.instance().disconnected.get();
}
});
connect(token).then(_room => {
room.set(_room);
_room.once('disconnected', disconnected.set(true));
_room.disconnect();
}, _error => {
error.set(_error);
});
constructor(props) {
super(props);
this.state = {};
connect(this.props.token).then(room => {
this.setState({ room });
room.once('disconnected', () => this.forceUpdate());
room.disconnect();
}, error => {
this.setState({ error });
});
}
}).then(localTracks => {
return connect('$TOKEN', {
name: 'my-room-name',
tracks: localTracks
});
}).then(room => {
console.log('Connected to Room:', room.name);
async function connectToRoom(creds) {
const videoTrack = await Video.createLocalVideoTrack();
const room = await Video.connect(creds.token, {
name: roomName,
tracks: [generateAudioTrack(), videoTrack]
});
return room;
}
joinRoom = async () => {
const { roomName } = this.state;
this.setState({ isJoining: true });
try {
const token = await this.getToken();
const localVideoTrack = await TwilioVideo.createLocalVideoTrack();
this.setState({ localVideoTrack });
const localAudioTrack = await TwilioVideo.createLocalAudioTrack();
this.setState({ localAudioTrack });
const videoRoom = await TwilioVideo.connect(
token,
{
name: roomName,
tracks: [localVideoTrack, localAudioTrack],
insights: false
}
);
videoRoom.on("disconnected", () => {
this.stopVideoTrack();
this.stopAudioTrack();
this.stopScreenTrack();
this.setState({
videoRoom: null
});
async function connectToRoom(creds) {
const room = await Video.connect( creds.token, {
name: roomName
});
return room;
}