我正在創建實時聊天應用程序。我已經在我的 laravel 和 vue.js 項目中設置了 pusher。但它不起作用。雖然我在控制臺中沒有任何錯誤。另外,我在網絡選項卡中沒有錯誤。我需要創建信使應用程序,所以我需要一個實時聊天功能。現在,我可以推送用戶的評論,但在其他用戶的窗口中,什么也沒有顯示。但它確實如此,一旦我刷新頁面。我認為我的推送器設置有問題,因為在推送器調試控制臺中,沒有執行任何會話。這是我的代碼。.envBROADCAST_DRIVER=pusherCACHE_DRIVER=fileQUEUE_CONNECTION=syncSESSION_DRIVER=fileSESSION_LIFETIME=120PUSHER_APP_ID=my idPUSHER_APP_KEY=my app keyPUSHER_APP_SECRET= my secret keyPUSHER_APP_CLUSTER=mt1廣播.php'pusher' => [ 'driver' => 'pusher', 'key' => env('my key'), 'secret' => env('my secret key'), 'app_id' => env('my id'), 'options' => [ 'cluster' => 'ap3', 'encrypted' => true, ],廣播服務提供者.phpBroadcast::routes(['middleware' => ['auth:api']]); require base_path('routes/channels.php');引導程序.jsimport Echo from 'laravel-echo'window.Pusher = require('pusher-js');window.Echo = new Echo({ broadcaster: 'pusher', key: 'my key', cluster: 'ap3', encrypted: true});新消息.phpuse Illuminate\Contracts\Broadcasting\ShouldBroadcast;class NewMessage implements ShouldBroadcast{ use Dispatchable, InteractsWithSockets, SerializesModels; public $message; /** * Create a new event instance. * * @return void */ 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->to); } public function broadcastWith() { $this->message->load('fromContact'); return ["message" => $this->message]; }}路線/頻道.phpuse Illuminate\Support\Facades\Broadcast;
- 2 回答
- 0 關注
- 206 瀏覽
添加回答
舉報
0/150
提交
取消