首页 > 解决方案 > Laravel 回显通知 + 套接字 io ,未收到通知

问题描述

所以我有 laravel echo 设置,一个通知类,我正在客户端监听 App.User.{id} 频道,但是每当我监听通知时,我什么都没有。我的 laravel echo 服务器正在工作;

[18:11:06] - Preparing authentication request to: http://localhost:3000
[18:11:06] - Sending auth request to: http://localhost:3000/broadcasting/auth

[18:11:07] - HTQYvo_jRsIn9YNbAAAE authenticated for: private-App.User.1
[18:11:07] - HTQYvo_jRsIn9YNbAAAE joined channel: private-App.User.1

我的 NotifyUser.class

class NotifyUser extends Notification implements ShouldQueue, ShouldBroadcast
{

    public function via($notifiable)
    {
        return ['database', 'broadcast'];
    }

    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
            'notification' => 1,
            'message' => $this->message,
            'orderId' => $this->orderId
        ]);
    }
}

我的前端:

import Echo from "laravel-echo";

window.io = require('socket.io-client');

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001'
});

监听通知:

 Echo.private(`App.User.${this.user.id}`)
                .notification((notification) => {
                    console.log(notification);
                });

我的队列监听器:

vagrant@homestead:~/code/ProjectTest$ php artisan queue:listen
[2020-03-11 16:11:18][119] Processing: App\Notifications\ProjectTest\NotifyUser
[2020-03-11 16:11:18][119] Processed:  App\Notifications\ProjectTest\NotifyUser
[2020-03-11 16:11:20][120] Processing: App\Notifications\ProjectTest\NotifyUser
[2020-03-11 16:11:20][120] Processed:  App\Notifications\ProjectTest\NotifyUser
[2020-03-11 16:11:21][121] Processing: Illuminate\Notifications\Events\BroadcastNotificationCreated
[2020-03-11 16:11:21][121] Processed:  Illuminate\Notifications\Events\BroadcastNotificationCreated

标签: phplaravel

解决方案


推荐阅读