webrtc如何在保持通话的情况下实现手机端前、后置摄像头切换,将切换后摄像头的video传到远端, 增加了这段客户获取stream,但没传到远端,远端是黑屏的
navigator.mediaDevices.enumerateDevices()
.then(devices => {
// 找到类型为'videoinput'的设备,即摄像头
const videoInputDevices = devices.filter(device => device.kind === 'videoinput');
// 选择要使用的摄像头设备,例如,选择第一个设备
const selectedDevice = videoInputDevices[2];
console.log(selectedDevice.deviceId);
// 后台赋流
c2c_phone.setConstraint('video', 'deviceId', selectedDevice.deviceId);
console.log('强制使用后置摄像头');
})
.catch(error => {
console.error('Error enumerating media devices.', error);
});
这段是负责手机端展示和推流的,此函数可以用,是webrtc提供的
callShowStreams: function (call, localStream, remoteStream) {
c2c_ac_log('phone>>> callShowStreams');
c2c_audioPlayer.stop();
// The speaker selection works only in Chrome (except iOS Chrome)
if (!c2c_devices) {
c2c_remoteVideo.srcObject = remoteStream;
c2c_remoteVideo.volume = c2c_isRegularCall ? 1.0 : c2c_config.testCallVolume;
} else {
c2c_setRemoteVideoSinkId()
.catch((e) => {
c2c_ac_log(`Warning: remove video HTMLVideoElement.setSinkId(): "${e.message}" [Used default browser speaker]`, e);
})
.finally(() => {
c2c_remoteVideo.srcObject = remoteStream;
c2c_remoteVideo.volume = c2c_isRegularCall ? 1.0 : c2c_config.testCallVolume;
});
}
},