我正在尝试使用 laravel 作为后端和 reactjs 作为前端来构建一个视频聊天 Web 应用程序。我试图在这里找到错误,但我找不到。请帮我解决我的错误。
显示的错误:
1/ 发布http://localhost/pusher/auth 404 (Not Found)
2/ 推杆 : : ["Error: Unable to retrieve auth string from auth endpoint - received status: 404 from /pusher/auth. 客户端必须经过身份验证才能加入私人或在线频道。请参阅:https://pusher.com/docs/authenticating_users"]
我的代码来自“resources/js/components/App.js”
setupPusher(){
Pusher.logToConsole = true;
this.pusher = new Pusher(APP_KEY,{
authEndpoint: '/pusher/auth',
cluster: 'ap2',
auth:{
params: this.user.id,
headers:{
'X-CSRF-Token': window.csrfToken
}
}
});
this.channel = this.pusher.subscribe('presence-video-channel');
this.channel.bind(`clnt-signal-${this.user.id}`,(signal) => {
let peer = this.peers[signal.userId];
// if peer is not already exists, we got an incoming call
if(peer == undefined){
this.setState({otherUserId: signal.userId});
peer = this.startPeer(signal.userId, false);
}
peer.signal(signal.data);
});
}
我的代码来自“ routes/web.php”
Route::post('/pusher/auth', [App\Http\Controllers\HomeController::class, 'authenticate']);
我的代码来自“app/Http/Controllers/HomeController.php”
public function authenticate(Request $request){
$socketId = $request->socket_id;
$channelName = $request->channel_name;
$pusher = new Pusher('a384f250f86af1f16f98', 'd30d380941bdec2e4e55', '1147033', [
'cluster' => 'ap2',
'useTLS' => true
]);
$presence_data = ['name' => auth()->user()->name];
$key = $pusher->presence_auth($channelName, $socketId, auth()->id(), $presence_data);
return response($key);
}