RTCPeerConnection.close() - Web APIs 编辑
Experimental
This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The RTCPeerConnection.close()
method closes the current peer connection.
Syntax
peerConnection.close();
This method has no parameters, and returns nothing.
Calling this method terminates the RTCPeerConnection's ICE agent, ending any ongoing ICE processing and any active streams. This also releases any resources in use by the ICE agent, including TURN permissions. All RTCRtpSender
objects are considered to be stopped once this returns (they may still be in the process of stopping, but for all intents and purposes, they're stopped).
Once this method returns, the signaling state as returned by RTCPeerConnection.signalingState
is closed
.
Make sure that you delete
all references to the previous RTCPeerConnection
before attempting to create a new one that connects to the same remote peer, as not doing so might result in some errors depending on the browser.
Example
var pc = new RTCPeerConnection();
var dc = pc.createDataChannel("my channel");
dc.onmessage = function (event) {
console.log("received: " + event.data);
pc.close(); // We decided to close after the first received message
};
dc.onopen = function () {
console.log("datachannel open");
};
dc.onclose = function () {
console.log("datachannel close");
};
Specifications
Specification | Status | Comment |
---|---|---|
WebRTC 1.0: Real-time Communication Between Browsers The definition of 'RTCPeerConnection.close()' in that specification. | Candidate Recommendation | Initial specification. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论