Easyrtc server with login

721 views
Skip to first unread message

Elvin Mirze

unread,
May 16, 2014, 8:29:44 AM5/16/14
to eas...@googlegroups.com
Hi,
We have create Simple login. If same user log in different browser tab then the second tab automatically log out. my code check , but logged out both of them. Please any suggestion?

Rod Apeldoorn

unread,
May 16, 2014, 2:03:46 PM5/16/14
to eas...@googlegroups.com
If I understand, you want to prevent the same user from logging in twice.

Here's the steps I would use to accomplish this:
  • In client, set the username prior to connecting - easyrtc.setUsername() and easyrtc.setCredential()
  • In server, create a listener for the authenticate event
  • Within the listener:
    • Verify authentication information
    • Scan through authenticated users on server for other user with same username
    • To disconnect the new connection, send an error to the next() callback.
    • To disconnect the previous connection, get its connectionObj and force it to disconnect. Then run next callback with no error.
Rod Apeldoorn,
EasyRTC Server Lead,

Elvin Mirze

unread,
May 16, 2014, 2:28:09 PM5/16/14
to eas...@googlegroups.com
Thanks Rod. Can you give me part of code about it? i have no idea about that.

Rod Apeldoorn

unread,
May 16, 2014, 5:51:39 PM5/16/14
to
Hi Elvin,

I'm afraid this problem has too many parts for me to answer in code here on the board. It would require a demo app to be written which would be a bit of a stretch time-wise for me at the moment.

Horia Schiau

unread,
May 16, 2014, 7:57:23 PM5/16/14
to eas...@googlegroups.com
I had some similar task. Rod helped me with it. I used async to go through all connections.
I haven't tested the code...I use this a bit differently ( to disconnect new connection ) on the room join event.

 var onAuthenticate = function(socket, easyrtcid, appName, username, credential, easyrtcAuthMessage, next) {
     
     
// TODO : Verify authentication information

     
var previousConn = false;
     app
.getConnectionEasyrtcids(function(error, id_list) {
         console
.log('Ids connected now :', id_list);
         async
.each(id_list, function(id, cb) {
             app
.connection(id, function(er, cObj){
                 
if (er) {
                     cb
(er);
                 
} else {
                     
if (cObj.getUsername() == username && cObj.getEasyrtcid() != easyrtcid) {
                         previousConn
= cObj;
                     
}
                     cb
();
                 
}
             
});
         
}, function(err) {
             
if (err) {
                 
next(err);
             
} else {
                 
if (previousConn != false) {
                     previousConn
.removeConnection(function(e){
                         console
.log('Removed previous connection.');
                         
next();
                     
});
                 
} else {
                     easyrtc
.events.emitDefault("authenticate", socket, easyrtcid, appName, username, credential, easyrtcAuthMessage, next);
                 
}
             
}
         
});

     
});
 
});


Hope this will put you on the right path.
        

Elvin Mirze

unread,
May 19, 2014, 3:43:38 PM5/19/14
to eas...@googlegroups.com
Hi, thanks for answer.but i dont know where implement this code.

Gonzalo Amadio

unread,
May 20, 2014, 12:48:54 PM5/20/14
to eas...@googlegroups.com
Hi Elvin, 
That code you have to put it into the server.js file.

By doing :

var onAuthenticate = function(socket, easyrtcid, appName, username, credential, easyrtcAuthMessage, next) {

//code
}

easyrtc
.events.on("authenticate", onAuthenticate);



You are overriding the listener for the authentication method. You can see the default behaviour into easyrtc_default_listeners.js file.
In this case, the "authenticate" event is fired, when you execute (for example if you use easyApp) 
easyrtc.easyApp(/*params*/)
Into you own logic on the client side.

 

Elvin Mirze

unread,
May 22, 2014, 2:39:59 PM5/22/14
to eas...@googlegroups.com
Thanks a lot Gonzalo
Reply all
Reply to author
Forward
0 new messages