Hi,
I believe I discovered an issue with the main message handler function on the backend :
foreach (module_implements('nodejs_message_callback') as $module) {
$function = $module . '_nodejs_message_callback';
$handlers += $function($message['messageType']);
}
foreach ($handlers as $callback) {
$callback($message, $response);
}
When multiples modules implements the nodejs_message_callback one of them may return nothing for this specific message type. So that when the messageType = "post", my module could still do :
function nodejs_livetracking_nodejs_message_callback($type) {
if ($type == 'device-auth') {
return array('nodejs_livetracking_auth_device');
}
elseif ($type == 'device-off') {
return array('nodejs_livetracking_off_device');
}
}
=> Note how I return nothing interesting since messageType = 'post '!
Actually the problem with having a module returning nothing is that it brokes this part of this code somehow (Not good enough to tell why. Would like to know) :
$handlers += $function($message['messageType'])
I first tryed to return an blank array (for any case => return array(''))). But that was not working neither. I suppose because += is overriding the key wich is always [0] here.
What works in my setup is to check if the function actually return an array before calling += on the handler :
if (is_array($function($message['messageType']))) {
$handlers += $function($message['messageType'];
}
This is what I use now.
Am I out of my mind here ?
Cheers !
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | nodejs-fix-multiple-message-handlers-2042613-5.patch | 613 bytes | julien66 |
Comments
Comment #1
Anonymous (not verified) commentedyeah, this looks like it could do with a revamp.
the biggest issue i see is any code out there that might already use this crappy set up.
Comment #2
julien66 commentedI now deeply rely on this module.
If I can do anything helping to fix it / improve it someway, just tell me.
Suggested change won't break anything on existing modules (they've always been excepted to return an array and so it is now).
++
Comment #3
julien66 commentedComment #4
julien66 commentedComment #5
julien66 commentedHi Beejeebus
I can confirm this trouble on a fresh brand new setup.
I attached a patch. Maybe this should help.
Thanks you.
Comment #6
julien66 commentedComment #7
Anonymous (not verified) commentedthanks! pushed here:
http://drupalcode.org/project/nodejs.git/commit/5346883