Skip to content

Instantly share code, notes, and snippets.

@soulfly
Last active December 20, 2017 20:15
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 soulfly/31481f6fec1d3c9433003d99db4cfa48 to your computer and use it in GitHub Desktop.
Save soulfly/31481f6fec1d3c9433003d99db4cfa48 to your computer and use it in GitHub Desktop.
switchVideoinput: function(mediaDeviceId, callbacks){
// removes the video track from both MediaStream and PeerConnection sender
videoRoomPlugin.webrtcStuff.myStream.removeTrack(videoRoomPlugin.webrtcStuff.myStream.getVideoTracks()[0]);
videoRoomPlugin.webrtcStuff.pc.removeTrack(videoRoomPlugin.webrtcStuff.pc.getSenders()[1])
// does a new getUserMedia just for video
var constraints = {
audio: false,
video: {deviceId: {exact: mediaDeviceId}}
};
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
// adds the new resulting video track to both MediaStream and PeerConnection
videoRoomPlugin.webrtcStuff.pc.addTrack(stream.getVideoTracks()[0], stream);
videoRoomPlugin.webrtcStuff.myStream.addTrack(stream.getVideoTracks()[0]);
videoRoomPlugin.createOffer({video: {deviceId: mediaDeviceId}, replaceVideo: true}, {
success: function(jsep) {
videoRoomPlugin.send({message: {request: "configure"}, "jsep": jsep});
},
error: function(error){
callbacks.error(error);
}
});
})
.catch(function(error) {
callbacks.error(error);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment