WebRTC:在Firefox中重新谈判 [英] WebRTC: Renegotiation in firefox
问题描述
音频
,我得到错误:lockquote>
NotSupportedError:removeStream not yet实施
告诉相同,但是这个告诉重新协商事件被支持,但不是 removeStream
重新协商的关键部分?我在Windows 7中使用的是Firefox 39版本。我很困惑,firefox目前还不支持重新协商,对吧? 解决方案
对单个轨道使用 replaceTrack
,而不是替换整个流。这个例子假设你有一个对等连接 pc1
和一个新流 newStream
来取代它。获取发件人,并用新流中的适当曲目替换曲目。工作示例此处。
Promise.all(pc1.getSenders()。map(sender =>
sender.replaceTrack((sender.track.kind ==audio)?
newStream.getAudioTracks() (0):
newStream.getVideoTracks()[0]))
.then(()=> log(Flip!))
.catch(failed);
另外请注意,从您的第一个链接:
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));
});
});
$ b $ p
$ b 注意这个例子调用 pc1.addTrack not pc1.addStream
而在相反的情况下,
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ();
screenSenders.forEach(sender){
pc1.removeTrack(sender);
});
}
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 not yet implemented
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?
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));
});
});
}
Notice that this example calls pc1.addTrack
not pc1.addStream
And in the same in reverse, for removing - pc1.removeTrack
:
function stopScreenShare() {
screenStream.stop();
screenSenders.forEach(sender) {
pc1.removeTrack(sender);
});
}
这篇关于WebRTC:在Firefox中重新谈判的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!