Skip to content

Instantly share code, notes, and snippets.

@digitallysavvy
Last active July 19, 2019 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitallysavvy/37aeed28ed9958b8932c57a8b3ce3797 to your computer and use it in GitHub Desktop.
Save digitallysavvy/37aeed28ed9958b8932c57a8b3ce3797 to your computer and use it in GitHub Desktop.
function to remove the remote containers
// remove the remote-container when a user leaves the channel
client.on("peer-leave", function(evt) {
var streamId = evt.stream.getId(); // the the stream id
if(remoteStreams[streamId] != undefined) {
remoteStreams[streamId].stop(); // stop playing the feed
delete remoteStreams[streamId]; // remove stream from list
if (streamId == mainStreamId) {
var streamIds = Object.keys(remoteStreams);
var randomId = streamIds[Math.floor(Math.random()*streamIds.length)]; // select from the remaining streams
remoteStreams[randomId].stop(); // stop the stream's existing playback
var remoteContainerID = '#' + randomId + '_container';
$(remoteContainerID).empty().remove(); // remove the stream's miniView container
remoteStreams[randomId].play('full-screen-video'); // play the random stream as the main stream
mainStreamId = randomId; // set the new main remote stream
} else {
var remoteContainerID = '#' + streamId + '_container';
$(remoteContainerID).empty().remove(); //
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment