【问题标题】:laravel PresenceChannel joining not workinglaravel PresenceChannel 加入不起作用
【发布时间】:2020-09-15 08:59:36
【问题描述】:

这是客户端js

  let user_id = $('meta[name="user-id"]').attr('content');
  let channel = Echo.join('user-' + user_id);
    channel.here((user) => {
      console.log('Here');
      console.log(user);
    })
    .joining((user) => {
        console.log('joining');
        console.log(user);
    })
    .leaving((user) => {
        console.log('leaving');
        console.log(user);
    });

在 laravel 回显服务器中显示此错误

 [11:48:15 AM] - wLO1jq5fW9p_8lOnAAAS left channel: presence-user-1 (transport close)
(node:24532) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
    at /usr/local/lib/node_modules/laravel-echo-server/dist/channels/presence-channel.js:78:21
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:24532) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 18)
[11:48:17 AM] - Preparing authentication request to: http://asapp.buginsoft.kz
[11:48:17 AM] - Sending auth request to: http://asapp.buginsoft.kz/broadcasting/auth

[11:48:17 AM] - W3CiOs736gv0o0OwAAAT authenticated for: presence-user-1
Unable to join channel. Member data for presence channel missing
[11:48:17 AM] - W3CiOs736gv0o0OwAAAT joined channel: presence-user-1

这是我的 MessageSent 事件

public function __construct($message,$id)
{
    $this->message = $message;
    $this->id = $id;
}

public function broadcastOn()
{
    return new PresenceChannel('user-'.$this->id);
}

这是我的控制台.php

Broadcast::channel('user-{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

但我的控制台很清晰,没有显示加入等的日志

【问题讨论】:

  • 欢迎使用 SO,请添加您的代码而不是图片。

标签: laravel echo laravel-echo


【解决方案1】:

在您的广播回调中,您返回了一个由私人频道询问的布尔值。但是当你验证一个在线通道时,如果用户被允许,你必须返回一个关于这个用户的数据数组。

https://laravel.com/docs/7.x/broadcasting#authorizing-presence-channels

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    相关资源
    最近更新 更多