0

我正在使用 Laravel-Redis-Socketio-LaravelEcho 制作实时通知。到目前为止,我能够广播到公共频道,但坚持使用私人频道。
我的 bootstrap.js:

import Echo from "laravel-echo"

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001'
});

Laravel-echo-server.json:

"authHost": "http://localhost",
    "authEndpoint": "/broadcasting/auth",
    "clients": [
        {
            "appId": "{{Omitted purposely}}",
            "key": "{{Omitted purposely}}"
        }
    ],
    "database": "redis",
    "databaseConfig": {
        "redis": {},
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": true,
    "host": null,
    "port": "6001",
    "protocol": "http",
    "socketio": {},
    "sslCertPath": "",
    "sslKeyPath": ""

在我的通知类中,我将 broadcastOn() 设置为:

public function broadcastOn() {
        return new PrivateChannel('my-channel');
    }

我的客户端是:

Echo.private('my-channel')
    .notification((notification) => {
        console.log('I am here');
    });

使用公共频道一切正常,但使用私人频道,命令行在启动 laravel-echo-server 后显示以下内容:

错误:连接 ECONNREFUSED 127.0.0.1:80。发送身份验证请求时出错。

4

1 回答 1

0

您必须通过取消注释以下行来添加broadcast authentication路线config/app.php

App\Providers\BroadcastServiceProvider::class,

以便在您的routes/channel.php遗嘱中检查特定的守卫并根据您的条件返回 1 或 0

于 2017-04-28T13:52:57.347 回答