How to list active subscribers using Faye?

I use Faye to send messages and it works well. But I want to get active connections for this channel, and everything will look different: see the " list of active subscribers on the channel ".

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

The intercepted message /meta/subscribe as follows:

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

It would be nice to send "username" => "foo" .

Monitoring is also interesting, but again, it seems like I cannot send any specific data to the subscription.

Does anyone have any experience with this?

+6
source share
2 answers

You can attach data using the client 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 implementing this, read this topic: https://groups.google.com/group/faye-users/msg/53ff678bcb726fc5

+8
source

Have you considered creating a channel to periodically publish which channel the user is currently connected to? You may think of it as a heartbeat / ping with additional status information such as a user and the channel to which they can subscribe.

+4
source

Source: https://habr.com/ru/post/905642/


All Articles