Laravel Echo加入私人频道`.here()`

时间:2017-03-03 13:26:53

标签: laravel laravel-echo

我加入了私人频道:

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

1 个答案:

答案 0 :(得分:0)

所以我发现您还需要在私有频道旁边加入Presence频道才能使用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);
                });
相关问题