How To Swap Camera Sources In Webrtc While In A Call (javascript Apis)
On iOS I can do: // set a new camera id cameraId = ([cameraId isEqualToString:frontCameraId]) ? backCameraId : frontCameraId; // determine if the stream has a video track BOOL h
Solution 1:
This is an experimental technology
WebRTC Javascript code samples contain an example of camera selection :
with source code available on github :
Get video|audio sources using MediaDevices.enumerateDevices (on chrome and firefox)
https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices
MediaStreamTrack.getSources (only chrome) was deprecated in favour of MediaDevices.enumerateDevices()
navigator.mediaDevices.enumerateDevices =
navigator.mediaDevices.enumerateDevices || function() {
returnnewPromise(function(resolve) {
var infos = [
{kind: 'audioinput', deviceId: 'default', label: '', groupId: ''},
{kind: 'videoinput', deviceId: 'default', label: '', groupId: ''}
];
resolve(infos);
});
};
if (browserDetails.version < 41) {
// Work around http://bugzil.la/1169665var orgEnumerateDevices =
navigator.mediaDevices.enumerateDevices.bind(navigator.mediaDevices);
navigator.mediaDevices.enumerateDevices = function() {
returnorgEnumerateDevices().then(undefined, function(e) {
if (e.name === 'NotFoundError') {
return [];
}
throw e;
});
};
}
}
to swap cameras, @omar-khaled answer from @wpp Changing a MediaStream of RTCPeerConnection
_this.rtc.localstream.stop();
_this.rtc.pc.removeStream(_this.rtc.localstream);
gotStream = function (localstream_aud){
var constraints_audio={
audio:true
}
_this.rtc.localstream_aud = localstream_aud;
_this.rtc.mediaConstraints= constraints_audio;
_this.rtc.createOffer();
}
getUserMedia(constraints_audio, gotStream);
gotStream = function (localstream){
var constraints_screen={
audio:false,
video:{
mandatory:{
chromeMediaSource: 'screen'
}
}
}
_this.rtc.localstream = localstream;
_this.rtc.mediaConstraints=constraints_video;
_this.rtc.createStream();
_this.rtc.createOffer();
}
getUserMedia(constraints_video, gotStream);
Post a Comment for "How To Swap Camera Sources In Webrtc While In A Call (javascript Apis)"