5

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

4

1 回答 1

9

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

  • 安装了一个扩展来在 Chrome 中进行屏幕共享。在FF中,将域添加到白名单就足够了。检查这个扩展。
  • 创建对象时在选项包中传递一个有效值sendSourcescreen或)windowkurentoUtils.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)
 });

的值sendSource是一个字符串,这取决于你想分享什么

  • 'screen': 会让你共享整个屏幕。如果你有多个,你可以选择分享哪一个
  • 'window':让您在所有打开的窗口之间进行选择
  • [ 'screen', 'window' ]: 警告!仅被 Chrome 接受,这将让用户在全屏或窗口之间进行选择。
  • 'webcam':这是您在这里不指定任何内容的默认值。猜猜会发生什么;-)
于 2016-04-08T06:50:31.667 回答