XXXXX无法通过在线状态进行身份验证,客户端无法通过身份验证,HTTP状态为404

时间:2020-10-22 13:12:24

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

我是Laravel的新手。我尝试使用Laravel和ReactJS,Socket.io,Redis构建实时消息时遇到问题 启动laravel-echo服务器时出现错误

enter image description here

文件laravel-echo-server.json

{
"authHost": "http://localhost:8000",
"authEndpoint": "/broadcasting/auth",
"clients": [
    {
        "appId": "XXXXXXXXXX",
        "key": "XXXXXXXXXXXXXXXXXXXXX"
    }
],
"database": "redis",
"databaseConfig": {
    "redis": {},
    "sqlite": {
        "databasePath": "/database/laravel-echo-server.sqlite"
    }
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
    "http": true,
    "redis": true
},
"apiOriginAllow": {
    "allowCors": false,
    "allowOrigin": "",
    "allowMethods": "",
    "allowHeaders": ""
}

}

channels.php文件

Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});

Broadcast::channel('online', function ($user) {
return $user;
});

在客户端使用ReactJS, 文件index.js

import Echo from "laravel-echo"

window.io = require('socket.io-client');

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

window.Echo.join(`online`)
  .here((users) => {
    console.log(users)
  })
  .joining((user) => {
    console.log(user.name);
  })
  .leaving((user) => {
    console.log(user.name);
  });

需要帮助...非常感谢!

0 个答案:

没有答案