serenade/live
Composer 安装命令:
composer require serenade/live
包简介
Server-Sent Events
README 文档
README
Serenade is a Laravel package for easily adding Server-Sent Events to your application. With Serenade, you can quickly and easily stream updates and events in real-time to your users, without the need for additional libraries or external dependencies.
Features
- Simple and easy API for creating and streaming events.
- Compatible with any modern browser that supports Server-Sent Events.
- Full support for Laravel's built-in queuing system for efficient event broadcasting.
- Easily integrate events with Laravel's authentication system.
- Simple configuration and setup for easy integration into your existing Laravel application.
Installation
To install Serenade, simply use Composer:
composer require esplora/serenade
Usage
Using Serenade is simple and intuitive. Here's an example of how to send a simple event:
//...
Configure
All of your application's event broadcasting configuration is stored in the config/broadcasting.php configuration file.
Add the following lines accordingly:
/* |-------------------------------------------------------------------------- | Broadcast Connections |-------------------------------------------------------------------------- | | Here you may define all of the broadcast connections that will be used | to broadcast events to other systems or over websockets. Samples of | each available type of connection are provided inside this array. | */ 'connections' => [ 'serenade' => [ 'domain' => '', 'prefix' => '', 'route' => 'serenade', 'middleware' => 'web', ], ],
Subscribing
Subscribing to updates from a web browser or any other platform supporting Server-Sent Events is straightforward:
const url = new URL('https://localhost/.well-known/serenade/your.channel'); const eventSource = new EventSource(url); // The callback will be called every time an update is published eventSource.onmessage = e => console.log(e); // do something with the payload
This will create a new event with the name example and the message Hello, World!. For more advanced usage, including authorization and queuing, see the official documentation.
License
Serenade is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 1.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-12