RTCMultiConnection Docs

RTCMultiConnection API Reference / "onNewSession" event

  1. "onNewSession" event allows you join a room with or without stream(s):
    1. Join with only audio
    2. Join with only video
    3. Join with audio and video
    4. Join with only screen
    5. Join with only data
    6. Join anonymously


    1. There are 5 teachers; and 20 students in a room! Teachers can see/talk each other. Students can just listen. Teachers can select any student to capture his webcam/mic at runtime!
    2. There are 3 broadcasters; and 15 listeners/viewers.
    3. User is given skype-like control i.e. join with audio or join with both webcam and mic!
  2. connection.onNewSession = function(session) {
         // session.userid
         // session.sessionid
         // session.extra
         // session.session i.e. {audio,video,screen,data}
    // or
    connection.onNewSession = function(session) {
        session.join();                           // join session as it is!
        session.join({audio: true});              // join session while allowing only audio
        session.join({video: true});              // join session while allowing only video
        session.join({screen: true});             // join session while allowing only screen
        session.join({audio: true, video: true}); // join session while allowing both audio and video
        session.join({oneway: true}); // to join with no stream!
  3. By default, onNewSession is fired once for each channel however you can override this default behavior by setting sessionid object; which allows you setup multiple sessions inside a single channel.
  4. var channelid = 'channel-id';
    var room1 = new RTCMultiConnection(channelid);
    var room2 = new RTCMultiConnection(channelid);
    var room3 = new RTCMultiConnection(channelid);
    var room4 = new RTCMultiConnection(channelid);
    room1.sessionid = 'room1';
    room2.sessionid = 'room2';
    room3.sessionid = 'room3';
    room4.sessionid = 'room4';
    room1.onNewSession = function(session) {};
    room2.onNewSession = function(session) {};
    room3.onNewSession = function(session) {};
    room4.onNewSession = function(session) {};
  5. onNewSession is useful to display list of rooms opened in a specific channel.
  6. If transmitRoomOnce is not "true"; onNewSession will be fired multiple times for same session. You can manage this behavior like this:
  7. connection.transmitRoomOnce = true;
    connection.onNewSession = function(session) {};
    // if you don't set transmitRoomOnce; then you MUST be aware of 
    // "onNewSession" multi-times invocation for same session				
    var sessions = {};
    connection.onNewSession = function(session) {
         if(sessions[session.sessionid]) return;
         sessions[session.sessionid] = session;

Want to ask a Question?

You can include your email for private conversation!