无法通过Redis&amp ;;在私人频道上播放通知Laravel 5.3

时间:2017-04-26 11:32:32

标签: laravel-5 redis socket.io laravel-echo

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

import Echo from "laravel-echo"

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

Laravel回波-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()as:

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。   发送身份验证请求时出错。

1 个答案:

答案 0 :(得分:0)

您必须在broadcast

中取消注释以下行,添加authentication config/app.php条路线

App\Providers\BroadcastServiceProvider::class,

这样你的routes/channel.php会检查特定的后卫并根据你的情况返回1或0