O
O
Ogureccc2020-01-31 10:51:27
Laravel
Ogureccc, 2020-01-31 10:51:27

How to properly listen for events in a channel?

Not a very good day, straight to the point, my events are broadcast to the App.User.{id}... channel
using Redis, trying to listen to the event:

$reportJob = (new CreateReport($dataType,  $dataTypeContent, $request->get('excel')))
    ->onConnection('redis')
    ->delay(Carbon::now()->addMinutes(1));

The bottom line is that the user does not wait until the script collects the collection in an excel file, and upon completion, gives the user a link to the finished file.

in the worker I see that everything worked successfully, in laravel-echo-server I see that the event is being broadcast to the channel
qYgR8k5XDQETRBtlAAAM joined channel: private-App.User.1
Channel: opencrm_database_private-App.User.1
Event: report.created

but at the front in the console is empty. I listen like this:
Echo.private(`App.User.{{ auth()->user()->id }}`)
        .listen('.report.created', (e) => {
            console.log(e);
        });

What am I doing wrong?
Z.Y. I have a notification, but it is also not broadcast to the channel
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\BroadcastMessage;

class ReportCreated extends Notification implements ShouldQueue
{
    use Queueable;

    public $report_link;

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

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

    public function toArray($notifiable)
    {
        return [
            'report_link' => $this->report_link
        ];
    }
}

I listened to them with a script from the documentation, when it came to broadcasting to the channel, I decided to first deal with at least the events ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Ogureccc, 2020-01-31
@Ogureccc

Guys, I'm closing the question, the problem was in the names of the channels. I thought that the server adds prefixes to channels only in the log.
With public channel and js:

Echo.channel(`opencrm_database_App.User.{{ auth()->user()->id }}`)
        .listen('AppCreateReport', (e) => {
            console.log(e);
        }).notification((notification) => {
            console.log(notification);
        });

everything works, I'll figure it out myself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question