Broadcasting notifications!!! #511
Unanswered
avazquez-bit
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, me again!!!
I have new questions... So, a little of context
I'm building an app to keep track of tasks and tickets
In the first idea, the app make an API request, to get data from server on every change of page, so it keeps date updated all time, the "problem" is that every hange of page or event every search of data take about 3 - 5 seconds, so for the begining that was ok, but now, we want to realease for all colaborator for the company, so this behavior could bring us some problems because too many requests and the perseption that app runs slowly, So...
In the next version we have the idea to copy data locally, to avoid continuis requests to server and increase speed, and its done, the app now runs more faaster, even se change of page in almost instatly, so fine until here, but to keep data updated we use the scheduler, so a task run every minute and make an API request to update existing data and copy new data, for this point it works fine
So the next function we try to apply is when update is running, I've add a broadcasting event to my scheduled task, to show a item que indicate de user, that data is being updated, and tried to listen for this event in a livewire component to show de alert, but I cant catch event, i see the event in laravel log, event native events live widnow blured and so appears there too with my custom event, but, in my livewire component I cant catch it
I thought I was triggering event, in wrong way, so I emited an event from other livewire component and using it, my notification shows...
So I wondering if I'm doing well
Here is my envolved code!!!
this code is from my scheduled task
`class GetSamvaActivities extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:get-samva-activities';
}
`
This code is from my console.php code
Schedule::command('app:get-samva-activities')->everyMinute();
This code is from my event
`<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
class SyncData implements ShouldBroadcastNow
{
use Dispatchable;
}
`
and this code if from my livewire volt component
`<?php
use Livewire\Attributes\On;
use Native\Laravel\Events\Windows\WindowBlurred;
use function Livewire\Volt{on, state};
state(['status', 'windowFocused']);
on(['native:custom' => function () {
$this->status = 'updating';
}
]);
?>
As you can see in my console.php class that runs every minute is called my class GetSamvaActivities throw the artisan command, here is called the event SyncData at the begining, and finally, my livewire component is listenign for the notification on channel, so I dont know if the event can be triggered by schedulres, there is nothig to indicated isnt possible, so I assume is possible, then I cant find why is not working, the event here is called with native:custom but I've tryed with 'custom' and other names in all referenced clases
Beta Was this translation helpful? Give feedback.
All reactions