how to close a webrtc datachannel?
Asked Answered
F

1

3

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?

Fahlband answered 20/7, 2015 at 2:5 Comment(1)
Can you clarify exactly what's wrong? If you're not using media, only datachannels, why are you trying to remove streams and pause video elements?Christman
C
8

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();
Christman answered 20/7, 2015 at 2:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.