如何使用 Faye 列出活跃订阅者?

发布于 2024-12-25 20:52:14 字数 845 浏览 2 评论 0 原文

我使用 Faye 来发送消息,效果很好。但我想检索给定通道的活动连接,并且事情的行为有点不同:请参阅“列出频道上的活跃订阅者”。

我想显示当前在房间中聊天的用户的列表。我尝试通过 extensions< 拦截 /meta/subscribe 通道来做到这一点/a> 但我不太确定如何将用户名等数据发送到服务器。

截获到 /meta/subscribe 的消息如下所示:

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

It'd be Nice to send "username" =>; “foo”。

监控也很有趣,但同样,看起来我无法发送任何特定数据订阅。

有人有处理此类问题的经验吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小糖芽 2025-01-01 20:52:15

您可以使用客户端扩展附加数据:

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

然后该数据将对您的服务器端扩展可见。不过,在实施之前,请阅读以下帖子:https://groups.google.com/group/faye -用户/msg/53ff678bcb726fc5

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

淡笑忘祈一世凡恋 2025-01-01 20:52:15

您是否考虑过创建一个频道来定期发布用户当前订阅的频道?您可以将其视为带有附加状态信息(例如他们可能订阅的用户和频道)的心跳/ping。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文