RTCDataChannel.close()
method closes the
RTCDataChannel
. Either peer is permitted to call this method to initiate closure of the channel.
Closure of the data channel is not instantaneous. Most of the process of closing the connection is handled asynchronously; you can detect when the channel has finished closing by watching for a
close
event on the data channel.
The sequence of events which occurs in response to this method being called:
RTCDataChannel.readyState
被设为
"closing"
.
close()
returns to the caller.
RTCDataChannel.readyState
property is set to
"closed"
.
RTCDataChannel
is sent a
NetworkError
事件。
close
event is sent to the channel.
In Firefox, the
RTCDataChannel
interface was implemented under the name
DataChannel
until Firefox 24, so this method was called
DataChannel.close()
.
RTCDataChannel.close();
None.
undefined
.
var pc = new RTCPeerConnection();
var dc = pc.createDataChannel("my channel");
dc.onmessage = function (event) {
console.log("received: " + event.data);
dc.close(); // We decided to close after the first received message
};
dc.onopen = function () {
console.log("datachannel open");
};
dc.onclose = function (
console.log("datachannel close");
};
// Now negotiate the connection and so forth...
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCDataChannel.close()' in that specification. |
候选推荐 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
close
|
Chrome 56 | Edge ≤79 | Firefox Yes | IE No | Opera 43 | Safari No | WebView Android 56 | Chrome Android 56 | Firefox Android Yes | Opera Android 43 | Safari iOS No | Samsung Internet Android 6.0 |
完整支持
不支持
RTCDataChannel
close()
send()
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceCandidate
RTCIceTransport
RTCPeerConnection
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsEvent
RTCStatsReport
RTCTrackEvent