Created
January 5, 2018 17:13
-
-
Save hugomallet/c80c5d2bcbfb7fd26a205a1726e93f8b to your computer and use it in GitHub Desktop.
twilio-video.js issue - Missing trackAdded events for the next published tracks
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>twilio-video.js issue publish / trackAdded</title> | |
</head> | |
<body> | |
<h1>twilio-video.js issue publish / trackAdded</h1> | |
<script src="https://media.twiliocdn.com/sdk/js/video/v1/twilio-video.min.js"></script> | |
<script src="./main.js"></script> | |
</body> | |
</html> |
This file contains hidden or 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 { connect } = window.Twilio.Video; | |
const params = new URLSearchParams(location.hash.replace(/^#/, '')); | |
let token = params.get('token'); | |
const publish = params.has('publish'); | |
if (!token) { | |
token = window.prompt('Add Twilio API token to URL hash (/#token=...)'); | |
params.set('token', token); | |
location.hash = params; | |
} | |
const onTrackAdded = track => { | |
console.log('trackAdded', track.name); | |
}; | |
const onParticipantConnected = participant => { | |
console.log('participantConnected', participant.identity); | |
participant.on('trackAdded', onTrackAdded); | |
participant.tracks.forEach(onTrackAdded); | |
}; | |
const connectRTC = (tok, roomName) => { | |
return connect(tok, { | |
name: roomName, | |
audio: false, | |
video: false, | |
logLevel: { | |
// default: 'debug', | |
// media: 'debug', | |
// signaling: 'debug', | |
// webrtc: 'debug' | |
} | |
}); | |
}; | |
const pub = room => { | |
navigator.mediaDevices | |
.getUserMedia({ audio: false, video: true }) | |
.then(stream => { | |
room.localParticipant.publishTrack(stream.getTracks()[0]) | |
.then(({ trackName }) => { console.log('pub', trackName); }); | |
}); | |
}; | |
connectRTC(token, 'test-room') | |
.then(room => { | |
console.log('connected', room); | |
room.on('participantConnected', onParticipantConnected); | |
room.participants.forEach(onParticipantConnected); | |
if (publish) { | |
pub(room); | |
setTimeout(() => { pub(room); }, 3000); | |
} | |
}) | |
.catch(error => { | |
console.error(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment