【问题标题】:How to make Pusher counting users?如何让 Pusher 统计用户?
【发布时间】:2019-09-30 06:38:25
【问题描述】:

我使用此代码首先加入在线状态频道,其次是 console.log 用户数。我得到了错误

未捕获的类型错误:无法读取未定义的属性“计数”

var presenceChannel = Echo.join('presenceChat');
    presenceChannel.listen('EventEvent', (e) => {
       console.log(e);
   })
   .here((users) => {
       this.users = users;
       console.log(this.users);
       var count = presenceChannel.users.count;
       var me = presenceChannel.users.me;
       update_member_count(count);
       console.log(count);
       console.log(users)        
   })

我怀疑我没有按照我必须的方式使用 Pusher。

我在他登录时监听 EventEvent 并调度 $user。我做错了什么?或者我应该采取哪些步骤来计算 Pusher 的出席频道成员?让我感到困惑的是,在文档示例中没有事件监听器。那么如何使用 Pusher?

【问题讨论】:

  • 就是说presenceChannel.users是未定义的
  • @Roman Bobrik 我得到了包含有关用户加入数据的对象。我只是不明白为什么计数不是 1
  • console.log(presenceChannel),看看有没有users。也许您需要使用presenceChannel.members.count?例如:pusher.com/docs/channels/using_channels/…
  • @Justinas 你为什么要回答?顺便谢谢你。我 console.log(presenceChannel) 并将用户更改为成员,这让我有机会继续我的工作。而且我也认为我不需要事件监听器。

标签: laravel pusher


【解决方案1】:

从评论中复制

documentation 中,它显示的是presenceChannel.members.count 而不是.users

您始终可以使用console.log(presenceChannel) 记录您的对象以查看其属性

【讨论】:

    猜你喜欢
    • 2017-06-08
    • 2021-02-11
    • 1970-01-01
    • 2020-07-02
    • 2013-08-17
    • 2016-03-21
    • 2020-11-09
    • 2017-11-27
    • 1970-01-01
    相关资源
    最近更新 更多