0

In my project backend sends a lot of messages published to different channels.
I can see from browser console the message arrived has channel property. But the problem is a callback passed to swampdragon.onChannelMessage doesn't get that channel information. It gets strange channels list instead.
So when a message arrives (in browser) I can't figure out the channel it was published to and therefore handle it properly.

I found the code where that channel info is stripped off https://github.com/jonashagstedt/swampdragon/blob/master/swampdragon/static/swampdragon/js/dist/swampdragon.js#L261

if ('channel' in e.data) {
  var channel = swampDragon.channels[e.data.channel];
  delete(e.data['channel']);
  swampDragon.settings.onchannelmessage(channel, e.data);
  return;
}

So my question is how frontend developer can figure out what channel the message arrived was published to in order to be able to handle the message properly?

Alexey
  • 1,257
  • 7
  • 13

1 Answers1

0

A little late, but in case you weren't able to solve this:

swampdragon.open(function() {
  swampdragon.subscribe('notification', 'notification', null, function (context, data) {
    // Successfully subscribed to the notification channel
  }, function () {
    console.error('Error', arguments);
  });
});

swampdragon.onChannelMessage(function(channels, message) {
  if (channels.indexOf('notification') > -1) {
    // Message sent on the notification channel
  }
});

In onChannelMessage the channels argument is an array of channels the incoming messages was sent to. You can use indexOf to check the channel you are interested in exists in the list.