tastyigniter / ti-ext-broadcast
Push browser notifications in real-time from your TastyIgniter application.
Fund package maintenance!
tastyigniter
Open Collective
Installs: 5 389
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 3
Open Issues: 4
Language:JavaScript
Type:tastyigniter-package
Requires
- ably/ably-php: ~1.0
- pusher/pusher-php-server: ~7.0
- tastyigniter/core: ^4.0
Requires (Dev)
- larastan/larastan: ^2.4
- laravel/pint: ^1.2
- pestphp/pest-plugin-laravel: ^3.0
- rector/rector: ^1.2
- sampoyigi/testbench: ^1.0
- v4.x-dev
- dev-master / 4.0.x-dev
- v4.0.1
- v4.0.0
- v4.0.0-beta.1
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/npm_and_yarn/elliptic-6.6.1
- dev-dependabot/npm_and_yarn/webpack-5.98.0
- dev-dependabot/npm_and_yarn/express-4.21.2
- dev-dependabot/github_actions/dependabot/fetch-metadata-2.3.0
This package is auto-updated.
Last update: 2025-03-07 14:06:42 UTC
README
Introduction
The TastyIgniter Broadcast extension leverages Laravel Broadcasting to deliver real-time browser notifications in response to specific events within TastyIgniter. This extension allows you to broadcast system events such as order status updates, reservation notifications, and more to your TastyIgniter website.
While the extension is designed to integrate with the Pusher service, it also supports other Laravel broadcast drivers.
Installation
You can install the extension via composer using the following command:
composer require tastyigniter/ti-ext-broadcast:"^4.0" -W
By default, the extension registers the /broadcasting/auth
route to handle authorization requests
Getting started
- Navigate to Admin > Manage > Settings > Broadcast Events to configure the extension. You will need to enter your Pusher App ID, Pusher Key, and Pusher Secret.
- You must configure and run a queue worker to process broadcast jobs. You can read more about this in the Queue worker section of the TastyIgniter installation documentation.
Usage
The Broadcast extension handles authorisation for the following broadcast channels:
main.user.{userId}
: A private channel for broadcasting events to a specific customer.admin.user.{userId}
: A private channel for broadcasting events to a specific staff member.
You can broadcast your custom events directly from your code, or you can broadcast other system events by registering event broadcasts class.
Defining broadcast events
To broadcast an event, you need to define an event broadcast class that implements the Illuminate\Contracts\Broadcasting\ShouldBroadcast
interface. The event broadcast class should define a broadcastOn
method that returns the channels the event should be broadcast on.
An event broadcast class is typically stored in the src/Events
directory of your extension.
namespace Author\Extension\Events; use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Queue\SerializesModels; class OrderStatusUpdated implements ShouldBroadcast { use Queueable, SerializesModels; public function __construct( public Activity $activity ) {} public function broadcastOn(): array { return [ new PrivateChannel('admin.user.'.$this->activity->user_id) ]; } }
In this example, the event is broadcast on a private channel named admin.user.{user_id}
.
For more details, refer to Laravel's Defining Broadcast Events documentation.
Registering event broadcasts
Once you have defined an event broadcast class, you need to register the event broadcast class to be broadcast when a system event is fired. You can do this by defining a registerEventBroadcasts
method on your extension class. The method should return an array of system event aliases and their corresponding event broadcast classes:
public function registerEventBroadcasts() { return [ 'igniter.cart.orderStatusAdded' => \Author\Extension\Events\OrderStatusUpdated::class, ]; }
In this example, the OrderStatusUpdated
event will be broadcast when the igniter.cart.orderStatusAdded
system event is fired.
Broadcasting events
By default, TastyIgniter will automatically broadcast registered event classes when the associated system event is fired. However, you can also manually broadcast events using the event's dispatch
method.
use Author\Extensions\Events\OrderStatusUpdated; OrderStatusUpdated::dispatch($activity);
Receiving broadcasts
You can listen for events on user authenticated channels or public channels as follows:
// User Authenticated Channel Broadcast.user() .listen('eventName', (e) => { console.log(e); }) // Public Channel Broadcast.channel('channelName') .listen('eventName', (e) => { console.log(e); })
Changelog
Please see CHANGELOG for more information on what has changed recently.
Reporting issues
If you encounter a bug in this extension, please report it using the Issue Tracker on GitHub.
Contributing
Contributions are welcome! Please read TastyIgniter's contributing guide.
Security vulnerabilities
For reporting security vulnerabilities, please see our our security policy.
License
TastyIgniter Broadcast extension is open-source software licensed under the MIT license.