使用公共频道时,我确实得到了响应,但是当我将其更改为带有签入频道的私人频道时.php文件返回true,我没有得到任何响应,从推送者的角度来看,很明显消息正在到达那里,但之后laravel echo没有得到响应
希望我的代码能帮助你配置事件
public function broadcastOn()
{
return new PrivateChannel('Chat.'. $this->chat->user_id.'.'.$this->chat->friend_id);
}
添加频道
Broadcast::channel('Chat.{user_id}.{friend_id}', function ($user,
$user_id,$friend_id) {
return $user->id == $friend_id;
});
从此通道获取数据
axios.post('/chat/getchat/'+friendId).then((response)=>{
this.chats = response.data;
});
Echo.private('Chat.'+friendId+'.'+userId)
.listen('BroadcastChat',(e)=>{
this.chats.push(e.chat);
});