The community forums are in BETA and closed to the public.

Client subscribed to multiple channels; Identify channels on messages.

I am attempting to build an observer client for my PubNub-driven app that can let me know the presence of clients subscribed to multiple channels (100+).

Using the method below, I can subscribe a client to multiple channels 1 and 2.

However, the messages returned through the presence and message callbacks don't identify the channel they came through.

Is there a good way to identify which channel triggered the callbacks?

Sub/Pub example

pubnub.subscribe({
  channel: ['1', '2'],
  presence: function(m){
    presenceCall(m);
  },
  message: function(m){
    messageCall(m);
  }
});

Examples of presence messages

Object {action: "join", uuid: "1xxd0xxd-dx75-4xxb-axdb-e1cxca28c225", timestamp: 1424025105, occupancy: 3}
Object {action: "join", uuid: "fx8efxab-ex21-4a89-xxx-b0x3dex0f1a6", timestamp: 1424025093, occupancy: 3}

While I'm still curious to know how to identify the channel source of messages, the use of the here_now function actually achieves my goal to observe all channels a bit better.

Subscribe example

var pubnub = PUBNUB.init({
  publish_key: "xxx",
  subscribe_key: "xxx"
});
pubnub.subscribe({
  channel: ["1", "2"]
});
pubnub.here_now({
  callback : function(m) {
    processHereNow(m);
  }
});

Observe occupancy of all channels

var processHereNow = function(m) {
  $.each(m.channels, function(key, value) {
    // do something to indicate occupancy
  });
}

example of here_now message

{1: {uuids: Array[1], occupancy: 1}, 2: {uuids: Array[1], occupancy: 2}}

Comments to this discussion are now closed!