-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
105 lines (86 loc) · 2.81 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const Webex = require('webex');
// Change to your access token from developer.webex.com
const myAccessToken = 'YOUR_ACCESS_TOKEN';
if (myAccessToken === 'YOUR_ACCESS_TOKEN') {
alert('Make sure to update your access token in the index.js file!');
throw new Error('Make sure to update your access token in the index.js file!');
}
const webex = Webex.init({
credentials: {
access_token: myAccessToken
}
});
webex.config.logger.level = 'debug';
webex.meetings.register()
.catch((err) => {
console.error(err);
alert(err);
throw err;
});
function bindMeetingEvents(meeting) {
meeting.on('error', (err) => {
console.error(err);
});
// Handle media streams changes to ready state
meeting.on('media:ready', (media) => {
if (!media) {
return;
}
if (media.type === 'remoteVideo') {
document.getElementById('remote-view-video').srcObject = media.stream;
}
if (media.type === 'remoteAudio') {
document.getElementById('remote-view-audio').srcObject = media.stream;
}
});
// Handle media streams stopping
meeting.on('media:stopped', (media) => {
// Remove media streams
if (media.type === 'remoteVideo') {
document.getElementById('remote-view-video').srcObject = null;
}
if (media.type === 'remoteAudio') {
document.getElementById('remote-view-audio').srcObject = null;
}
});
// Of course, we'd also like to be able to leave the meeting:
document.getElementById('hangup').addEventListener('click', () => {
meeting.leave();
});
}
// Join the meeting and add media
// Join the meeting and add media through joinWithMedia method.
async function joinMeeting(meeting) {
const microphoneStream = await webex.meetings.mediaHelpers.createMicrophoneStream({
echoCancellation: true,
noiseSuppression: true,
});
const cameraStream = await webex.meetings.mediaHelpers.createCameraStream({ width: 640, height: 480 });
document.getElementById('self-view').srcObject=cameraStream.outputStream;
const meetingOptions = {
mediaOptions: {
allowMediaInLobby: true,
shareAudioEnabled: false,
shareVideoEnabled: false,
localStreams:{
camera:cameraStream,
microphone: microphoneStream
},
},
};
await meeting.joinWithMedia(meetingOptions);
}
document.getElementById('destination').addEventListener('submit', (event) => {
// again, we don't want to reload when we try to join
event.preventDefault();
const destination = document.getElementById('invitee').value;
return webex.meetings.create(destination).then((meeting) => {
// Call our helper function for binding events to meetings
bindMeetingEvents(meeting);
return joinMeeting(meeting);
})
.catch((error) => {
// Report the error
console.error(error);
});
});