RTCMultiConnection exception on connection.addStream()

RTCMultiConnection exception on connection.addStream()

本文关键字:addStream connection exception on RTCMultiConnection      更新时间:2023-09-26

我正在尝试将源 - 屏幕切换到网络摄像头(LIVE)。我从函数 addStream() 开始,执行后出现此错误:

DOMException: Failed to execute 'webkitGetUserMedia' on 'Navigator': At least one of audio and video must be requested(…) Object {audio: false, video: false}

这是代码:

       function switchToWebcam() {
            connection.sdpConstraints.mandatory = {
                OfferToReceiveAudio: true,
                OfferToReceiveVideo: true
            };
            connection.addStream({
                video: true,
                audio: true
            });
        }

也许还有其他方法可以切换源。只是找不到例子。谢谢。

以下是在屏幕共享会话中添加音频+视频流的方法:

connection.session.audio = true;
connection.session.video = true;
connection.addStream({
    audio: true, // because session.audio==true, now it works
    video: true, // because session.video==true, now it works
    oneway: true
});

您可以在金丝雀上尝试此音频+屏幕演示。该演示也有"添加视频"按钮。

  • https://rtcmulticonnection.herokuapp.com/demos/Audio+ScreenSharing.html