Created
November 6, 2019 13:57
-
-
Save sanatem/a4471aa0b8763509b74d2f45401277f6 to your computer and use it in GitHub Desktop.
Webex Meetings demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Webex = require('webex'); | |
const myAccessToken = 'YOUR_ACCESS_TOKEN'; | |
if (myAccessToken === 'YOUR_ACCESS_TOKEN') { | |
alert('Make sure to update your access token in the index.js file!'); | |
return; | |
} | |
webex = Webex.init({ | |
credentials: { | |
access_token: myAccessToken | |
} | |
}); | |
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 === 'local') { | |
document.getElementById('self-view').srcObject = media.stream; | |
} | |
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 === 'local') { | |
document.getElementById('self-view').srcObject = null; | |
} | |
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 | |
function joinMeeting(meeting) { | |
return meeting.join().then(() => { | |
const mediaSettings = { | |
receiveVideo: true, | |
receiveAudio: true, | |
receiveShare: false, | |
sendVideo: true, | |
sendAudio: true, | |
sendShare: false | |
}; | |
// Get our local media stream and add it to the meeting | |
return meeting.getMediaStreams(mediaSettings).then((mediaStreams) => { | |
const [localStream, localShare] = mediaStreams; | |
meeting.addMedia({ | |
localShare, | |
localStream, | |
mediaSettings | |
}); | |
}); | |
}); | |
} | |
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); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment