gpt4 book ai didi

javascript - Mozilla Firefox 中未触发事件回调

转载 作者:行者123 更新时间:2023-11-28 00:40:18 25 4
gpt4 key购买 nike

我正在使用 WebRTC 创建一个用于音频 session 的示例应用程序。我想做的是创建一个 RTCpeerconnection 对象并向其传递从调用者收到的远程描述。设置远程描述后,就会为对等连接对象触发“onaddstream”事件,我们可以将远程描述中接收到的流设置为某些音频/视频控件,如下面的示例代码所示:

function call() {        
chatHub.server.connect('receiver');
pc2 = new RTCPeerConnection(null, pcConstraints);
pc2.onicecandidate = iceCallback2;
pc2.onaddstream = gotRemoteStream;
}
function gotDescription1(desc) {
var dessc = new RTCSessionDescription({ type: 'offer', sdp: desc });
pc2.setRemoteDescription(dessc);
}
function gotRemoteStream(e) {
//attaching the stream to UI controls
audio2 = attachMediaStream(audio2, e.stream);
audio2.play();
pc2.createAnswer(gotDescription2, onCreateSessionDescriptionError,sdpConstraints);
callButton.disabled = true;
hangupButton.disabled = false;
}
function gotDescription2(desc) {
pc2.setLocalDescription(desc);
}
function iceCallback2(event) {
//---foo----
}

从示例代码中可以清楚地看出,流程从调用方法开始,该方法设置一个 PeerConnection 对象并设置其事件回调,然后由某个代码元素调用 gotDescription1,现在这是我们设置remoteDescription的地方,它应该在内部触发gotRemoteStream

所有这些在除 Firefox 之外的主要浏览器中都工作正常,为对象设置了远程描述,但没有 gotStream 的回调。

检查此内容以获取可能的解释。

https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection#Initializing_the_call

最佳答案

spec关于 onaddstream 说:

It is called any time a MediaStream is added by the remote peer. This will be fired only as a result of setRemoteDescription. Onnaddstream happens as early as possible after the setRemoteDescription. This callback does not wait for a given media stream to be accepted or rejected via SDP negotiation.

Firefox 目前在协商完成之前不会触发 onaddstream;请参阅Bug 1122306

无论如何,在您执行 SetLocalDescription() 之前,媒体不应该流动,所以只要让它不阻止您的接受即可。

关于javascript - Mozilla Firefox 中未触发事件回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28026876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com