我正在使用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。 发送身份验证请求时出错。
答案 0 :(得分:0)
您必须在broadcast
authentication
config/app.php
条路线
App\Providers\BroadcastServiceProvider::class,
这样你的routes/channel.php
会检查特定的后卫并根据你的情况返回1或0