Rush
Table of Contents
About
Rush is a powerful package that enables real-time event handling on web pages using WebSockets. It seamlessly integrates with Laravel and MoonShine admin panel to provide a robust solution for notifications, collaborative form editing, and dynamic content updates.
Features
- Real-time Notifications: Instantly receive and display notifications on the page.
- Collaborative Form Editing: Display active users on editing forms and track their actions in real-time.
- Dynamic Fragment Reload: Reload specific page fragments without a full page refresh.
- Flexible WebSocket Support: Compatible with various WebSocket applications:
- Laravel Echo (Pusher, Reverb)
- Centrifugo
- SocketIO
- Custom solutions
Installation
-
Install the package via Composer:
composer require moonshine/rushcomposer require moonshine/rush -
Publish assets, configuration, and WebSocket application code samples:
php artisan moonshine-rush:installphp artisan moonshine-rush:install -
If you're using notifications from this package, replace
MoonShineNotificationContract
in your service provider:$this->app->bind(MoonShineNotificationContract::class, RushNotificationAdapter::class);$this->app->bind(MoonShineNotificationContract::class, RushNotificationAdapter::class);
Usage
Notifications
Attach the HasRushNotifications
trait to your MoonShineLayout:
final class MoonShineLayout extends CompactLayout{use HasRushNotifications;// ...}
final class MoonShineLayout extends CompactLayout{use HasRushNotifications;// ...}
FormPage
To display active users on the form page, attach the HasRushForm
trait to your resource:
use HasRushForm;
use HasRushForm;
FragmentReload
Enable fragment reloading on Alpine events:
FragmentWs::make([FlexibleRender::make("Test reload " . time()),])->name('metrics');
FragmentWs::make([FlexibleRender::make("Test reload " . time()),])->name('metrics');
Trigger a fragment reload from the server:
FragmentReload::send('metrics');
FragmentReload::send('metrics');
For private channels:
FragmentWs::make([FlexibleRender::make("Test reload " . time()),])->privateChannel()->name('metrics');// Sending event to a specific userFragmentReload::send('metrics', userId: 1);
FragmentWs::make([FlexibleRender::make("Test reload " . time()),])->privateChannel()->name('metrics');// Sending event to a specific userFragmentReload::send('metrics', userId: 1);
Configuration
The configuration file is located at config/moonshine_rush.php
. Key options include:
prefix
: Prefix for all channelsnotifications_channel
: Prefix for notification channelsnow_on_form_channel
: Prefix for form channelsfragment_reload_channel
: Prefix for fragment reload channels
Connection
Frontend
Initialize the connection after the moonshine:init
event:
document.addEventListener("moonshine:init", () => {// Your initialization code here})
document.addEventListener("moonshine:init", () => {// Your initialization code here})
Pass all channel events to the MoonShine.onCallback('onMoonShineWS')
function:
// Echo exampleMoonShine.onCallback('onMoonShineWS', function(channel, onPublic) {window.Echo.private(channel).listen('.moonshine.ws.event', (e) => {onPublic(e)}).subscribed(() => {document.dispatchEvent(new CustomEvent('rush-subscribe:' + channel))})})
// Echo exampleMoonShine.onCallback('onMoonShineWS', function(channel, onPublic) {window.Echo.private(channel).listen('.moonshine.ws.event', (e) => {onPublic(e)}).subscribed(() => {document.dispatchEvent(new CustomEvent('rush-subscribe:' + channel))})})
Trigger the moonshine:rush
event after connecting:
window.Echo.connector.pusher.connection.bind('connected', () => {document.dispatchEvent(new CustomEvent('moonshine:rush'))})
window.Echo.connector.pusher.connection.bind('connected', () => {document.dispatchEvent(new CustomEvent('moonshine:rush'))})
Backend
Implement the RushBroadcastContract
interface for server-side event sending:
final class SocketIO implements RushBroadcastContract{public function send(string $channel, RushData $rushData): void {// Your implementation here}}
final class SocketIO implements RushBroadcastContract{public function send(string $channel, RushData $rushData): void {// Your implementation here}}
Bind the implementation in your service provider:
$this->app->bind(RushBroadcastContract::class, SocketIO::class);
$this->app->bind(RushBroadcastContract::class, SocketIO::class);
License
Rush is a commercial software product distributed under a paid license. To use the package, you must purchase a license.
Purchasing a license
- Visit the official website moonshine-laravel.com.
- Make a payment through the available methods on the site.
- After successful payment, you will receive a personal license key.
Terms of Use
- The license is issued for one developer.
- The license gives the right to use the Rush package in commercial and non-commercial projects.
- Distribution or resale of the license key to third parties is strictly prohibited.
- Technical support and updates are provided in accordance with the terms of the purchased license.
For all questions related to licensing, please contact support: info@cutcode.dev