Merge branch '35-remove-ext'

Esse commit está contido em:
Joshua Gross
2010-09-27 16:34:36 -05:00
6 arquivos alterados com 72 adições e 27 exclusões
-3
Ver Arquivo
@@ -23,9 +23,6 @@ Install Node Package Manager (`npm`):
Install `Express.js` and `Connect` (included automatically):
npm install express
Install `Ext.js` (fixed version for Node.js 0.2.0+ and latest `npm` until changes are merged):
npm install http://github.com/endtwist/ext.js/tarball/0698dfdc0ff7d79926f3215779c27774120ce7f4
Compile the daemon add-on if you plan on letting the server daemonize itself:
cd server/libs/daemon
node-waf configure build
+6 -6
Ver Arquivo
@@ -1,11 +1,11 @@
#!/usr/bin/env node
var sys = require('sys'),
express = require('express'),
packages = require('./libs/packages');
Object.merge(global, require('ext'));
packages = require('./libs/packages'),
o_ = require('./libs/utils');
Object.merge(global, require('./settings'));
try { Object.merge(global, require('./settings.local')); } catch(e) {}
o_.merge(global, require('./settings'));
try { o_.merge(global, require('./settings.local')); } catch(e) {}
try {
var daemon = require('./libs/daemon/daemon'),
@@ -57,8 +57,8 @@ var app = express.createServer(
express.cookieDecoder(),
express.bodyDecoder(),
require('./middleware/im')({
lifetime: (15).minutes,
reapInterval: (1).minute,
lifetime: 15 * 60 * 1000,
reapInterval: 60 * 1000,
authentication: require('./libs/authentication/' + AUTH_LIBRARY)
})
);
+46
Ver Arquivo
@@ -0,0 +1,46 @@
// Many functions borrowed from
// ext.js - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
module.exports = o_ = {
merge: function(a, b) {
if(!b) return a;
var keys = Object.keys(b);
for(var i = 0, len = keys.length; i < len; i++)
a[keys[i]] = b[keys[i]];
return a;
},
values: function(obj) {
if(typeof obj == 'array')
return obj;
if(!obj || typeof obj !== 'object')
return [];
var keys = Object.keys(obj),
vals = [];
for(var i = 0, len = keys.length; i < len; ++i)
vals.push(obj[keys[i]]);
return vals;
},
find: function(arr, fn, context) {
if(typeof arr == 'array') {
for(var i = 0, len = arr.length; i < len; ++i)
if(fn.call(context, arr[i], i, arr))
return arr[i];
} else if(typeof arr == 'object') {
var keys = Object.keys(obj);
for(var i = 0, len = keys.length; i < len; ++i)
if(fn.call(context, arr[keys[i]], keys[i], arr))
return [arr[keys[i]], keys[i]];
}
},
bind: function(fn, context) {
var self = fn,
args = Array.prototype.slice.call(arguments, 2);
return function() {
var _args = Array.prototype.slice.call(arguments);
return fn.apply(context, args.concat(_args));
};
}
};
+1 -1
Ver Arquivo
@@ -36,7 +36,7 @@ module.exports = function setupHub(options) {
sess.touch();
if(url.parse(req.url).pathname === '/listen') {
req.connection.setTimeout((5).minutes);
req.connection.setTimeout(5 * 60 * 1000);
sess.listener(res);
store.set(req.sessionID, sess);
+16 -15
Ver Arquivo
@@ -1,6 +1,7 @@
var events = require('events'),
sys = require('sys'),
packages = require('../../libs/packages'),
o_ = require('../../libs/utils'),
User = require('./user');
var Hub = module.exports = function Hub(options) {
@@ -8,8 +9,8 @@ var Hub = module.exports = function Hub(options) {
this.auth = options.authentication;
this.sessions = {};
this.maxAge = options.maxAge || 14400000;
this.reapInterval = options.reapInterval || 60000;
this.maxAge = options.maxAge || 4 * 60 * 60 * 1000;
this.reapInterval = options.reapInterval || 60 * 1000;
if(this.reapInterval !== -1) {
setInterval(function(self) {
@@ -17,14 +18,14 @@ var Hub = module.exports = function Hub(options) {
}, this.reapInterval, this);
}
this.events.addListener('update', (function(package) {
this.events.addListener('update', o_.bind(function(package) {
if(package.constructor === exports.Offline) {
for(var i = 0, l = this.users.length; i < l; i++) {
if(this.users[i].get('username') == package.user)
this.users.splice(i, 1);
}
}
}).bind(this));
}, this));
};
Hub.prototype.destroy = function(sid, fn) {
@@ -37,9 +38,9 @@ Hub.prototype.reap = function(ms) {
for(var i = 0, len = sids.length; i < len; ++i) {
var sid = sids[i], sess = this.sessions[sid];
if(sess.lastAccess < threshold) {
sess.signoff((function() {
sess.signoff(o_.bind(function() {
delete this.sessions[sid];
}).bind(this));
}, this));
}
}
};
@@ -48,37 +49,37 @@ Hub.prototype.get = function(sid, fn) {
if(this.sessions[sid]) {
fn(null, this.sessions[sid]);
} else {
this.auth.authenticate(sid, (function(data) {
this.auth.authenticate(sid, o_.bind(function(data) {
if(data) {
var session = new User(sid, data);
this.set(sid, session);
this.auth.friends(sid, data, (function(friends) {
this.auth.friends(sid, data, o_.bind(function(friends) {
var friends_copy = friends.slice();
Object.values(this.sessions).filter(function(friend) {
o_.values(this.sessions).filter(function(friend) {
return ~friends.indexOf(friend.data('username'));
}).each(function(friend) {
}).forEach(function(friend) {
var username = friend.data('username');
friends_copy[friends_copy.indexOf(username)] =
[username, friend.data('status')];
}, this);
session._friends(friends_copy);
session.events.addListener('status', (function(value) {
session.events.addListener('status', o_.bind(function(value) {
this.events.emit(
'update',
new packages.Status(session.data('username'), value)
);
}).bind(this));
}, this));
this.events.addListener('update',
session.receivedUpdate.bind(session));
o_.bind(session.receivedUpdate, session));
this.set(sid, session);
fn(null, session);
}).bind(this));
}, this));
} else {
fn();
}
}).bind(this));
}, this));
}
};
+3 -2
Ver Arquivo
@@ -1,5 +1,6 @@
var events = require('events'),
packages = require('../../libs/packages');
packages = require('../../libs/packages'),
o_ = require('../../libs/utils');
var User = module.exports = function(id, data) {
this.id = id;
@@ -12,7 +13,7 @@ var User = module.exports = function(id, data) {
this.events = new events.EventEmitter();
this.status = packages.STATUSES[0];
setInterval(this._expireConns.bind(this), 500);
setInterval(o_.bind(this._expireConns, this), 500);
};
User.prototype.receivedUpdate = function(package) {