onsignalingstatechange event handler property of the RTCPeerConnection interface specifies a function to be called when the signalingstatechange event occurs on an RTCPeerConnection 接口。 The function receives as input the event object of type 事件 ; this event is sent when the peer connection's signalingState changes, which may happen either because of a call to setLocalDescription() or to setRemoteDescription() .

句法

rtcPeerConnection.onsignalingstatechange = errorHandler;
					

Set this to a function which you provide that receives an 事件 object as input; this contains the signalingstatechange event. This event object doesn't provide details about what changed, but you can examine the signalingState property to determine what the new state is.

You may also, as always, set up a handler for the signalingstatechange event using addEventListener() :

myRTCPeerConnection.addEventListener("signalingstatechange", mySignalingStateChangeHandler);
					

Or, using an anonymous (inline) handler:

myRTCPeerConnection.addEventListener("signalingstatechange", event => {
  /* handle the event here */
});
					

范例

This snippet shows a handler for signalingstatechange that looks for the "have-local-pranswer" signaling state—indicating that a remote offer has been received and a local description of type "pranswer" has been applied in response.

pc.onsignalingstatechange = function(event) {
  if (pc.signalingState === "have-local-pranswer") {
    // setLocalDescription() has been called with an answer
  }
};
					

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.onsignalingstatechange' in that specification.
候选推荐 最初的规范。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
onsignalingstatechange Chrome 28 Edge 15 Firefox 22 IE No Opera 43
43
Promise-based version.
不支持 37 — 43
Safari 11 WebView Android Yes Chrome Android 28 Firefox Android 44 Opera Android 43
43
Promise-based version.
不支持 37 — 43
Safari iOS Yes Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: