2

我不能使用以下方法。

因为我只使用数据通道(不使用 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>

有没有办法关闭数据通道?

4

1 回答 1

7

要关闭RTCDataChannel,您可以调用close()- 这也可以在 RTCPeerConnection 上调用,这将关闭在 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();
于 2015-07-20T02:58:31.433 回答