Class Index | File Index

Classes


Class nowjs


Defined in: now.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
nowjs()
The object returned by require('now').
Method Summary
Method Attributes Method Name and Description
 
getClient(id, callback)
Retrieves a user from the given client ID and executes of several actions in the context of that user.
 
getGroup(name)
Retrieves and returns a group from its name, creating it if necessary.
 
getGroups(callback)
Retrieves a list (represented in Javascript as an array) of all groups that have been created and passes it in to the supplied callback.
<static>  
nowjs.initialize(server, options)
Returns a reference to the `everyone` object.
 
Removes all traces of a group.
Event Summary
Event Attributes Event Name and Description
 
Called in the context of a user when the server first receives a message from the given user.
 
Called in the context of a user who has just disconnected from the server.
 
groupdel(group)
Called when deleting a variable from all members of the group specified by this function's argument.
 
grouprv(group)
Called when replacing the value of a variable for all members of the group specified by this function's argument.
 
newgroup(group)
Called when a new group is created.
 
removegroup(group)
Called when a group is removed.
Class Detail
nowjs()
The object returned by require('now').
Method Detail
getClient(id, callback)
Retrieves a user from the given client ID and executes of several actions in the context of that user.
nowjs.getClient('1234567890' function () {
  this.now.receiveMessage('SERVER', 'Anything is possible with NowJS.');
});
Parameters:
{String} id
The client ID associated with the target user.
{Function} callback
Takes no arguments. Called in the context of the user corresponding to the given id.

{Group} getGroup(name)
Retrieves and returns a group from its name, creating it if necessary.
var new_group = nowjs.getGroup('a new group');
Parameters:
{String} name
The name of the group to be retrieved.

getGroups(callback)
Retrieves a list (represented in Javascript as an array) of all groups that have been created and passes it in to the supplied callback.
nowjs.on('connect', function () {
  var self = this;
  nowjs.getGroups(function (groups) {
    nowjs.getGroup(groups[Math.floor(groups.length * Math.random())]).addUser(self);
  });
});
Parameters:
{Function} callback
Takes one argument, an array of all groups that have been created.

<static> {Group} nowjs.initialize(server, options)
Returns a reference to the `everyone` object. The options object, if supplied, will be automatically merged with the default values.
nowjs.initialize(server, {clientWrite: false, socketio: {'log level': 2});
Parameters:
{httpServer} server
A Node.js http server (such as the one available in the http module or a module like Express) on which to run Now.
{Object} options Optional, Default: {"clientWrite" : true, "autoHost" : true, "host" : undefined, "port" : undefined, "socketio" : {}, "closureTimeout : 30000, "client : {}, "scope" : "window"}

{Group} removeGroup(name)
Removes all traces of a group.
var new_group = nowjs.getGroup('a new group');
Parameters:
{String} name
The name of the group to be retrieved.
Event Detail
connect()
Called in the context of a user when the server first receives a message from the given user.
nowjs.on('connect', function () {
  this.now.receiveMessage('SERVER', 'Welcome to NowJS.');
});

disconnect()
Called in the context of a user who has just disconnected from the server.
nowjs.on('disconnect, function () {
  delete myArray[this.user.clientId];
});

groupdel(group)
Called when deleting a variable from all members of the group specified by this function's argument.
nowjs.on('groupdel', function (group) {
  if (group.groupName === 'everyone') {
    console.log('Everyone now no longer possesses ' + group.fqn);
  }
});
Parameters:
{Group} group
Actually not quite a group; this parameter refers to a clone of the group in question that also carries the fully qualified name (fqn) of the variable to delete. Access the fqn via `group.fqn`.

grouprv(group)
Called when replacing the value of a variable for all members of the group specified by this function's argument.
nowjs.on('grouprv', function (group) {
  if (group.groupName === 'everyone') {
    console.log('Everyone now sees ' + group.fqn + ' as ' + group.val);
  }
});
Parameters:
{Group} group
Similar to nowjs#groupdel, this is also a clone of the actual group. In addition to the fully qualified name, this clone also possesses a serialized form of its target value, accessible via `group.val`.

newgroup(group)
Called when a new group is created.
nowjs.on('newgroup', function (group) {
  console.log('You have successfully created the group `' + group.groupName + '`');
});
Parameters:
{Group} group
The group created by nowjs#getGroup.

removegroup(group)
Called when a group is removed.
nowjs.on('removegroup', function (group) {
  console.log('Group `' + group.groupName + '` eliminated from existence.');
});
Parameters:
{Group} group
The group removed by nowjs#getGroup.

Documentation generated by JsDoc Toolkit 2.4.0 on Tue Jan 03 2012 15:53:12 GMT-0800 (PST)