我正在創(chuàng)建實(shí)時聊天應(yīng)用程序。我已經(jīng)在我的 laravel 和 vue.js 項目中設(shè)置了 pusher。但它不起作用。雖然我在控制臺中沒有任何錯誤。另外,我在網(wǎng)絡(luò)選項卡中沒有錯誤。我需要創(chuàng)建信使應(yīng)用程序,所以我需要一個實(shí)時聊天功能?,F(xiàn)在,我可以推送用戶的評論,但在其他用戶的窗口中,什么也沒有顯示。但它確實(shí)如此,一旦我刷新頁面。我認(rèn)為我的推送器設(shè)置有問題,因?yàn)樵谕扑推髡{(diào)試控制臺中,沒有執(zhí)行任何會話。這是我的代碼。.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, ],廣播服務(wù)提供者.phpBroadcast::routes(['middleware' => ['auth:api']]); require base_path('routes/channels.php');引導(dǎo)程序.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 關(guān)注
- 205 瀏覽
添加回答
舉報
0/150
提交
取消