Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ericz committed Jul 20, 2011
1 parent 6cd87d4 commit 215a721
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 113 deletions.
97 changes: 16 additions & 81 deletions lib/group.js
Expand Up @@ -8,10 +8,7 @@ exports.initialize = function (nowjs) {

/**
* @name Group
* @class Represents a group containing some subset of all
users. Each group has its own {@link Group#now} namespace.
* @class Represents a group containing some subset of all users.
* @property {String} groupName The name associated with the group.
*/
var Group = function (groupName) {
Expand All @@ -22,7 +19,7 @@ exports.initialize = function (nowjs) {

this.excludes = {};
/**
* @name Group#now
* @name Group.now
* @namespace The now namespace for this particular group. Actions
* to this namespace affect all users that are members of the
* group. All functions that are called will be called in the
Expand All @@ -36,12 +33,8 @@ exports.initialize = function (nowjs) {
Group.prototype.__proto__ = EventEmitter.prototype;

/**
* @name count
* @function
* @memberOf Group#
* @description Used to find the cardinality of the group (how
* many users it contains).
* Used to find the cardinality of the group (i.e. how many users it
* contains).
* @param {Function} callback Called with a Number corresponding to
* the group's user count.
Expand All @@ -51,12 +44,8 @@ exports.initialize = function (nowjs) {
};

/**
* @name getUsers
* @function
* @memberOf Group#
* @description Used to retrieve a list of the client IDs
* corresponding to all users in the group.
* Used to retrieve a list of the client IDs corresponding to all
* users in the group.
* @param {Function} callback Called with an Array of Strings
* corresponding to the client IDs of all users in the group.
Expand All @@ -66,30 +55,21 @@ exports.initialize = function (nowjs) {
};

/**
* @name connected
* @function
* @memberOf Group#
* @deprecated As of 0.7.0. Use Now:connect instead.
* @deprecated As of 0.7.0. Use nowjs.on('connect') instead.
*/
Group.prototype.connected = function (callback) {
nowjs.on('connect', callback);
};

/**
* @name disconnected
* @function
* @memberOf Group#
* @deprecated As of 0.7.0. Use Now:disconnect instead.
* @deprecated As of 0.7.0. Use nowjs.on('disconnect') instead.
*/
Group.prototype.disconnected = function (callback) {
nowjs.on('disconnect', callback);
};

/**
* @name addUser
* @function
* @memberOf Group#
* @description Adds the user identified by clientId to this group.
* Adds the user identified by clientId to this group.
* @param {String} clientId The client ID associated with the target
* user.
Expand Down Expand Up @@ -123,24 +103,13 @@ exports.initialize = function (nowjs) {
this.socket.emit('rv', toSend);
}
var user = nowUtil.clone(this, {'_events': self._events});

/**
* @name Group#join
* @event
* @description Called in the context of a user who has just been
* added to the group.
*/
self.emit.apply(user, ['join']);
});
});
};

/**
* @name removeUser
* @function
* @memberOf Group#
* @version 0.7.0
* @description Removes the user identified by clientId from this group.
* Removes the user identified by clientId from this group.
* @param {String} clientId The client ID associated with the target
* user.
Expand All @@ -152,14 +121,6 @@ exports.initialize = function (nowjs) {
return;
}
var user = nowUtil.clone(self.users[clientId], {'_events': self._events});

/**
* @name Group#leave
* @event
* @version 0.7.0
* @description Called in the context of a user who has just been
* removed from the group.
*/
self.emit.apply(user, ['leave']);
// Delete all remote functions that are part of this group from
// the user.
Expand All @@ -178,15 +139,10 @@ exports.initialize = function (nowjs) {
};

/**
* @memberOf Group#
* @function
* @name exclude
* @version 0.7.0
* @description 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.
* 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.
* @param {Array} clientIds A list of client IDs corresponding to
* clients to exclude.
Expand All @@ -204,12 +160,7 @@ exports.initialize = function (nowjs) {
};

/**
* @memberOf Group#
* @function
* @name hasClient
* @description Used to determine a given user's membership in the
* group.
* Used to determine a given user's membership in the group.
* @param {String} clientId The client ID associated with the target
* user.
Expand Down Expand Up @@ -248,20 +199,4 @@ exports.initialize = function (nowjs) {
};

return Group;
};

/**
* @name Group#connect
* @event
* @deprecated As of 0.7.0. Use Now#connect instead.
* @description Called in the context of a user when the server
* first receives a message from the given user.
*/

