您好,我目前正在使用 Laravel 学习 Vue.js 并尝试开发团队聊天。由于经济原因,我使用了 redis 而不是 pusher,并使用了这个 laravel echo server作为 echo server。一旦您选择了一个团队,群聊就会将用户连接到一个私人频道。之后它加载消息并在前端显示它们。当您发送消息时,控制器操作成功执行并且消息存储在数据库中。然而,用户和其他团队成员必须重新单击团队名称并因此重新加载消息列表以获取最新消息,尽管事件在回显服务器上被触发并且 Redis 接收到消息。这是当有人选择团队聊天并发送消息时我从回显服务器得到的:[10:20:41 PM] - gK5b68mvO1goLE4nAAAI authenticated for: private-messages.11[10:20:41 PM] - gK5b68mvO1goLE4nAAAI joined channel: private-messages.11Channel: clash_finder_database_private-messages.11Event: App\Events\NewMessage这是我从监控 redis-server得到的:1589921588.805758 [0 127.0.0.1:37594] "PUBLISH" "clash_finder_database_private-messages.11" " {\"event\":\"App\\\\Events\\\\NewMessage\",\"data\":{\"message\": {\"id\":9,\"message\":\"test\",\"team_id\":11,\"user_id\":3,\"created_at\":\"2020-05-19 20:53:08\",\"updated_at\":\"2020-05-19 20:53:08\"},\"socket\":null},\"socket\":null}"我的NewMessage事件如下所示:namespace App\Events;use App\Message;use Illuminate\Broadcasting\Channel;use Illuminate\Broadcasting\InteractsWithSockets;use Illuminate\Broadcasting\PresenceChannel;use Illuminate\Broadcasting\PrivateChannel;use Illuminate\Contracts\Broadcasting\ShouldBroadcast;use Illuminate\Foundation\Events\Dispatchable;use Illuminate\Queue\SerializesModels;class NewMessage implements ShouldBroadcast{use Dispatchable, InteractsWithSockets, SerializesModels;public $message;/** * Create a new event instance. * * @param Message $message */public function __construct(Message $message){ $this->message = $message;}/** * Get the channels the event should broadcast on. * * @return \Illuminate\Broadcasting\Channel|array */public function broadcastOn(){ return new PrivateChannel('messages.' . $this->message->team_id);}}
- 1 回答
- 0 关注
- 90 浏览
添加回答
举报
0/150
提交
取消