Class Index | File Index

Classes


Class Group

Represents a group containing some subset of all users. Each group has its own Group#now namespace.
Defined in: group.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Group()
Field Summary
Field Attributes Field Name and Description
 
The name associated with the group.
Method Summary
Method Attributes Method Name and Description
 
addUser(clientId)
Adds the user identified by clientId to this group.
 
 
count(callback)
Used to find the cardinality of the group (how many users it contains).
 
 
exclude(clientIds)
Returns a new Group that is identical to the calling group, except with the specified clients excluded.
 
getUsers(callback)
Used to retrieve a list of the client IDs corresponding to all users in the group.
 
hasClient(clientId, callback)
Used to determine a given user's membership in the group.
 
removeUser(clientId)
Removes the user identified by clientId from this 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.
 
join()
Called in the context of a user who has just been added to the group.
 
Called in the context of a user who has just been removed from the group.
Class Detail
Group()
See:
nowjs#getGroup
Group#now
Field Detail
{String} groupName
The name associated with the group.
Method Detail
addUser(clientId)
Adds the user identified by clientId to this group.
everyone.addUser('1234567890');
Parameters:
{String} clientId
The client ID associated with the target user.

connected()
Deprecated:
As of 0.7.0. Use nowjs:connect instead.

count(callback)
Used to find the cardinality of the group (how many users it contains).
everyone.count(function (ct) {
  console.log(ct);
});
Parameters:
{Function} callback
Called with a Number corresponding to the group's user count.

disconnected()
Deprecated:
As of 0.7.0. Use nowjs:disconnect instead.

{Group} exclude(clientIds)
Returns a new Group that is identical to the calling group, except with the specified clients excluded. The returned group automatically updates to accommodate any changes made to its parent group.
everyone.now.distribute = function (msg) {
  everyone.exclude([this.user.clientId]).now.receive(this.now.name, msg);
};
factionOne.now.distribute = function (msg) {
  factionTwo.getUsers(function (users) {
    factionOne.exclude(users).now.receive(this.user.clientId, msg);
  });
};
Parameters:
{Array} clientIds
A list of client IDs corresponding to clients to exclude.

getUsers(callback)
Used to retrieve a list of the client IDs corresponding to all users in the group.
everyone.getUsers(function (users) {
  for (var i = 0; i < users.length; i++) console.log(users[i]);
});
Parameters:
{Function} callback
Called with an Array of Strings corresponding to the client IDs of all users in the group.
See:
nowjs#getClient

hasClient(clientId, callback)
Used to determine a given user's membership in the group.
group.hasClient('1234567890', function (bool) {
  if (bool) {
    console.log('User is a member of `group`.');
  }
});
Parameters:
{String} clientId
The client ID associated with the target user.
{Function} callback
Called with a Boolean indicating the user's membership in the group.

removeUser(clientId)
Removes the user identified by clientId from this group.
otherGroup.removeUser('1234567890');
Parameters:
{String} clientId
The client ID associated with the target user.
Event Detail
connect()
Called in the context of a user when the server first receives a message from the given user.
Deprecated:
As of 0.7.0. Use nowjs#connect instead.

disconnect()
Called in the context of a user who has just disconnected from the server.
Deprecated:
As of 0.7.0. Use nowjs#disconnect instead.

join()
Called in the context of a user who has just been added to the group.
everyone.on('join', function () {
  otherGroup.addUser(this.user.clientId);
});

leave()
Called in the context of a user who has just been removed from the group.
otherGroup.on('leave', function () {
  // Store the context, i.e. the user who has just left.
  var self = this;
  // Check that the user is still connected to the server.
  everyone.hasClient(this.user.clientId, function (bool) {
    if (bool) {
      // Send parting words to the client.
      this.now.receive('SERVER', 'Goodbye. I'll miss you dearly.');
    }
  });
});

Documentation generated by JsDoc Toolkit 2.4.0 on Tue Aug 16 2011 17:09:04 GMT-0700 (PDT)