/**
* @name Group#disconnect
* @event
* @deprecated As of 0.7.0. Use Now#disconnect instead.
* @description Called in the context of a user who has just
* disconnected from the server.
*/
};
44 changes: 23 additions & 21 deletions lib/now.js
Expand Up @@ -4,9 +4,8 @@ var EventEmitter = require('events').EventEmitter;
var nowUtil = require('./nowUtil').nowUtil;

/**
* @name Now
* @constructor
* @description The object returned by require('now').
* The object returned by require('now').
*/
var Now = function () {
this.closures = {};
Expand Down Expand Up @@ -43,38 +42,29 @@ Now.prototype._readConfigFile = function (path) {
};

/**
* @memberOf Now#
* @function
* @name getClient
* @description Retrieves a user from the given client ID and executes of several
* Retrieves a user from the given client ID and executes of several
* actions in the context of that user.
* @param {String} id The client ID associated with the target user.
* @param {Function} callback Takes no arguments. Called in the
* context of the user corresponding to the given id.
* context of the user corresponding to id.
*/
Now.prototype.getClient = function (id, callback) {
callback.apply(this.users[id]);
};

/**
* @memberOf Now#
* @function
* @name getGroup
* @description Retrieves and returns a group from its name, creating it if
* Retrieves and returns a group from its name, creating it if
* necessary.
* @param {String} name The name of the group to be retrieved.
* @type Group
*/
Now.prototype.getGroup = function (name) {
if (!nowUtil.hasProperty(this.groups, name)) {
this.groups[name] = new this.Group(name);
/**
* @name Now#newgroup
* @event
* @param {Group} group The group created by Now#getGroup.
* @description Called when a new group is created.
*/

this.emit('newgroup', this.groups[name]);
}
return this.groups[name];
Expand All @@ -88,13 +78,25 @@ Now.prototype.getGroup = function (name) {
* @description Returns a reference to the `everyone` object. The
* options object, if supplied, will be automatically merged with the
* default values.
* Returns a reference to the `everyone` object. The options object,
* if supplied, will be automatically merged with the default values.
* @static
* @param {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.
* @param {Object} [options={"clientWrite" : true, "autoHost" : true,
"host" : undefined, "port" : undefined, "socketio" : {},
"closureTimeout : 30000, "client : {}, "scope" : "window"}]
* @param {Object} [options={
"clientWrite" : true,
"autoHost" : true,
"host" : undefined,
"port" : undefined,
"socketio" : {},
"closureTimeout : 30000
"client : {},
"scope" : "window"
}]
* @type Group
*/
Expand Down
22 changes: 11 additions & 11 deletions lib/user.js
Expand Up @@ -7,14 +7,18 @@ exports.initialize = function (nowjs) {

/**
* @name User
* @class Represents an individual user connected to the now
* server. Exposed as the context in which group.now functions are
* called, as well as the context in which the callback to
* nowjs.getClient is executed. Each user has the {@link User#now}
* and {@link User#user} namespaces.
* nowjs.getClient is executed.
* @property {Socket} socket The user's Socket.IO socket.
* @property {Socket} socket The user's Socket.IO socket.
* @property {Object} now Synchronized with the connected user's
* local now namespace; function calls with respect to this
* namespace will only be executed for the current user.
*/
var User = function (socket) {
var self = this;
Expand All @@ -35,7 +39,7 @@ exports.initialize = function (nowjs) {
this.scopeTable = new ScopeTable();

/**
* @name User#user
* @name User.user
* @namespace Contains properties unique to each user. Can be used
* to store information that should not be exposed to the
* connected user.
Expand All @@ -52,7 +56,7 @@ exports.initialize = function (nowjs) {
this.ready = false;

/**
* @name User#now
* @name User.now
* @namespace Synchronized with the connected user's local now
* namespace; function calls with respect to this namespace will
* only be executed for the current user.
Expand Down Expand Up @@ -135,12 +139,8 @@ exports.initialize = function (nowjs) {
};

/**
* @memberOf User#
* @function
* @name getGroups
* @description Used to retrieve a list of the group names
* corresponding to all groups the user is in.
* Used to retrieve a list of the group names corresponding to all
* groups the user is in.
* @param {Function} callback Called with an Array of Strings
* corresponding to the various group names.
Expand Down

0 comments on commit 215a721

Please sign in to comment.