我正在使用WebRTC进行多视频会议。 但是我发现,当其他人来到我的房间时,getUserMedia将被调用。
从WebRTC中的多连接开始,有没有方法只能调用一次getUsermedia?
答案 0 :(得分:1)
dontCaptureUserMedia=true
navigator.mediaDevices.getUserMedia
attachStreams
数组onstream
或手动设置localVideo.srcObject=stream
示例:
// first step
connection.dontCaptureUserMedia = true;
// seocond step
navigator.mediaDevices.getUserMedia({
audio: true,
video: true
}).then(function(stream) {
// third step
stream.isVideo = true;
connection.attachStreams = [stream];
// fourth step
var video = document.createElement('video');
video.playsinline = true;
video.controls = true;
video.muted = true;
video.srcObject = stream;
connection.onstream({
stream: stream,
type: 'local',
streamid: stream.id,
mediaElement: video
});
// last step: now open or join a room
connection.openOrJoin('your-room-id');
});
它如何工作?
dontCaptureUserMedia
将忽略(绕过)任何本地getUserMedia调用attachStreams
数组将用于与远程方共享其余的代码是随意的。