使用 Kurento Media Server 在 Chrome 中获取"ScreenCaptureError"



我正在尝试与Kurento WebRtc服务器共享屏幕。但是得到这个错误:

NavigatorUserMediaError {name: "ScreenCaptureError", message: "", constraintName: ""}

使用相同代码的Firefox中并没有错误。用于webrtc:的约束

    var constraints = {
        audio: true,
        video: {
            mandatory : {
                chromeMediaSource: 'screen',
                maxWidth: 1920,
                maxHeight: 1080,
                maxFrameRate: 30,
                minFrameRate: 15,
                minAspectRatio: 1.6
            },
            optional: []
        }
    }
    var options = {
           localVideo : video,
           onicecandidate : onIceCandidate,
           mediaConstraints : constraints
    }
    webRtcPeer = new kurentoUtils.WebRtcPeer.WebRtcPeerSendonly(options,function(error) {
       if (error) {
           return console.error(error);
       }
       webRtcPeer.generateOffer(onOfferPresenter);
    });

如何使用chrome和kurento共享屏幕?

通过WebRTC与Kurento共享屏幕与共享网络摄像头完全相同:从客户端获取流并协商端点。在进行屏幕共享时,棘手的部分是获取流。kurento utils js库将在这方面为您提供一些帮助,因为您可以在客户端中创建WebRtcPeer对象,指示您想要共享屏幕或窗口。你只需要确保你的

  • 安装了一个扩展程序,可以在Chrome中进行屏幕共享。在FF中,将域添加到白名单中就足够了。检查此扩展
  • 创建kurentoUtils.WebRtcPeer对象时,在选项袋中传递有效的sendSource值(screenwindow
  • 在您的窗口对象中有一个getScreenConstraints方法,因为它将在这里使用。getScreenConstraints应该返回一组有效的约束,具体取决于浏览器。您可以在此处检查该函数的实现

我认为这就足够了。我们正在使用我们自己的getScreenConstrains和扩展与库进行屏幕共享,它运行良好。一旦你有了这些,使用kurento utils js库进行屏幕共享就很容易了。创建对等时只需要传递sendSource

 var constraints = {
   audio: false,
   video: true
 }
 var options = {
   localVideo: videoInput, //if you want to see what you are sharing
   onicecandidate: onIceCandidate,
   mediaConstraints: constraints,
   sendSource: 'screen'
 }
 webRtcPeerScreencast = kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function(error) {
   if (error) return onError(error) //You'll need to use whatever you use for handling errors
   this.generateOffer(onOffer)
 });

sendSource的值是一个字符串,它取决于您想要共享的内容

  • 'screen':将让您共享整个屏幕。如果您有多个,您可以选择要共享的
  • 'window':允许您在所有打开的窗口之间进行选择
  • [ 'screen', 'window' ]:警告!只有Chrome接受,这将允许用户在全屏或窗口之间进行选择
  • 'webcam':这是的默认值。这里没有指定任何内容。猜猜会发生什么;-)

最新更新