How do I list active subscribers using Faye?
Asked Answered
S

2

7

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?

Slog answered 10/1, 2012 at 17:16 Comment(0)
I
8

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

Indehiscent answered 19/1, 2012 at 22:12 Comment(0)
P
4

Have you considered creating a channel for periodically publishing which channel a user is currently subscribed to? You can think of it like a heartbeat/ping with additional status information such as which user and channel they may be subscribed to.

Population answered 12/1, 2012 at 16:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.