-
-
Save digitallysavvy/37aeed28ed9958b8932c57a8b3ce3797 to your computer and use it in GitHub Desktop.
function to remove the remote containers
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
// 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