大网数据广告活动
Web 标准与前端开发

RTCPeerConnection: signalingState property

· 52CE 我爱测

The **`signalingState`** read-only property of the RTCPeerConnection interface returns a string value describing the state of the signaling process on the local end of the connection while connecting or reconnecting to another peer. See Signaling in our WebRTC session lifetime pa

WebRTC

The signalingState read-only property of the RTCPeerConnection interface returns a string value describing the state of the signaling process on the local end of the connection while connecting or reconnecting to another peer. See Signaling in our WebRTC session lifetime page.

Because the signaling process is a state machine, being able to verify that your code is in the expected state when messages arrive can help avoid unexpected and avoidable failures. For example, if you receive an answer while the signalingState isn't "have-local-offer", you know that something is wrong, since you should only receive answers after creating an offer but before an answer has been received and passed into RTCPeerConnection.setLocalDescription(). Your code will be more reliable if you watch for mismatched states like this and handle them gracefully.

This value may also be useful during debugging, for example.

In addition, when the value of this property changes, a RTCPeerConnection/signalingstatechange_event event is sent to the RTCPeerConnection instance.

Value

The allowed string values are:

  • stable
    • : There is no ongoing exchange of offer and answer underway. This may mean that the RTCPeerConnection object is new, in which case both the RTCPeerConnection.localDescription and RTCPeerConnection.remoteDescription are null; it may also mean that negotiation is complete and a connection has been established.
  • have-local-offer
    • : The local peer has called RTCPeerConnection.setLocalDescription(), passing in SDP representing an offer (usually created by calling RTCPeerConnection.createOffer()), and the offer has been applied successfully.
  • have-remote-offer
    • : The remote peer has created an offer and used the signaling server to deliver it to the local peer, which has set the offer as the remote description by calling RTCPeerConnection.setRemoteDescription().
  • have-local-pranswer
    • : The offer sent by the remote peer has been applied and an answer has been created (usually by calling RTCPeerConnection.createAnswer()) and applied by calling RTCPeerConnection.setLocalDescription(). This provisional answer describes the supported media formats and so forth, but may not have a complete set of ICE candidates included. Further candidates will be delivered separately later.
  • have-remote-pranswer
    • : A provisional answer has been received and successfully applied in response to an offer previously sent and established by calling setLocalDescription().
  • closed
    • : The RTCPeerConnection has been closed.

Examples

const pc = new RTCPeerConnection(configuration);
const state = pc.signalingState;

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。