rtcmulticonnection

RTCMultiConnection, failing to set up and connect to rooms.


I am trying to test a real-time data connection between peers using RTCMultiConnection.

Setting up a session/room seems to work, but once it has been made, peers cannot seem to join. If I run this function again from another browser, while a session is opened, it still says the room does not exist and it opens up a new one, rather than joining in.

The channel and session id's are identical, so why does the peer not find the session?

function makeOrJoinRoom(id){
	channelid = 'channel'+id;
	roomid = 'room'+id;
	sessionMedia = {audio: false, video: false, data: true};
	
	var connection = new RTCMultiConnection(channelid);
	connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';
	connection.checkPresence( roomid, function(roomExists, roomid) {
		alert('checking presence...');
		alert('Room exists='+roomExists);
  		if(roomExists) {
  			alert('I am a participant');
    		connection.join({
       			 sessionid: roomid,
        		 session: sessionMedia
    			});
  		} else {
  			alert('I am the moderator');
  			connection.session =  sessionMedia;
    		connection.open({
        		sessionid: roomid
    		});
  		}
	});
}


Solution

  • Please replace your function with this:

    function makeOrJoinRoom(roomid) {
        var connection = new RTCMultiConnection();
    
        connection.session = {
            data: true
        };
    
        connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';
    
        alert('checking presence...');
        connection.checkPresence(roomid, function(roomExist, roomid) {
            alert('Room exists=' + roomExist);
            if (roomExist === true) {
                alert('I am a participant');
                connection.join(roomid);
            } else {
                alert('I am the moderator');
                connection.open(roomid);
            }
        });
    
        connection.onopen = function(event) {
            alert('WebRTC chat opened!');
        };
    }
    
    // call above function like this
    makeOrJoinRoom('your-unique-room-id');