0

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 App\Providers\BroadcastServiceProvider 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 App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

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 \Illuminate\Broadcasting\Channel|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 \App\Events\PlaygroundEvent());
    return null;
});
  1. When visiting that page I encounter the error:
Argument 4 passed to Pusher\Pusher::trigger() must be of the type array, null given, called in [...]vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.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

Bryan
  • 623
  • 1
  • 6
  • 23
  • Great question. Go back to your Laravel.log, to the stacktrace. The error in the vendor folder originates from somewhere else. Would you mind showing the stacktrace of the error? – UnderDog Dec 21 '22 at 01:58
  • @UnderDog I've added it to the bottom of the question, thanks. – Bryan Dec 21 '22 at 17:27

2 Answers2

2

Try adding a payload to the event:

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

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

levi
  • 23,693
  • 18
  • 59
  • 73
  • 1
    Thanks, but no difference I'm afraid. I'd prefer not to upgrade to 8 if it can be avoided but I'll definitely keep it in mind. – Bryan Dec 21 '22 at 00:58
  • Focus on this one: `App\\Events\\PlaygroundEvent))`, in the stacktrace and this one: `Illuminate\\Queue\\Queue->pushOn(NULL...`, the paste is great, but I'm still puzzled that the error didn't get triggered in your own source code. There's nothing else to do then to dd() your way through Laravel's sourcecode. May I ask why you don't want to upgrade? Laravel 8 is still PHP 7 compatible, if that would be your reason. – UnderDog Dec 22 '22 at 04:51
  • 1
    @UnderDog It's not a great reason, just that I've had poor experiences with upgrading in react native and trying to fix the dozens/hundreds of obscure errors that sprang from that. Also upgrading other large libraries in RN that caused a similar nightmare. I had a look at the laravel upgrade guide and it does seem thorough so maybe I shouldn't be so reluctant. – Bryan Dec 22 '22 at 06:30
  • 1
    Upgrading to laravel 8 did fix the issue. – Bryan Jan 05 '23 at 00:14
1

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"