php - 使用没有错误消息的私人频道时无法从推送者那里获得响应
问题描述
使用公共频道时,我确实收到了响应,但是当我将其更改为私人频道并检查 channels.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);
});
推荐阅读
- spring - Spring Batch MetaData 表数据未填充到正确的模式中
- javascript - 如何在创建组后立即将组分配给 Cognito 用户?
- kubernetes-helm - 如何定义模板函数以在 Helm 中设置全局或局部容差?
- blockchain - 一个闪电节点可以同时打开多少通道
- python - Selenium Python 在 Span 之间提取文本
- packer - 在 Hashicorp Packer 中,除了脚本类型的功能之外,还有其他选项可以使用 vnc 吗?
- c++ - NULL 和 0 行为相同的问题
- c# - StreamWriter/StreamReader 可以写入/读取 .txt 以外的文件吗?
- python - VirtualBox API - 还原后解锁机器
- python - 无法安装 pip 3.4 版