This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
60 lines (48 loc) · 1.75 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const avengersNames = ['Thor', 'Cap', 'Tony Stark', 'Black Panther', 'Black Widow', 'Hulk', 'Spider-Man'];
let randomName = avengersNames[Math.floor(Math.random() * avengersNames.length)];
const main = async () => {
/* Event handlers */
// When a stream is added to the conference
VoxeetSDK.conference.on('streamAdded', (participant, stream) => {
if (stream.type === 'ScreenShare') {
return addScreenShareNode(stream);
}
if (stream.getVideoTracks().length) {
// Only add the video node if there is a video track
addVideoNode(participant, stream);
}
addParticipantNode(participant);
});
// When a stream is updated
VoxeetSDK.conference.on('streamUpdated', (participant, stream) => {
if (stream.type === 'ScreenShare') return;
if (stream.getVideoTracks().length) {
// Only add the video node if there is a video track
addVideoNode(participant, stream);
} else {
removeVideoNode(participant);
}
});
// When a stream is removed from the conference
VoxeetSDK.conference.on('streamRemoved', (participant, stream) => {
if (stream.type === 'ScreenShare') {
return removeScreenShareNode();
}
removeVideoNode(participant);
removeParticipantNode(participant);
});
try {
// Initialize the Voxeet SDK
// WARNING: It is best practice to use the VoxeetSDK.initializeToken function to initialize the SDK.
// Please read the documentation at:
// https://docs.dolby.io/interactivity/docs/initializing
VoxeetSDK.initialize('customerKey', 'customerSecret');
// Open a session for the user
await VoxeetSDK.session.open({ name: randomName });
// Initialize the UI
initUI();
} catch (e) {
alert('Something went wrong : ' + e);
}
}
main();