gpt4 book ai didi

Laravel Socket.io,Redis 事件正在广播但未在客户端显示

转载 作者:可可西里 更新时间:2023-11-01 11:47:21 29 4
gpt4 key购买 nike

在我的 laravel.log 中,我可以看到事件正在 channel 上广播,即

[2018-08-30 13:41:27] local.INFO: Broadcasting [App\Events\NewRating] on channels [rating] with payload:
{
"music": {
"id": 42,
"name": "1535368873_admin.mp3",
"path": "public\/music\/1535368873_admin.mp3",
"rating": 53,
"user_id": 4,
"created_at": "2018-08-27 11:21:13",
"updated_at": "2018-08-27 11:21:13",
"is_last_played": 1,
"is_now_playing": 0,
"location_id": 1
},
"socket": null
}

据我所知,我已根据要求完成所有操作。我的 redis 服务器正在运行。laravel-echo-server 正在运行并且它正在加入我的 channel ,即

[18:41:24] - VX9bkHqs-QHRv3MvAAAC joined channel: rating

这是我订阅 channel 和收听事件的地方

window.app = new Vue({
el: '#app',

beforeMount: function () {
alert("asdas");
this.joinPublicChatChannel();
},

methods: {
joinPublicChatChannel: function () {
Echo.channel('rating').listen('App\\Events\\NewRating', (event) => {
console.log("Event fired!"); //This doesnt work
});
}
}
});

这是我的事件类

class NewRating implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $music;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Music $music)
{
$this->music=$music;
}

/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return new Channel('rating');
}
}

这是我的环境文件

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel_restaurant
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=redis
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=

不知道背后的原因:/

更新

刚刚清除了所有缓存,现在我在 laravel-echo-server 控制台中得到了这个

Channel: rating
Event: App\Events\NewRating
Channel: rating
Event: App\Events\NewRating
Channel: rating
Event: App\Events\NewRating

最佳答案

你可以在你的事件文件中使用它:

public function broadcastAs()
{
return 'NewRating';
}

关于Laravel Socket.io,Redis 事件正在广播但未在客户端显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52098728/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com