@crustum/laravel-echo-mercure
v1.0.0
Published
Mercure connector for Laravel Echo - Server-Sent Events (SSE) implementation
Maintainers
Readme
@crustum/laravel-echo-mercure
Mercure connector for Laravel Echo - Server-Sent Events (SSE) implementation compatible with Laravel Echo API.
Installation
npm install @crustum/laravel-echo-mercureUsage
With Laravel Echo
import Echo from 'laravel-echo';
import { MercureConnector } from '@crustum/laravel-echo-mercure';
window.Echo = new Echo({
broadcaster: MercureConnector,
mercureUrl: '/.well-known/mercure',
authEndpoint: '/broadcasting/auth',
});Standalone Usage
import { MercureConnector } from '@crustum/laravel-echo-mercure';
const connector = new MercureConnector({
mercureUrl: '/.well-known/mercure',
authEndpoint: '/broadcasting/auth',
});
const channel = connector.privateChannel('App.Model.Entity.User.123');
channel.listen('PostUpdated', (data) => {
console.log('Post updated:', data);
});Browser Build
For browser usage without a bundler:
<script src="node_modules/@crustum/laravel-echo-mercure/dist/index.umd.js"></script>
<script>
const connector = new MercureConnector({
mercureUrl: '/.well-known/mercure',
authEndpoint: '/broadcasting/auth',
});
</script>Features
- Compatible with Laravel Echo API
- Server-Sent Events (SSE) via Mercure Hub
- Channel batching for efficient connections
- Private channel support with JWT authentication
- Automatic channel routing
- Event listener management
Configuration Options
mercureUrl- Mercure Hub URL (default:'/.well-known/mercure')authEndpoint- Authentication endpoint for JWT tokens (default:'/broadcasting/auth')namespace- Event namespace (default:'App.Events')
License
MIT
