bfg/puller is a Laravel package for a description for puller..
It currently has 0 GitHub stars and 73 downloads on Packagist (latest version 2.1.1).
Install it with composer require bfg/puller.
Discover more Laravel packages by bfg
or browse all Laravel packages to compare alternatives.
Last updated
composer require bfg/puller
This package is intended for cases when you need a minimum real time, but to raise the WebSocket too expensive or meaningless. The essence of the package is the simplest Long Pull, which is easy to install and configure. It added control over the user's tabs, which allows us to control the status of all the user tabs and send commands to all the user tabs at all, to all browsers. So, we have an excellent opportunity to follow the online meter and a real-time list of users.
Be careful, the package uses the default caching system by default,
with the driver that is listed there, but if you switch the caching
driver to redis, then you will feel a significant increase in speed
and get a better and accurate task distribution system and online.
...
CACHE_DRIVER=redis
...
To do this, you should have the extension
Redisforphp.
In order to start using, you need to make a couple of simple things:
public/vendor folder published puller/puller.js.
He had to appear immediately after installing the package,
as it broads publications in the laravel-assets group.
If this did not happen and you did not appear there, publish it manually:php artisan vendor:publish --tag=puller-assets
<script src="{{ asset('vendor/puller/puller.js') }}"></script>
document.addEventListener('my_test', function ({detail}) {
console.log(detail);
});
\Puller::user(Auth::user())
->channel('my_test')
->stream('Hello world!');
Further, in the browser, in the developer console, you will see the reaction.
If you want the main processing and data from receiving data on the side of the task recipient, you must use that advanced
Pullers, since thehandlemethod is always performed on the recipient side.
Generate worker:
php artisan make:task MyTestPull
After that, you will have a class worker:
app/Pulls/MyTestPull.php
<?php
namespace App\Pulls;
use Bfg\Puller\Task;
class MyTestPull extends Task
{
public function handle () {
//
}
}
What will be described in the Handle method will be performed on the client
side when the task is performed. And the fact that this method will return,
will be sent as the details of the event. The event name will be generated
automatically or you can specify the protected ?string $name = "my_name"; property.
public function handle () {
return "Hello world!";
}
Prepare your own document event listener:
document.addEventListener('my_test_pull', function ({detail}) { //
console.log(detail);
});
The name of the class-based event will be generated in
snake_case,MyTestPullwill turn into amy_test_pull.
Submit the Puller worker:
\App\Pulls\MyTest::user(\Auth::user())
->stream();
Further, in the browser, in the developer console, you will see the reaction.
app/Pulls/SayHelloPull.php
<?php
namespace App\Pulls;
use Bfg\Puller\Task;
class MyTestPull extends Task
{
protected $user_name;
public function __construct(string $user_name) {
$this->user_name = $user_name;
}
public function handle () {
return "Hello, " . $this->user_name;
}
}
Current authorized user So will always be installed by default, it is simply indicated by an example of a user transmission, you can pass as a model there and the identifier.
\App\Pulls\MyTest::user(\Auth::user()) // Current auth user set by default
->stream('Administrator');
\App\Pulls\MyTest::flux('Administrator');
\App\Pulls\MyTest::flow('Administrator');
\App\Pulls\MyTest::new()->channel('my_test')->flow('Administrator');
\App\Pulls\MyTest::totab($tabid, 'Administrator');
\App\Pulls\MyTest::new()->channel('my_test')->totab($tabid, 'Administrator');
php artisan make:task DarkMode_Toggle
Well be generated
dark_mode.togglename
An event that triggers if the user appeared online.
Event::listen(\Bfg\Puller\Events\UserOnlineEvent::class, function (UserOnlineEvent $event) {
info("User $event->user_id online");
});
The event that triggers in the case when the user is lost.
Event::listen(\Bfg\Puller\Events\UserOfflineEvent::class, function (UserOfflineEvent $event) {
info("User $event->user_id offline");
});
An event that triggers in the case when the user opens a new tab.
Event::listen(\Bfg\Puller\Events\UserNewTabEvent::class, function (UserNewTabEvent $event) {
info("User $event->user_id new tab $event->tab");
});
Attention! If you reboot a tab, offline and online events will not work, since in fact you stay online if you need an event for each page load, understand that every time you restart the page it is believed that you create a new tab.
The event that triggers in the case when the user closes the tab.
Event::listen(\Bfg\Puller\Events\UserCloseTabEvent::class, function (UserCloseTabEvent $event) {
info("User $event->user_id close tab $event->tab");
});
\Puller::myTab();
\Puller::new();
\Puller::channel();
\Puller::online();
\Puller::users();
\Puller::isOnlineUser(int $user_id);
\Puller::identifications();
\Puller::onOnline(function (UserOnlineEvent $event) {
info("User $event->user_id online");
});
\Puller::onOffline(callable);
\Puller::onOnlineAndOffline(callable);
\Puller::onNewTab(callable);
\Puller::onCloseTab(callable);
\Puller::onNewAndCloseTab(callable);
You can use helpers for listeners of model events.
\App\Pulls\MyTest::modelWatchToStream(
\App\Modeld\Message::class,
$events = [] // 'updated', 'created', 'deleted' by default
);
\App\Pulls\MyTest::modelWatchToFlow(
\App\Modeld\Message::class,
$events = [] // 'updated', 'created', 'deleted' by default
);
\App\Pulls\MyTest::modelWatchToFlux(
\App\Modeld\Message::class,
$events = [] // 'updated', 'created', 'deleted' by default
);
\App\Pulls\MyTest::modelOwnerWatchToStream(
\App\Modeld\Message::class,
$owner_field = "user_id",
$events = [] // 'updated', 'created', 'deleted' by default
);
\App\Pulls\MyTest::modelOwnerWatchToFlow(
\App\Modeld\Message::class,
$owner_field = "user_id",
$events = [] // 'updated', 'created', 'deleted' by default
);
\App\Pulls\MyTest::modelOwnerWatchToFlux(
\App\Modeld\Message::class,
$owner_field = "user_id",
$events = [] // 'updated', 'created', 'deleted' by default
);
// Or
\App\Pulls\MyTest::modelWatchToFlow([
\App\Modeld\Message::class,
\App\Modeld\User::class,
]);
The report will be sent to the user the identifier of which is called in this column that you indicated in the property
$owner_field(may be an array with a list of several columns).
The area of liability movement, if the zone will be released inside the zone, the zone will fix it and posts the call to the mass control queue, and the general call may already delegate the type of shipment. Thus, we have mass control over tasks.
\Puller::moveZone('admin', function () {
\Puller::channel('test')->detail('hi');
\Puller::channel('test2')->detail('hi2');
\Puller::channel('test3')->detail('hi3');
})->flux();
You have a globally registered Puller object that is intended for external control.
Puller.tab(); // Get current tab id.
Puller.run(); // Run subscription.
Puller.stop(); // Stop subscription.
Puller.restart(); // Reconnect subscription will make stop and launch.
Puller.channel(name, callback); // Add Channel handler (Alpine and Livewire are channels).
Puller.state(name, value); // Set or unset the state for uninterrupted communication.
Puller.emit(channel, name, detail); // Reply imitation to `Puller`.
Puller.dispatch(eventName, detail); // Dispatch a browser event.
Puller.message(eventName, data); // Send a message with the name of events and data for Backend.
Messages - this is a mechanism for performing tasks in a stream that distributes tasks to the current execution request and on the connections.
In order to use the messaging mechanism you should know the minimum data type specification.
Message is a signed request for an event.
What to transmit the names of the events and
at the same time not to transmit its full
range of names, the system is looking for
nesting in any space that is compiled depending
on your security guard, the default is web
So your nesting prefix will be the next WebMessage
And all created and declared Events and will cause them
consistently if there will be several events in one name.
Event search occurs on the following pattern:
Send name:
my-eventormy;Called Event:
*\WebMessage\MyEvent
Send name:
actions:my-eventoractions:my;Called Event:
*\WebMessageActions\MyEvent
*- Maybe any value.
All events Puller send from such an event will be inserted in
response to the request and the task will be distributed to what
a service station can be processed now and what needs to be
sent to others.
All transmitted values in the message will be added as a form to request.
php artisan puller:events
https://github.com/bfg-s/puller-livewire
https://github.com/bfg-s/puller-alpine
Please see CHANGELOG for more information what has changed recently.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.