Initial removal of ext.js; replace functions with small utils library
Esse commit está contido em:
+6
-6
@@ -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)
|
||||
})
|
||||
);
|
||||
|
||||
@@ -11,5 +11,4 @@ html
|
||||
script(src: '/js/im.js', type: 'text/javascript')
|
||||
script(type: 'text/javascript')
|
||||
| $(function(){var im = AjaxIM.init({theme: "/themes/default"});});
|
||||
|
||||
body Hello.
|
||||
@@ -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));
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
@@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário