Merge pull request #853 from fourplusone/feature/async_handleMessage
async handle message
This commit is contained in:
commit
ead379cf66
|
@ -159,11 +159,7 @@ exports.handleDisconnect = function(client)
|
||||||
*/
|
*/
|
||||||
exports.handleMessage = function(client, message)
|
exports.handleMessage = function(client, message)
|
||||||
{
|
{
|
||||||
_.map(hooks.callAll( "handleMessage", { client: client, message: message }), function ( newmessage ) {
|
|
||||||
if ( newmessage || newmessage === null ) {
|
|
||||||
message = newmessage;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if(message == null)
|
if(message == null)
|
||||||
{
|
{
|
||||||
messageLogger.warn("Message is null!");
|
messageLogger.warn("Message is null!");
|
||||||
|
@ -175,6 +171,23 @@ exports.handleMessage = function(client, message)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var handleMessageHook = function(callback){
|
||||||
|
var dropMessage = false;
|
||||||
|
|
||||||
|
// Call handleMessage hook. If a plugin returns null, the message will be dropped. Note that for all messages
|
||||||
|
// handleMessage will be called, even if the client is not authorized
|
||||||
|
hooks.aCallAll("handleMessage", { client: client, message: message }, function ( messages ) {
|
||||||
|
_.each(messages, function(newMessage){
|
||||||
|
if ( newmessage === null ) {
|
||||||
|
dropMessage = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// If no plugins explicitly told us to drop the message, its ok to proceed
|
||||||
|
if(!dropMessage){ callback() };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var finalHandler = function () {
|
var finalHandler = function () {
|
||||||
//Check what type of message we get and delegate to the other methodes
|
//Check what type of message we get and delegate to the other methodes
|
||||||
if(message.type == "CLIENT_READY") {
|
if(message.type == "CLIENT_READY") {
|
||||||
|
@ -203,11 +216,18 @@ exports.handleMessage = function(client, message)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (message && message.padId) {
|
if (message) {
|
||||||
async.series([
|
async.series([
|
||||||
|
handleMessageHook,
|
||||||
//check permissions
|
//check permissions
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(!message.padId){
|
||||||
|
// If the message has a padId we assume the client is already known to the server and needs no re-authorization
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Note: message.sessionID is an entirely different kind of
|
// Note: message.sessionID is an entirely different kind of
|
||||||
// session from the sessions we use here! Beware! FIXME: Call
|
// session from the sessions we use here! Beware! FIXME: Call
|
||||||
// our "sessions" "connections".
|
// our "sessions" "connections".
|
||||||
|
@ -231,8 +251,6 @@ exports.handleMessage = function(client, message)
|
||||||
},
|
},
|
||||||
finalHandler
|
finalHandler
|
||||||
]);
|
]);
|
||||||
} else {
|
|
||||||
finalHandler();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue