我已经安装了Laravel echo server和Laravel echo client。
以下是laravel-echo-server.json配置。
{
"authHost": "http://taxation.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "APP_ID",
"key": "someKey"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": "127.0.0.1",
"port": "3000",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": ""
}
以下脚本用于侦听频道事件。 npm run dev
可以很好地构建它。
import Echo from 'laravel-echo'
let token = document.head.querySelector('meta[name="token"]');
if (token) {
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
window.Echo = new Echo({
broadcaster: 'socket.io',
host: '127.0.0.1:3000',
reconnectionAttempts: 5
});
window.Echo.join('checked-in-1')
.listen('.user.checked_in', (e) => {
console.log(e);
});
尝试在start laravel-echo-server
命令上侦听任何事件时。它不停地投掷Client can not be authenticated, got HTTP status 500
。
注意:
我真的没有在laravel-echo-serve和google上找到任何帮助。
任何帮助都会受到很多赞赏。
Laravel V5.4
由于
答案 0 :(得分:1)
因为CSRF令牌而刚刚遇到问题。没有将令牌传递给回声。
window.Echo = new Echo({
broadcaster: 'socket.io',
host: '127.0.0.1:3000',
reconnectionAttempts: 5,
csrfToken: token.content <--
});