使用Kurento Media Server在Chrome中获取“ScreenCaptureError”

时间:2016-04-07 19:33:46

标签: javascript webrtc kurento screensharing

我正在尝试与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分享我的屏幕?

1 个答案:

答案 0 :(得分:7)

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

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

我认为这应该足够了。我们正在使用我们自己的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':这是您在此处未指定任何内容的默认值。猜猜会发生什么; - )