-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to know whether to create a room, or join one #38
Comments
I am new to node.js and WebRTC and I started playing with it last night, I have similar thoughts, I was wondering if there is a way to remove dependency of Firebase. I came up with this idea (not tested) //expects query param id eg. http://localhost:8888/isRoomExists?id=blahblah |
Channel presence in "socket.io over node.js" can be detected like this: function testChannelPresence(channel) { var socket = io.connect('/'); socket.on('presence', function (isChannelPresent) { console.log('is channel present', isChannelPresent); if (!isChannelPresent) playRoleOfSessionInitiator(); }); socket.emit('presence', channel); } testChannelPresence('default-channel'); Demo: http://webrtc-signaling.jit.su/RTCMultiConnection Socket.io over Node.js source code: https://github.com/muaz-khan/WebRTC-Experiment/tree/master/socketio-over-nodejs
function testChannelPresence(channel) {
var socket = io.connect('/');
socket.on('presence', function (isChannelPresent) {
console.log('is channel present', isChannelPresent);
if (!isChannelPresent) playRoleOfSessionInitiator();
});
socket.emit('presence', channel);
}
testChannelPresence('default-channel'); |
cool, thanks :) I know I asked for this functionality...but thinking about it now, it would save a trip to the server if you could call 'new-channel' and have the server either |
Is it possible to make such kind of trick for connections based on Firebase? |
Are you meant something like this? channelToTest = 'default-channel';
new Firebase('https://chat.firebaseIO.com/' + channelToTest).once('value', function (data) {
var isChannelPresent = data.val() != null;
if (!isChannelPresent) playRoleOfSessionInitiator();
console.log('is channel present', isChannelPresent);
}); |
Yep, exactly, works great. Thanks! |
The Firebase method doesn't seem to work with 1.3. Should it? |
@zdfs Are you meant "unable to detect presence of the channel".....or....? Did you try something like this? channelToTest = location.hash.substr(1) || 'another-channel';
new Firebase('https://chat.firebaseIO.com/' + channelToTest).once('value', function (data) {
var isChannelPresent = data.val() != null;
// if no channel present; open new session
if (!isChannelPresent) connection.open('a-session-id');
// else join existing session
else connection.connect('a-session-id');
}); |
Yeah. |
It works;
var sessionid = 'session-id';
var connection = new RTCMultiConnection();
connection.session = {
audio: true,
video: true
};
connection.onstream = function (e) {
document.body.appendChild(e.mediaElement);
};
new window.Firebase('https://chat.firebaseIO.com/' + sessionid).once('value', function (data) {
var isRoomPresent = data.val() != null;
if (!isRoomPresent) connection.open(sessionid);
else connection.connect(sessionid);
console.debug('room is present?', isRoomPresent);
}); By default, // overriding for session initiation
connection.firebase = 'signaling';
// presence detection
new window.Firebase('https://signaling.firebaseIO.com/' + sessionid).once(....); You can see that |
I'll take a look tomorrow. Thanks for your input! |
Turns out that Will probably switch to my own socket IO implementation at some point, but will need the Firebase service for a bit longer. Thanks for your help! |
Do you know, firebase can behave like socket.io over node.js too! new Firebase('https://YOURINSTANCE.firebaseio.com').on('value', function(snap) {
// here is the data transferred from the sender!
var data = snap.val();
// will never keep data on firebase servers!
snap.ref().remove();
}); I'm using same technique in Their |
@muaz-khan Your proposed solution, which is working well with RTCMultiConnection-1.3, fails when using RTCMultiConnection-1.4. How can we then check whether to create or join a room? |
etc. Following code works well with v1.4 too; to detect presence of the room; and create/join room accordingly: new window.Firebase('https://chat.firebaseIO.com/' + sessionid).once('value', function (data) {
var isRoomPresent = data.val() != null;
if (!isRoomPresent) connection.open(sessionid);
else connection.connect(sessionid);
console.debug('room is present?', isRoomPresent);
}); |
can I replace Firebase('https://chat.firebaseIO.com/' + sessionid) with node.js signaling server |
One of the current problems I'm experiencing with RTCMultiConnection-v1.2.js with the socketio-over-nodejs server is the lack of a proper way to establish a session. I'm currently using the hack that waits 5 seconds to see if it gets a session invite, otherwise it creates a new channel, but it's pretty unreliable, especially with a slow connection.
I feel like there should be a way to ask the server - "does this room exist?" - like you do with Firebase. Otherwise the two people who want to chat have to go in one at a time, which is not always practical. And a 5 second wait is quite long...especially when testing over and over :)
The text was updated successfully, but these errors were encountered: