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