如何在 RTCMulticonnection 中切换摄像头
我获取设备列表及其 ID
var videoDevices = document.getElementById('video-devices');
var audioDevices = document.getElementById('audio-devices');
connection.DetectRTC.load(function() {
connection.DetectRTC.audioInputDevices.forEach(function(device) {
var option = document.createElement('option');
option.innerHTML = device.label;
option.value = device.id;
document.querySelector('select').appendChild(option);
});
connection.DetectRTC.videoInputDevices.forEach(function(device) {
var option = document.createElement('option');
option.innerHTML = device.label;
option.value = device.id;
videoDevices.appendChild(option);
});
});
并尝试通过以下方式更改相机。取自GitHub 问题
document.getElementById('switch-camera').onclick = function() {
var videoSourceId = videoDevices.value;
connection.codecs.video = 'VP8';
connection.bandwidth = { // all values in kbits/per/seconds
audio: 192,
video: 512,
screen: 512
};
connection.stopMediaAccess();
setTimeout(() => {
connection.mediaConstraints.video.optional = [{
sourceId: videoSourceId
}];
connection.addStream({audio: true, video: true});
},2000);
};
但是没有使用相机根本不会改变我尝试了很多方法但失败了
WebRTC 示例中的这个示例可能有助于它做我想要的,但对与 RTCMulticoonection 的集成感到困惑。