MenuMenu

RTCMultiConnection.closeSocket

Disconnect socket.io and close all peers

Usage

connection.closeSocket();

Best practice

btnLeave.onclick = function() {
    // disconnect with all users
    connection.getAllParticipants().forEach(function(pid) {
        connection.disconnectWith(pid);
    });

    // stop all local cameras
    connection.attachStreams.forEach(function(localStream) {
        localStream.stop();
    });

    // close socket.io connection
    connection.closeSocket();
};

Demo

<script src="https://rtcmulticonnection.herokuapp.com/dist/RTCMultiConnection.min.js"></script>
<script src="https://rtcmulticonnection.herokuapp.com/socket.io/socket.io.js"></script>

<script>
var connection = new RTCMultiConnection();

// this line is VERY_important
connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

// if you want audio+video conferencing
connection.session = {
    audio: true,
    video: true
};

btnLeave.onclick = function() {
    // disconnect with all users
    connection.getAllParticipants().forEach(function(pid) {
        connection.disconnectWith(pid);
    });

    // stop all local cameras
    connection.attachStreams.forEach(function(localStream) {
        localStream.stop();
    });

    // close socket.io connection
    connection.closeSocket();
};

connection.openOrJoin('your-room-id');
</script>