Download the PHP package mvanduijker/laravel-mercure-broadcaster without Composer
On this page you can find all versions of the php package mvanduijker/laravel-mercure-broadcaster. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mvanduijker/laravel-mercure-broadcaster
More information about mvanduijker/laravel-mercure-broadcaster
Files in mvanduijker/laravel-mercure-broadcaster
Package laravel-mercure-broadcaster
Short Description Mercure broadcaster
License MIT
Homepage https://github.com/mvanduijker/laravel-mercure-broadcaster
Informations about the package laravel-mercure-broadcaster
Laravel Mercure Broadcaster
Laravel broadcaster for Mercure for doing Server Sent Events in a breeze.
Installation
Make sure you have installed Mercure and have it running. Check their docs how to do it. (It's pretty easy)
Configure laravel to use the Mercure broadcaster by editing config/broadcasting.php
for example:
Usage
Add an event which implements ShouldBroadcast interface like in https://laravel.com/docs/master/broadcasting#defining-broadcast-events
In your frontend do something like:
Private channels go a bit differently than with broadcasting through sockets. Private channels are baked in Mercure and are secured with a jwt token.
First create a http middleware, so we can generate the Mercure authentication cookie with the token. Don't forget to add the middleware to your route!
Example:
Because Laravel encrypts and decrypts cookies by default, don't forget to add an exception for the mercureAuthorization
cookie in App\Http\Middleware\EncryptCookies
.
Example event:
Example Frontend:
Advanced usage
If you want to generate your own JWT, you can do it by overriding the mvanduijker.mercure_broadcaster.publisher_jwt
service.
You want to do this if you want to have custom claims, using other signing algorithms, etc. It expects a string back containing the JWT.
Example how the default JWT is generated: https://github.com/mvanduijker/laravel-mercure-broadcaster/blob/master/src/LaravelMercureBroadcasterServiceProvider.php#L32
Make sure you also make the changes in the cookie middleware.
Further reading
Make sure you read the documentation of Mercure and how to run it securely (behind https).
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
- Mark van Duijker
- Kévin Dunglas
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-mercure-broadcaster with dependencies
illuminate/broadcasting Version ~6.0|~7.0|~8.0|~9.0|~10.0|~11.0
lcobucci/jwt Version ~4.0
symfony/mercure Version ~0.4