how to close a webrtc datachannel?

 ̄綄美尐妖づ 提交于 2019-12-11 06:56:02

问题


I can not use the following methods.

Because i use only datachannel (not use getUserMedia)

<script>
    peerConnection.removeStream(remoteStream)
    remoteVideo.onerror = null;
    remoteVideo.pause();
    remoteVideo.src = undefined;
    remoteStream.stop();
    remoteStream.onended = null;
    remoteStream = null;

    peerConnection.removeStream(localStream)

    localVideo.onerror = null;
    localVideo.pause();
    localVideo.src = undefined;
    localStream.stop();
    localStream.onended = null;
    localStream = null;
</script>

Is there a way to close a data channel?


回答1:


To close an RTCDataChannel, you call close() - this can be called on an RTCPeerConnection as well, which will close all datachannels created on the peerconnection.

var pc = new RTCPeerConnection();
var dc = pc.createDataChannel("my channel");
var dc2 = pc.createDataChannel("my other channel");

dc.onclose = function () {
  console.log("datachannel close");
};

dc2.onclose = function () {
  console.log("dc2 close");
};

dc.close();
pc.close();


来源:https://stackoverflow.com/questions/31507934/how-to-close-a-webrtc-datachannel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!