variable declared in client-side

25 views
Skip to first unread message

Jalex

unread,
Jun 19, 2011, 8:08:04 AM6/19/11
to nowjs
Hi,

I test the example from the guide page (http://nowjs.com/guide) that
set a variable name (now.name) and dont get a good result. Already in
server, when a put on the console.log, the variable name
(everyone.now.name) is 'undefined'.
What`s happening? Someone test this example too?

Tom

unread,
Jun 19, 2011, 8:29:55 AM6/19/11
to no...@googlegroups.com
The everyone variables accesses 'everyone', yet not everyone can have the same name, thus this request makes no sense.

You could get the name for a specific client though, like so:

   now.on('disconnect', function(client) {
       require('util').debug(this.now.name + ' disconnected.');
   });

Keep in mind that this variable can be changed at wish by the client and is not validated.

Tom

2011/6/19 Jalex <jal...@gmail.com>

Eric Zhang

unread,
Jun 19, 2011, 12:44:53 PM6/19/11
to no...@googlegroups.com
Yep Tom is right.

You can't read variables from 'everyone' because you'd be trying to read the variable for ALL connected users which doesn't make sense since they'll probably have different values!

This means you have to access the variable for that single user. You can do this in the scope of a function call on the server, or in the scope provided by the `nowjs.getClient` function.


If you need more help take a look at the helloworld chat example : https://github.com/Flotype/now/blob/master/examples/helloworld_example/helloworld_server.js

Corresponding client code:

It uses now.name to set name in the chatroom.


Good luck,
Eric
Reply all
Reply to author
Forward
0 new messages