php - 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
解决方案
推荐阅读
- docker - 无法从远程 Linux 机器连接到 docker
- azure-devops - Azure DevOps 每晚构建 - 计划 \ cron 语法
- linq - 当前不支持方法“System.Linq.Queryable.TakeLast”的这种重载
- python - 将带有反斜杠后跟数字的字符串转换为路径
- sql-server - 从 API 定位“AlwaysOn 可用性组”数据库
- wordpress - 如何使用 Vue Router 重定向到外部文件
- macos - 在命令行上更新单个 nuget 包 (macOS)
- sas - 高效地从 SAS 读取大型 MSSQL 表
- database-design - 一个包含 2 个不同数据类型的字段的表,其中只有一个用于连接目的,这是一个好的解决方案吗?
- python - 在情节中自定义图例的顺序