Esse commit está contido em:
Daniel Howard
2014-05-07 16:17:38 -07:00
commit e1097a73d5
5 arquivos alterados com 32 adições e 36 exclusões
+7 -10
Ver Arquivo
@@ -1398,16 +1398,13 @@ AjaxIM.request = function(url, type, data, successFunc, failureFunc) {
dataType: jsonp? 'jsonp': 'json',
type: type,
cache: false,
timeout: 299000,
success: function(json, textStatus, xhr) {
if(!jsonp && 'status' in xhr && xhr.status == '0') return;
_dbg(json);
successFunc(json);
},
complete: function(xhr, textStatus) {
if(!jsonp && (~errorTypes.indexOf(textStatus) || xhr.status == '0'))
failureFunc(textStatus);
}
timeout: 299000
}).done(function(data) {
_dbg(JSON.stringify(data));
successFunc(data);
}).fail(function(jqXHR, textStatus) {
_dbg(textStatus);
failureFunc(textStatus);
});
// This prevents Firefox from spinning indefinitely
+11 -11
Ver Arquivo
@@ -81,25 +81,25 @@ app.listen(APP_PORT, APP_HOST);
// Listener endpoint; handled in middleware
app.get('/app/listen', function(){});
app.post('/app/message', function(req, res) {
res.find(req.body['to'], function(user) {
app.use('/app/message', function(req, res) {
res.find(req.param('to'), function(user) {
if(!user)
return res.send(new packages.Error('not online'));
res.message(user, new packages.Message(
req.session.data('username'),
req.body.body
req.param('body')
));
});
});
app.post('/app/message/typing', function(req, res) {
if(~packages.TYPING_STATES.indexOf('typing' + req.body['state'])) {
res.find(req.body['to'], function(user) {
app.use('/app/message/typing', function(req, res) {
if(~packages.TYPING_STATES.indexOf('typing' + req.param('state'))) {
res.find(req.param('to'), function(user) {
if(user) {
res.message(user, new packages.Status(
req.session.data('username'),
'typing' + req.body.state
'typing' + req.param('state')
));
}
@@ -112,16 +112,16 @@ app.post('/app/message/typing', function(req, res) {
}
});
app.post('/app/status', function(req, res) {
if(~packages.STATUSES.indexOf(req.body['status'])) {
res.status(req.body.status, req.body.message);
app.use('/app/status', function(req, res) {
if(~packages.STATUSES.indexOf(req.param('status'))) {
res.status(req.param('status'), req.param('message'));
res.send(new packages.Success('status updated'));
} else {
res.send(new packages.Error('invalid status'));
}
});
app.post('/app/signoff', function(req, res) {
app.use('/app/signoff', function(req, res) {
res.signOff();
res.send(new packages.Success('goodbye'));
});
+6 -13
Ver Arquivo
@@ -14,30 +14,23 @@ module.exports = function setupHub(options) {
return;
}
// move "fake" cookies from query or body (for JSONP)
if (!(options.authentication.cookie in req.cookies)) {
if (options.authentication.cookie in req.query) {
req.cookies[options.authentication.cookie] = req.query[options.authentication.cookie];
} else if (options.authentication.cookie in req.body) {
req.cookies[options.authentication.cookie] = req.body[options.authentication.cookie];
if (req.param(options.authentication.cookie)) {
req.cookies[options.authentication.cookie] = req.param(options.authentication.cookie);
}
}
// move "fake" cookies from query or body (for JSONP)
if (!('callback' in req.cookies)) {
if ('callback' in req.query) {
req.cookies.callback = req.query.callback;
} else if ('callback' in req.body) {
req.cookies.callback = req.body.callback;
if (req.param('callback')) {
req.cookies['callback'] = req.param('callback');
}
}
req.sessionID = req.cookies[options.authentication.cookie];
req.jsonpCallback = req.cookies.callback;
delete req.query[options.authentication.cookie];
delete req.body[options.authentication.cookie];
delete req.query.callback;
delete req.body.callback;
if(url.parse(req.url).pathname.substring(0, 5) !== '/app/') {
next();
return;
+3
Ver Arquivo
@@ -52,6 +52,9 @@ Hub.prototype.reap = function(ms) {
Hub.prototype.get = function(req, fn) {
if(this.sessions[req.sessionID]) {
if (!this.sessions[req.sessionID].req) {
this.sessions[req.sessionID].req = req;
}
fn(null, this.sessions[req.sessionID]);
} else {
this.auth.authenticate(req, o_.bind(function(data) {
+5 -2
Ver Arquivo
@@ -12,7 +12,8 @@ var User = module.exports = function(req, data) {
this._data = data;
this.events = new events.EventEmitter();
this.status(packages.STATUSES[0], '');
this._status = packages.STATUSES[0];
this._status_message = '';
setInterval(o_.bind(this._expireConns, this), 500);
};
@@ -54,7 +55,7 @@ User.prototype.listener = function(conn) {
};
User.prototype.respond = function(code, message, callback) {
this._send('connection', code, message, callback);
this._send(this.req.jsonpCallback? 'listener': 'connection', code, message, callback);
};
User.prototype.send = function(code, message, callback) {
@@ -76,6 +77,7 @@ User.prototype._send = function(type, code, message, callback) {
message = JSON.stringify(message);
if(type == 'connection' && this.connection) {
// end a regular connection with a response
this.connection.writeHead(code || 200, {
// 'Content-Type': 'application/json',
'Content-Type': 'application/javascript',
@@ -83,6 +85,7 @@ User.prototype._send = function(type, code, message, callback) {
});
this.connection.end(this.addCallback(message));
} else {
// add a message to a long-polling connection
if(!this.listeners.length)
return this.message_queue.push(arguments);