문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top