xx无法通过在线状态验证,客户端无法通过身份验证,获得http状态404

np8igboo  于 2021-06-09  发布在  Redis
关注(0)|答案(0)|浏览(189)

我是个新手。当我试图用laravel&reactjs、socket.io、redis errors构建一条实时消息时,我遇到了一个问题

文件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);
  });

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

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题