Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list active subscribers using Faye?

I'm using Faye for dispatching messages and it works well. But I want to retrieve the active connections for a given channel, and things behave a bit differently: See "list active subscribers on a channel".

I want to show the list of current users chatting in a room. I tried to do this by intercepting the /meta/subscribe channel via extensions but I'm not quite sure how to send data like the username to the server.

An intercepted message to /meta/subscribe looks like this:

{"channel"=>"/meta/subscribe", "clientId"=>"50k233b4smw8z7ux3npas1lva", "subscription"=>"/comments/new", "id"=>"2"}

It'd be nice to send "username" => "foo".

Monitoring is interesting too, but again, it looks like I can't send any specific data on-subscribe.

Does anyone have experience with these kind of issues?

like image 573
jpemberthy Avatar asked Jan 10 '12 17:01

jpemberthy


1 Answers

You can attach data using a client-side extension:

client.addExtension({
  outgoing: function(message, callback) {
    if (message.channel === '/meta/subscribe') {
      message.ext = message.ext || {};
      message.ext.username = 'username';
    }
    callback(message);
  }
});

This data will then be visible to your server-side extension. However, before you implement that, read this thread: https://groups.google.com/group/faye-users/msg/53ff678bcb726fc5

like image 56
jcoglan Avatar answered Sep 27 '22 20:09

jcoglan