无法从 laravel 回显服务器接收广播消息

Can't recieve broadcasted message from laravel echo server

在laravel-echo-console中:

L A R A V E L  E C H O  S E R V E R

version 1.5.2

⚠ Starting server in DEV mode...

✔  Running at localhost on port 6001
✔  Channels are ready.
✔  Listening for redis events...

Server ready!

[7:07:00 PM] - YSTAl2zDJP0HtuoCAAAA joined channel: public
[7:07:00 PM] - Sending auth request to: https://xxxxx/broadcasting/auth

[7:07:00 PM] - YSTAl2zDJP0HtuoCAAAA authenticated for: private-survey.2
[7:07:00 PM] - YSTAl2zDJP0HtuoCAAAA joined channel: private-survey.2


Channel: laravel_database_private-survey.2
Event: server.message

一切正常,但我无法在浏览器中收到此消息:

window.Echo.private('survey.2')
 .listen('.server.message', (e) => {
        console.log(e)  
});
e {events: {…}, name: "private-survey.2", socket: p, options: {…}, eventFormatter: t}

我的活动class:

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

    public function broadcastOn()
    {
        return new PrivateChannel('survey.2');
    }

    public function broadcastAs()
    {
        return 'server.message';
    }

在laraveltelescope我看到:

{
  message: "wdfwsfwf",
  socket: null
}

socket为null正常吗? 此事件也始终有 0 个听众。

怎么了?

我的问题就在这里Channel: laravel_database_ private-survey.2config/database.php

中更改此设置

在这种情况下,echo 必须加入“survey.2

如果broadcasAs

 public function broadcastAs()
    {
        return 'server.message';
    }

echo 必须监听“.server.message” - dot 在说不使用命名空间之前 - 这是事件 - 不是通道!

根据https://github.com/laravel/framework/issues/28210config/database.php 中为 redis 注释掉 'prefix' 行应该可以解决问题,尽管我建议进一步阅读 link 以获得更多见解。

    'redis' => [

        'client' => env('REDIS_CLIENT', 'predis'),

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'predis'),
//            'prefix' => Str::slug(env('APP_NAME', 'laravel'), '_').'_database_',
        ],