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 !

Comments

Anonymous’s picture

yeah, 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.

julien66’s picture

I 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).
++

julien66’s picture

Priority: Normal » Major
julien66’s picture

Title: multiple module message handler problem » Multiple module message handler problem
julien66’s picture

Hi Beejeebus

I can confirm this trouble on a fresh brand new setup.
I attached a patch. Maybe this should help.
Thanks you.

julien66’s picture

Status: Active » Needs review
Anonymous’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.