在 Mozilla Firefox 中不触发事件回调
event callback not firing in Mozilla Firefox
我正在为使用 WebRTC 的音频会议创建示例应用程序。我想要做的是创建一个 RTCpeerconnection
object 并将从调用者收到的远程描述传递给它。一旦设置了远程描述,然后为 peer-connection object 触发 'onaddstream' 事件,我们可以将远程描述中接收到的流设置为某些 audio/video 控件,如示例所示代码如下:
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
object 并设置了它的事件回调,然后 gotDescription1
被一些代码元素调用,现在这是我们设置 remoteDescription 的地方,它应该在内部触发 gotRemoteStream
。
除 Firefox 外,所有这些在主要浏览器中都运行良好,为 object 设置了远程描述,但没有为 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 目前在协商完成之前不会触发 addstream;见 Bug 1122306
无论如何,在您执行 SetLocalDescription() 之前,媒体不应该流动,所以只要让它不影响您的接受即可。
我正在为使用 WebRTC 的音频会议创建示例应用程序。我想要做的是创建一个 RTCpeerconnection
object 并将从调用者收到的远程描述传递给它。一旦设置了远程描述,然后为 peer-connection object 触发 'onaddstream' 事件,我们可以将远程描述中接收到的流设置为某些 audio/video 控件,如示例所示代码如下:
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
object 并设置了它的事件回调,然后 gotDescription1
被一些代码元素调用,现在这是我们设置 remoteDescription 的地方,它应该在内部触发 gotRemoteStream
。
除 Firefox 外,所有这些在主要浏览器中都运行良好,为 object 设置了远程描述,但没有为 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 目前在协商完成之前不会触发 addstream;见 Bug 1122306
无论如何,在您执行 SetLocalDescription() 之前,媒体不应该流动,所以只要让它不影响您的接受即可。