Download the PHP package jacked-php/live-belt without Composer
On this page you can find all versions of the php package jacked-php/live-belt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package live-belt
Live Belt
Livewire Component for Real Time interactions using Laravel Conveyor Driver.
Video: https://www.youtube.com/watch?v=nQgMK2r_gww
Installation
Step 1: install package
Step 2: add service provider
Add the following to your bootstrap/providers.php
file:
`
Step 3: install dependencies for JS
Comment import './echo';
from resources/js/bootstrap.js
.
Then add this to your app.js
:
At this stage, be sure to follow the steps 1 to 5 at the Laravel Conveyor Driver documentation.
Step 4: adjust configuration
Add the following to your config/broadcasting.php
file:
Set the configurations for the WebSocket server in the .env
file:
Usage
First, check the Laravel Conveyor Driver documentation to set up your Laravel project.
Add this to your scripts area:
This example will write to your console log.
You can communicate with it using this example event:
Dispatch it like this and see the console log of your browser:
Events
In Live Belt, you can listen to conveyor events and send messages with them. As seen above in the "Usage" section, you can already send events leveraging the Laravel Broadcasting system. You can also broadcast from the front end!
Let's start by examining the cases of listening events in the backend and front end. Then, we will visit the case of triggering events from the front end.
Listening Live Belt events
To listen to events in the backend, you can just listen to the event \LiveBelt\Events\OnConveyorMessage
. That way, whenever you receive some event from Conveyor Server, you'll be able to react to it in the backend.
Here is an example:
In the front end, you can listen to events thrown in the window scope: onConveyorMessage
. Here is an example:
Triggering Live Belt events
To trigger events to Conveyor Server from the frontend, you just dispatch the event onConveyorMessageBroadcast
in the window scope. You must send the channel you want to send to and the message. Both fields are required. Here is an example:
Notes
- There will be logs in the browser console in case of errors (shown as warnings).