WebRTC:在 Firefox 中重新协商 [英] WebRTC: Renegotiation in firefox

查看:37
本文介绍了WebRTC:在 Firefox 中重新协商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据这篇文章,重新协商在 firefox v38 中实现,我们可以从相同的对等连接中添加删除流而无需创建新的流,但我找不到任何工作演示来支持该声明,当我尝试时,两个用户在视频模式下聊天,我更改了其中一个他们的流到 audio,我收到错误:

According to this article, re-negotiation is implemented in firefox v38 and we can add remove streams from same peerconnections without creating new ones, but I am unable to find any working demos to support that claim, and when I tried it, two users chating in video mode, I changing one of their stream to audio, I get the error:

NotSupportedError:removeStream 尚未实现

NotSupportedError: removeStream not yet implemented

this 也是如此,但 说明支持重新协商事件,但 removeStream 不是重新协商的关键部分吗?我在 Windows 7 中使用 Firefox 39 版.我很困惑,firefox 尚不支持重新协商,对吗?

this tells the same, but this tells renegotiation events are supported, but isn't removeStream key part of renegotiation? I am using firefox version 39 in windows 7. I am confused, renegotiation is not yet supported in firefox, right?

推荐答案

尝试将 replaceTrack 用于单个轨道,而不是替换整个流.这个例子假设你有一个对等连接 pc1 和一个新的流 newStream 来替换它.获取发件人,并用新流中的适当曲目替换曲目.工作示例 此处.

Try using replaceTrack for individual tracks, instead of replacing the entire stream. This example assumes you have a peer connection pc1 and a new stream newStream to replace on it. Get the senders, and replace the tracks with appropriate tracks from the new stream. Working sample here.

Promise.all(pc1.getSenders().map(sender =>
  sender.replaceTrack((sender.track.kind == "audio")?
                      newStream.getAudioTracks()[0] :
                      newStream.getVideoTracks()[0])))
.then(() => log("Flip!"))
.catch(failed);

还要注意这一点,来自您的第一个链接:

Also note this, from your first link:

function screenShare() {
    let screenConstraints = {video: {mediaSource: "screen"}};

    navigator.mediaDevices.getUserMedia(screenConstraints)
    .then(stream) {
        stream.getTracks().forEach(track) {
            screenStream = stream;
            screenSenders.push(pc1.addTrack(track, stream));
        });
    });
}

注意这个例子调用的是 pc1.addTrack 而不是 pc1.addStream

Notice that this example calls pc1.addTrack not pc1.addStream

反之亦然,用于删除 - pc1.removeTrack:

And in the same in reverse, for removing - pc1.removeTrack:

function stopScreenShare() {
    screenStream.stop();
    screenSenders.forEach(sender) {
        pc1.removeTrack(sender);
    });
}

这篇关于WebRTC:在 Firefox 中重新协商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