Documentation generator: JsDoc Toolkit 2.4.0
Template: Codeview 1.2
Generated on: 2011-6-22 12:26

Class Now

Class Summary
Constructor Attributes Constructor Name and Description
 
Now()
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.
<static>  
Now.initialize(server, options)
Returns a reference to the `everyone` object.
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.

Class Detail

Now()
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.
  • <static> {Group} Now.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"}

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 Now#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 (name) {
  console.log('You have successfully created the group `' + name + '`');
});
Parameters:
{Group} group
The group created by Now#getGroup.