RTCDataChannel.close() - Web APIs 编辑
The 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
is set to"closing"
.- A background task is established to handle the remainder of the steps below, and
close()
returns to the caller. - The transport layer deals with any buffered messages; the protocol layer decides whether to send them or discard them.
- The underlying data transport is closed.
- The
RTCDataChannel.readyState
property is set to"closed"
. - If the transport was closed with an error, the
RTCDataChannel
is sent aNetworkError
event. - A
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()
.
Syntax
RTCDataChannel.close();
Parameters
None.
Return value
undefined
.
Example
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...
Specifications
Specification | Status | Comment |
---|---|---|
WebRTC 1.0: Real-time Communication Between Browsers The definition of 'RTCDataChannel.close()' in that specification. | Candidate Recommendation | Initial specification. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论