Skip to content

Commit

Permalink
#580 checkPresence method finally works. (SSE)
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed May 16, 2018
1 parent b9bf7ff commit fee4df2
Show file tree
Hide file tree
Showing 8 changed files with 5,084 additions and 4,999 deletions.
20 changes: 11 additions & 9 deletions demos/SSEConnection.html
Expand Up @@ -78,13 +78,15 @@ <h1>

document.getElementById('open-or-join-room').onclick = function() {
disableInputButtons();
// connection.openOrJoin(document.getElementById('room-id').value);
connection.checkPresence(document.getElementById('room-id').value, function(isRoomExist, roomid) {
disableInputButtons('enable');
if(isRoomExist === true) {
document.getElementById('join-room').onclick();
console.info('checkPresence', isRoomExist, roomid);

if(isRoomExist) {
connection.join(roomid);
}
else {
document.getElementById('open-room').onclick();
connection.open(roomid);
}
});
};
Expand Down Expand Up @@ -126,11 +128,11 @@ <h1>
}
};

function disableInputButtons(enable) {
document.getElementById('open-room').disabled = !enable;
document.getElementById('join-room').disabled = !enable;
document.getElementById('open-or-join-room').disabled = !enable;
document.getElementById('room-id').disabled = !enable;
function disableInputButtons() {
document.getElementById('open-room').disabled = true;
document.getElementById('join-room').disabled = true;
document.getElementById('open-or-join-room').disabled = true;
document.getElementById('room-id').disabled = true;
}

// ......................................................
Expand Down
21 changes: 14 additions & 7 deletions dev/RTCMultiConnection.js
Expand Up @@ -956,7 +956,15 @@
audio: isAudioPlusTab(connection) ? getAudioScreenConstraints(screen_constraints) : false,
video: screen_constraints,
isScreen: true
}, (session.audio || session.video) && !isAudioPlusTab(connection) ? connection.invokeGetUserMedia(null, gumCallback) : gumCallback);
}, function(stream) {
if ((session.audio || session.video) && !isAudioPlusTab(connection)) {
connection.invokeGetUserMedia(null, function(stream) {
gumCallback(stream);
});
} else {
gumCallback(stream);
}
});
});
} else if (session.audio || session.video) {
connection.invokeGetUserMedia(null, gumCallback);
Expand Down Expand Up @@ -1522,14 +1530,13 @@
// check if room exist on server
// we will pass roomid to the server and wait for callback (i.e. server's response)
connection.checkPresence = function(remoteUserId, callback) {
if (SocketConnection.name && SocketConnection.name === 'SSEConnection') {
if (SocketConnection.name === 'SSEConnection') {
SSEConnection.checkPresence(remoteUserId, function(isRoomExist, roomid) {
if (!isRoomExist) {
connection.sessionid = connection.userid = roomid;
connection.isInitiator = true;
}

if (!connection.socket) {
if (!isRoomExist) {
connection.userid = roomid;
}

connection.connectSocket(function() {
callback(isRoomExist, roomid);
});
Expand Down
13 changes: 2 additions & 11 deletions dev/RTCPeerConnection.js
Expand Up @@ -533,18 +533,9 @@ function PeerInitiator(config) {
}

try {
if (peer.iceConnectionState.search(/closed|failed/gi) === -1) {
peer.getRemoteStreams().forEach(function(stream) {
var streamEndedEvent = 'ended';

if ('oninactive' in stream) {
streamEndedEvent = 'inactive';
}

fireEvent(stream, streamEndedEvent);
});
if (peer.nativeClose !== peer.close) {
peer.nativeClose();
}
peer.nativeClose();
} catch (e) {}

peer = null;
Expand Down
19 changes: 6 additions & 13 deletions dev/SSEConnection.js
Expand Up @@ -91,6 +91,11 @@ function SSEConnection(connection, connectCallback) {
console.info('SSE connection is opened.');
}

// this event tries to open json file on server
connection.socket.emit('fake_EventName', {
remoteUserId: connection.userid
});

connectCallback(connection.socket);
connectCallback = null;
}
Expand Down Expand Up @@ -276,7 +281,7 @@ SSEConnection.checkPresence = function(roomid, callback) {
};
hr.addEventListener('load', function() {
if (connection.enableLogs) {
console.log('XMLHttpRequest', hr.response);
console.info('XMLHttpRequest', hr.response);
}
callback(hr.response.isRoomExist, roomid);
});
Expand All @@ -285,16 +290,4 @@ SSEConnection.checkPresence = function(roomid, callback) {
});
hr.open('GET', sseDirPath + 'checkPresence.php?roomid=' + roomid);
hr.send();

/*
var script = document.createElement('script');
script.onload = function() {
callback(true, roomid);
};
script.onerror = function() {
callback(false, roomid);
};
script.src = sseDirPath + 'rooms/' + roomid + '.json';
(document.body || document.documentElement).appendChild(script);
*/
}

0 comments on commit fee4df2

Please sign in to comment.