您好,我目前正在使用 Laravel 學(xué)習(xí) Vue.js 并嘗試開發(fā)團(tuán)隊(duì)聊天。由于經(jīng)濟(jì)原因,我使用了 redis 而不是 pusher,并使用了這個(gè) laravel echo server作為 echo server。一旦您選擇了一個(gè)團(tuán)隊(duì),群聊就會(huì)將用戶連接到一個(gè)私人頻道。之后它加載消息并在前端顯示它們。當(dāng)您發(fā)送消息時(shí),控制器操作成功執(zhí)行并且消息存儲在數(shù)據(jù)庫中。然而,用戶和其他團(tuán)隊(duì)成員必須重新單擊團(tuán)隊(duì)名稱并因此重新加載消息列表以獲取最新消息,盡管事件在回顯服務(wù)器上被觸發(fā)并且 Redis 接收到消息。這是當(dāng)有人選擇團(tuán)隊(duì)聊天并發(fā)送消息時(shí)我從回顯服務(wù)器得到的:[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這是我從監(jiān)控 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 回答

繁星淼淼
TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個(gè)贊
找到了問題的原因。在redis監(jiān)控上可以看到,通道名是有前綴的。我
在 .env 中設(shè)置 REDIS_PREFIX= 以刪除此前綴。
- 1 回答
- 0 關(guān)注
- 122 瀏覽
添加回答
舉報(bào)
0/150
提交
取消