ulrichm
2 years ago

Event will not broadcast to Pusher with BroadcastOn

Posted 2 years ago by ulrichm

Where could the problem lie ??

From a controller, I call

 event(new TaskWasCreated($newTask->id));

TaskWasCreated:

<?php

namespace App\Events;

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

class TaskWasCreated implements ShouldBroadcast // also tried extends Event
{
    use Dispatchable, InteractsWithSockets, SerializesModels; // also tried without InteractsWithSockets

    public $taskId;

    /**
     * TaskWasCreated constructor.
     * @param $taskId
     */
    public function __construct($taskId)
    {
        $this->taskId = $taskId;
    }

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

.env:

BROADCAST_DRIVER=pusher

PUSHER_APP_ID=xxxxxx
PUSHER_APP_KEY=yyyyyyyyyyyyyyy
PUSHER_APP_SECRET=zzzzzzzzzzzzzzz

broadcasting.php:

    'default' => env('BROADCAST_DRIVER', 'pusher'),

    'connections' => [

        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => 'eu',
                'encrypted' => true
            ],
        ],

All I get i a entry in the laravel.log:

[2017-02-15 11:19:12] local.INFO: Broadcasting [App\Events\TaskWasCreated] on channels [it_channel] with payload:
{
    "taskId": 14,
    "socket": null
}  

Nothing hits pusher.coms debug console, BUT if I insert this code in the controller, it DOES reach pusher ??:

  $options = array(
      'cluster' => 'eu',
      'encrypted' => true
  );
  $pusher = new Pusher(
      'yyyyyyyyyyyyyyy',
      'zzzzzzzzzzzzzzz',
      'xxxxxx',
      $options
  );
        $data['taskId'] = 1;
        $pusher->trigger(['it_channel'], 'TaskWasTested', $data);


         // $input = $request->all();
        // return Task::create($input);
        return $this->serve(CreateTaskFeature::class);
    }

And it does not make a log entry.

Please sign in or create an account to participate in this conversation.