标签: laravel-broadcast

为什么BroadCastEvent在Laravel中排队?怎么阻止?

我正在研究需要实时广播纬度和经度的项目

我有类似下面的东西

namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Support\Facades\Redis;

class TrackersBroadcast extends Event implements ShouldBroadcast
{
        public  $lat, $lng,$imei,$date_time

    use SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(
                                    $lat, 
                                    $lng, 
                                    $imei, 
                                    $date_time 

                                )

    {
        $this->lat = $lat;
        $this->lng = $lng;
        $this->imei = $imei;
        $this->date_time = $date_time;

    }

    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['tracker-channel']; …
Run Code Online (Sandbox Code Playgroud)

php message-queue redis laravel laravel-broadcast

11
推荐指数
2
解决办法
2332
查看次数

如何配置流明以通过Pusher广播事件?

Lumen的文档指出:“ Lumen开箱即用地支持多个广播驱动程序:PusherRedislog用于本地开发和调试的驱动程序。每个驱动程序均包含一个配置示例。BROADCAST_DRIVER配置选项可用于设置默认驱动程序。”

在我的.env文件中,我已设置BROADCAST_DRIVER=pusher。我在哪里/如何配置我的推送程序ID,密钥和机密?我看到在Laravel中有一个用于设置这些选项的配置文件config/broadcasting.php我在流明的哪里可以设置这些选项?

暂时,我已经编辑Illuminate\Broadcasting\BroadcastManager并硬编码了我的值。

protected function createPusherDriver(array $config)
    {
        // override
        $app_id = 'hidden';
        $key = 'hidden';
        $secret = 'hidden';

        return new PusherBroadcaster(
            new Pusher($key, $secret, $app_id, Arr::get($config, 'options', []))
        );
    }
Run Code Online (Sandbox Code Playgroud)

php laravel pusher lumen laravel-broadcast

5
推荐指数
1
解决办法
1929
查看次数

如何使用 Laravel Broadcasting 实现高速

我正在开发 Laravel 应用程序,我需要实现广播功能。官方文档https://laravel.com/docs/7.x/broadcasting建议了3种方式:

  1. Pusher.com --> 回声
  2. laravel-websockets --> Echo
  3. Redis --> Socket.Io --> Echo

到目前为止,我已经尝试仅使用 Pushes.com 解决方案作为最简单的解决方案。在我的睾丸上,该解决方案向用户浏览器发送消息,延迟约 1 秒。但1秒对我来说太长了。

  • Laravel 广播解决方案的正常延迟是多少?
  • 哪种解决方案最适合使用?
  • 方案2和方案3如何选择?

php websocket laravel pusher laravel-broadcast

5
推荐指数
0
解决办法
404
查看次数

如何测试/断言 Laravel 中是否广播事件

我正在开发一个 Laravel 应用程序。我在我的应用程序中使用 Laravel Broadcast。我现在想做的是测试 Laravel 中是否广播了一个事件。

我正在广播这样的事件:

broadcast(new NewItemCreated($item));
Run Code Online (Sandbox Code Playgroud)

我想测试该事件是否被广播。我该如何测试它?我的意思是在单元测试中。我想做类似的事情

Broadcast::assertSent(NewItemCreated::class) 
Run Code Online (Sandbox Code Playgroud)

附加信息

该事件在创建项目时触发的观察者事件中广播。

laravel laravel-testing laravel-events laravel-broadcast

4
推荐指数
1
解决办法
6323
查看次数

Laravel 广播通知 - 尝试发送通知时出现“array_key_exists()”错误

我正在尝试在数据更改时向用户发送广播通知。但是每次我尝试发送通知时,都会收到此错误:

array_key_exists(): The first argument should be either a string or an integer.

这是我的通知:

class MyNotification extends Notification
{
    use Queueable;

    public $games;

    public $title;
    public $summary;
    public $url;

    public function __construct($games)
    {
        $this->games = $games;

        $this->title = "Your games";
        $this->summary = "Games for {$games[0]->team}";
        $this->url = "/some/url";
    }

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

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return …
Run Code Online (Sandbox Code Playgroud)

broadcast laravel laravel-echo laravel-notification laravel-broadcast

3
推荐指数
1
解决办法
453
查看次数