←HOME

Multi-Session Establishment using RTCMultiConnection

Copyright © 2013 Muaz Khan<@muazkh>.

Join one of following sessions


Copy any of the following session-ids and paste in above input-box:
  1. : session-id for audio + video conferencing
  2. : session-id for audio + video broadcasting
  3. : session-id for audio-only conferencing
  4. : session-id for one-way only-audio broadcasting
  5. : session-id for one-way only-video broadcasting

Open Five Unique Sessions

Local Media Streams

Remote Media Streams



How to open multi-sessions using RTCMultiConnection?

<script src="https://webrtc-experiment.appspot.com/RTCMultiConnection-v1.1.js"></script>
<script>
    var connection = new RTCMultiConnection();

    // get access to local or remote streams
    connection.onstream = function (stream) {
        if (stream.type === 'local') {
            //------------------------
            //-------------- see here!
            //------------------------
            var stream = stream.stream;
            open_audio_conferencing_session(stream);
            open_audio_video_broadcasting_session(stream);
            open_only_audio_broadcasting_session(stream);
            open_only_video_broadcasting_session(stream);
        }
    }
	
    // to create/open a new session
    connection.open('session-id');

    // if someone already created a session; to join it: use "connect" method
    connection.connect('session-id');

    function open_audio_conferencing_session(stream) {
        var new_connection = new RTCMultiConnection();

        // -------- getting only-audio stream!
        stream = new MediaStream(stream.getAudioTracks());
        new_connection.attachStream = stream;

        new_connection.session = 'only-audio';

        new_connection.open('audio conferencing session-id');
    }

    function open_audio_video_broadcasting_session(stream) {
        var new_connection = new RTCMultiConnection();

        // -------- attaching same stream!
        new_connection.attachStream = stream;

        // -------- setting 'one way' direction
        new_connection.direction = 'one-way';

        new_connection.open('audio-video broadcasting session-id');
    }

    function open_only_audio_broadcasting_session(stream) {
        var new_connection = new RTCMultiConnection();

        // -------- getting only-audio stream!
        stream = new MediaStream(stream.getAudioTracks());
        new_connection.attachStream = stream;

        new_connection.session = 'only-audio';
        new_connection.direction = 'one-way';

        new_connection.open('audio one-way broadcasting session-id');
    }

    function open_only_video_broadcasting_session(stream) {
        var new_connection = new RTCMultiConnection();

        // -------- getting only-video stream!
        stream = new MediaStream(stream.getVideoTracks());
        new_connection.attachStream = stream;

        new_connection.session = 'only-video';
        new_connection.direction = 'one-way';

        new_connection.open('video one-way broadcasting session-id');
    }
</script>


Why multi-sessions?

  1. Sometimes you want to one-way broadcast your video for users who have no-camera or no-microphone
  2. You may want to allow audio-conferencing along with video-conferencing in the same session / same stream!
  3. You may want to open one-to-one ports between main-peer and the server to record speech or to further broadcast the stream
  4. You may want to allow end-users to anonymously join/view main-video session or chatting room
  5. You may want to open one-to-one private session between chairperson and CEO! — in the same session; same page!
There are many other use-cases of multi-sessions.

Source code and Documentation on Github!