我正在创建实时聊天应用程序。我已经在我的 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 关注
- 181 浏览
添加回答
举报
0/150
提交
取消