# RTCMultiConnection All-in-One test ® Muaz Khan

HOME © Muaz Khan . @WebRTCWeb . Github . Latest issues . What's New?

Setup Fake Data Connection?

## Select SessionType and Direction-of-Flow!

## WebRTC DataChannel

## Text Chat | ## Share Files

1. Mesh networking model is implemented to open multiple (1:1) interconnected peer connections
2. Maximum peer connections limit per page is 256 (on chrome) i.e. 256 users can connect together!

## How to use RTCMultiConnection?

    // https://cdn.webrtc-experiment.com/RTCMultiConnection.js

## Common Code

    var MODERATOR_CHANNEL_ID = 'ABCDEF'; // channel-id
    var MODERATOR_SESSION_ID = 'XYZ';    // room-id
    var MODERATOR_ID         = 'JKL';    // user-id
    var MODERATOR_SESSION    = {         // media-type
        audio: true,
        video: true
    };
    var MODERATOR_EXTRA      = {};       // empty extra-data

## Code for Room Moderator (i.e. Initiator)

    var moderator     = new RTCMultiConnection(MODERATOR_CHANNEL_ID);
    moderator.session = MODERATOR_SESSION;
    moderator.userid  = MODERATOR_ID;
    moderator.extra   = MODERATOR_EXTRA;
    moderator.open({
        dontTransmit: true,
        sessionid:    MODERATOR_SESSION_ID
    });

## Code for Room Participants

    var participants = new RTCMultiConnection(MODERATOR_CHANNEL_ID);
    participants.join({
        sessionid: MODERATOR_SESSION_ID,
        userid:    MODERATOR_ID,
        extra:     MODERATOR_EXTRA,
        session:   MODERATOR_SESSION
    });

## (optional) Handle how to get streams

    // same code can be used for participants
    // (it is optional)
    connection.onstreamid = function(event) {
        // got a clue of incoming remote stream
        // didn't get remote stream yet

        var incoming_stream_id = event.streamid;

        YOUR_PREVIEW_IMAGE.show();

        // or
        YOUR_PREVIEW_VIDEO.show();
    };

    // same code can be used for participants
    // it is useful
    connection.onstream = function(event) {
        // got local or remote stream
        // if(event.type == 'local')  {}
        // if(event.type == 'remote') {}

        document.body.appendChild(event.mediaElement);

        // or YOUR_VIDEO.src = event.blobURL;
        // or YOUR_VIDEO.src = URL.createObjectURL(event.stream);
    };

    // same code can be used for participants
    // it is useful but optional
    connection.onstreamended = function(event) {
        event.mediaElement.parentNode.removeChild(event.mediaElement);
    };

## Latest Issues

## Feedback

Enter your email too; if you want "direct" reply!

## Latest Updates