0

我正在使用 webrtc+janusgateway+streamCapture 构建流服务。

这,开始流式传输视频:

  public streamVideo() {
    var video = $('#video1').get(0);
        var stream;

    video.onplay = () => {
      if (video.captureStream) {
        stream = video.captureStream();
      } else if (video.mozCaptureStream) {
        stream = video.mozCaptureStream();
      } else {
        alert('captureStream() not supported');
      }

            console.log(stream);
      $("#secondvideoforll").get(0).srcObject = stream;

    this.sfutest.createOffer(
      {
        media: { audioRecv: 0, videoRecv: 0, audioSend: 1, videoSend: 1}, // Publishers are sendonly
        stream: stream,
        success: (jsep) => {
          Janus.debug("Got publisher SDP!");
          Janus.debug(jsep);
          var publish = { "request": "configure", "audio": 1, "video": 1 };
          this.sfutest.send({"message": publish, "jsep": jsep});
        },
        error: (error) => {
          Janus.error("WebRTC111 error:", error);
        }
      });
    }
  }

视频播放效果很好,但是当我尝试创建报价(以及进一步的 addStream)时。我收到此错误:

WebRTC111 error: DOMException [InternalError: "Cannot create an offer with no local tracks, no offerToReceiveAudio/Video, and no DataChannel."
code: 0
nsresult: 0x0]

相同的报价创建(不带 stream 参数)适用于网络摄像头流式传输,但不适用于视频流。

我发现的主要区别是网络摄像头使用:LocalMediaStream,而我streamCapture使用 MediaStream。

关于这个有什么想法吗?

4

1 回答 1

0

当调用 video.captureStream() getTracks() 返回空数组,但在 1.5 秒后,它按预期返回轨道。

Error produced if no tracks are added: WebRTC111 error: DOMException [InternalError: "Cannot create an offer with no local tracks, no offerToReceiveAudio/Video, and no DataChannel

Adding this for doc purposes, as others might find this confusing.

Solution:

setInterval(function(){
// We wait till the mediaTracks are added to mediaStream
console.log(stream.getTracks());
// Further actions with the mediaStream
}, 1000);

Thanks!

Reference: https://github.com/w3c/webrtc-pc/issues/923

于 2016-11-08T13:29:12.523 回答