【问题标题】:Laravel Echo joining private channel `.here()`Laravel Echo 加入私人频道`.here()`
【发布时间】:2017-03-03 13:26:53
【问题描述】:

我加入了一个私人频道:

Echo.private('chat_room.'+comments_room_id)
.listen('.App.Events.Common.Comment.CommentCreated', function(e) {
                    e.comment.user = e.user;
                    e.comment.new_msg = 1;
                    _this.comment_room.comments.unshift(e.comment);
                });

我想使用 .here() 状态调用来让一组用户更新当前在线的用户。

我尝试了以下方法:

Echo.private('chat_room.'+comments_room_id)
                    .here(users => {
                        this.users = users;
                    })
                    .listen('.App.Events.Common.Comment.CommentCreated', function(e) {

但这没有用......

控制台中的错误是: Echo.private(...).here is not a function

【问题讨论】:

    标签: laravel laravel-echo


    【解决方案1】:

    所以我发现您还需要在私人频道旁边加入一个在线状态频道才能使用 here() 方法。

                    Echo.join('chat_room.'+comments_room_id)
                    .here((users) => {
                        this.users = users;
                    })
                    .joining((user) => {
                        this.users.push(user)
                    })
                    .leaving((person) => {
                        this.users = _.reject(this.users, user => user.id == person.id);
                    });
    

    【讨论】:

      猜你喜欢
      • 2020-01-15
      • 2020-11-22
      • 2019-06-04
      • 2019-02-08
      • 2017-05-12
      • 2021-03-09
      • 2019-11-05
      • 2020-02-13
      • 2021-08-28
      相关资源
      最近更新 更多