skip to Main Content

I am trying to follow along with this tutorial: https://www.youtube.com/watch?v=AUlbN_xsdXg which is very straight forward and simple, but unfortunately does not work for me. Based on the comments others do not seem to be having this issue.

This is what I’ve done so far:

  1. Installed "beyondcode/laravel-websockets": "^1.13" and "pusher/pusher-php-server": "7.0" (First tried the current version 7.2 but there was no difference in the error) and did composer updates
  2. Uncommented AppProvidersBroadcastServiceProvider in config/app.php
  3. Changed .env to BROADCAST_DRIVER=pusher and Modified config/broadcasting.php
'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'), // These env vars have config:cache'd dummy values
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'useTLS' => false,
                'encrypted' => false,
                'host' => '127.0.0.1',
                'port' => '6001',
                'scheme' => 'http',
            ],
        ],
  1. Published websockets.php and the migration files/performed the migration
  2. Created the dummy Event class and added ‘implements ShouldBroadcast’
<?php

namespace AppEvents;

use IlluminateBroadcastingChannel;
use IlluminateBroadcastingInteractsWithSockets;
use IlluminateBroadcastingPresenceChannel;
use IlluminateBroadcastingPrivateChannel;
use IlluminateContractsBroadcastingShouldBroadcast;
use IlluminateFoundationEventsDispatchable;
use IlluminateQueueSerializesModels;

class PlaygroundEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return IlluminateBroadcastingChannel|array
     */
    public function broadcastOn()
    {
        return new Channel('public.playground.1');
        // return new PrivateChannel('channel-name');
    }
}
  1. Added a test in my web.php routes file
Route::get('/playground', function(){
    event(new AppEventsPlaygroundEvent());
    return null;
});
  1. When visiting that page I encounter the error:
Argument 4 passed to PusherPusher::trigger() must be of the type array, null given, called in [...]vendorlaravelframeworksrcIlluminateBroadcastingBroadcastersPusherBroadcaster.php on line 113

If you search for that error you will find like 2 results that are both unresolved. Not sure where to mention this but the WebSockets Dashboard appears to work fine.

Environment: PHP Version 7.4.5, Windows 10 64, "laravel/framework": "^7.0", "beyondcode/laravel-websockets": "^1.13", "pusher/pusher-php-server": "7.0" and 7.2 while trying to fix.

Since there’s so little out there for this error I’m not sure where to go next, except here of course. Any help appreciated, thank you.

Edit: The stacktrace: https://justpaste.it/9lwe3

2

Answers


  1. Try adding a payload to the event:

    public function broadcastWith() {
        return [
            "foo" => "bar"
        ];
    }
    

    Alternatively, upgrading to Laravel 8+ should solve this issue.

    Login or Signup to reply.
  2. You can try upgrading your Laravel version to at least v8 or you can downgrade your pusher to a version that will work well with Laravel 7.

    From the Laravel 7 docs at https://laravel.com/docs/7.x/broadcasting, the pusher-php-server version that is used is v4 and you can install it with

    composer require pusher/pusher-php-server "~4.0"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search