How to maintain unique EasyRTC id for unique session

307 views
Skip to first unread message

Deepak manwal

unread,
Apr 16, 2015, 1:55:24 AM4/16/15
to eas...@googlegroups.com
I am developing chat application with EasyRTC and Nodejs.

Once user logs in it redirects to the welcome.jade. I am using following Javascript code for connecting user:

function connect() { //calling this function on body onload
    easyrtc.setUsername($('#username').text()); //setting username
    easyrtc.setPeerListener(addToConversation);
    easyrtc.setRoomOccupantListener(convertListToButtons);
    easyrtc.connect("easyrtc.instantMessaging", loginSuccess, loginFailure);
}
function loginSuccess(easyrtcid) {  //callback function
    selfEasyrtcid = easyrtcid;
    console.log("I am " + easyrtcid);
}

Suppose i logged in with user x...@gmail.com then a unique easyrtcid generated. But if i open this application in new tab, then another easyrtcid generated for same user x...@gmail.com. So x...@gmail.com(xyz) user showing online double time to another users.

How can I prevent this happening?? How can i create this easyrtcid once and use it across the application or session? Is this possible?

Eric Davies

unread,
Apr 16, 2015, 2:11:16 AM4/16/15
to eas...@googlegroups.com
You can't.
The easyrtcid is unique to a session.
If you want something unique to your machine, you need to use a cookie or local storage mechanism to map easyrtcid <--> userids.
Somebody on the group may have some experience with.

Ataul Mukit

unread,
Apr 18, 2015, 5:24:17 AM4/18/15
to eas...@googlegroups.com
I find the function easyrtc.setUsername quite useful in this scenario.

What you have to do , is use have a very unique id for each user (might be a database id for the user) and set that to  easyrtc.setUsername

And then you can easyrtc.idtoname to get the unique id from the easyrtcid, and after that you can query to the database to get the rest of the information for that user.

However, in my case inorder to minimize server depenancy, I am trying to have each user send their userinfo to through easyrtc.senddata to other users through a semi-complicated process. 

My style is 

1. User logs in
2. He broadcasts his own info to the room
3. In return, those who gets the broadcasted info of the new user, responses back their own info to the newly logged in user.

But whatever technique you use to get further information for each user, easyrtc.setUsername where instead of some display name of the user, setting the unique id for the user works like charm.

 
Reply all
Reply to author
Forward
0 new messages