Question

I'm using nowjs for my webapp. How do I differentiate between two clients.

I tried using req.session and also using global variable in the main app.js file. But I haven't succeeded properly in attaining what I need.

My main aim is to handle these two clients seperately - one as a moderator and another as a viewer. What is the optimal way of doing it.

Basic framework that I'm following is as follows (as mentioned in the documentation)

everyone.now.sendToServer = function(parameter){
  everyone.now.recieveFromServer(parameter);
}

so if one updates, everyone else will get the update.

But What I need is. I want to differentiate between the updater and the update receiver.

Was it helpful?

Solution

I'm not sure I exactly understand your question, but you can differentiate between clients in a few different ways:

  • Use the this.now object

(this.now is a special version of the now object that points to one particular user. It is available in the body of functions defined on the server.)

  • Use the group feature,

(Groups behave exactly the same as everyone above, but acts on a subset of all connected users.)

  • Get the client id of a user

(The nowjs.getClient(clientId, func) allows you to address one specific client directly, when you know its clientId.)

Here are the docs: http://nowjs.com/doc/nowjs

OTHER TIPS

I'm not exactly sure how how to achieve this with NowJS, but I can tell you how to do it for Socket.IO (which is used by NowJS under the hood). Once the client connects, you can get his cookies and parse it to obtain the session.

Read more about this here:

http://www.danielbaulig.de/socket-ioexpress/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top