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

Mor*_*ory 5 javascript screensharing webrtc kurento

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

NavigatorUserMediaError {name: "ScreenCaptureError", message: "", constraintName: ""}
Run Code Online (Sandbox Code Playgroud)

使用相同代码的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);
    });
Run Code Online (Sandbox Code Playgroud)

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

igr*_*cia 8

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

  • 已安装扩展程序以在Chrome中进行屏幕共享.在FF中,将域添加到白名单就足够了.检查扩展程序.
  • 在创建对象时,在选项包中传递有效值sendSource(screenwindow)kurentoUtils.WebRtcPeer
  • 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)
 });
Run Code Online (Sandbox Code Playgroud)

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

  • 'screen':会让你分享整个屏幕.如果您有多个,可以选择分享哪一个
  • 'window':让您在所有打开的窗口之间进行选择
  • [ 'screen', 'window' ]: 警告!只有Chrome接受,才能让用户在全屏或窗口之间进行选择.
  • 'webcam':这是您在此处未指定任何内容的默认值.猜猜会发生什么;-)