--- title: RTCPeerConnection.connectionState slug: Web/API/RTCPeerConnection/connectionState translation_of: Web/API/RTCPeerConnection/connectionState ---

{{APIRef("WebRTC")}}

 

connectionState 只读,说明当前连接状态。状态值参见RTCPeerConnectionState ,值由一个peer connection返回。

值变化时,一个connectionstatechange 事件发送给RTCPeerConnection对象实例中。

Syntax

var connectionState = RTCPeerConnection.connectionState;

Value

The current state of the connection, as a value from the enum RTCPeerConnectionState.

{{page("/en-US/docs/Web/API/RTCPeerConnection", "RTCPeerConnectionState enum", 0, 1)}}

Example

var pc = new RTCPeerConnection(configuration);

/* ... */

var connectionState = pc.connectionState;

Specifications

Specification Status Comment
{{ SpecName('WebRTC 1.0', '#widl-RTCPeerConnection-connectionState', 'RTCPeerConnection.connectionState') }} {{ Spec2('WebRTC 1.0') }} Initial specification.

Browser compatibility

{{Compat("api.RTCPeerConnection.connectionState")}}

See also