supportpal / pollcast
Laravel 广播驱动程序,适用于受限的托管环境。
v1.2.3
2024-03-11 14:46 UTC
Requires
- php: ^8.1
- ext-json: *
- goldspecdigital/laravel-eloquent-uuid: ^10.0
- illuminate/broadcasting: ^10.0
- illuminate/database: ^10.0
- illuminate/http: ^10.0
- illuminate/session: ^10.0
- illuminate/support: ^10.0
Requires (Dev)
- graham-campbell/testbench: ^6.0
- nunomaduro/larastan: 2.9.2
- phpstan/phpstan-mockery: 1.1.2
- phpunit/phpunit: ^10.0
- rregeer/phpunit-coverage-check: ^0.3.1
- supportpal/coding-standard: 0.4.4
This package is auto-updated.
Last update: 2024-09-10 00:51:22 UTC
README
Pollcast. 使用短轮询的 Laravel 广播驱动程序。
Pollcast
"Pollcast" 是指使用 Laravel 广播的 XHR 轮询。
动机
Laravel 支持多个广播驱动程序,但所有这些都需要与第三方服务(如 Pusher)集成或安装额外的软件。这个包背后的动机是提供一个无需额外配置即可在所有环境中工作并与 Laravel Echo 兼容的广播驱动程序。
在大多数情况下,如果您控制环境,您会想要使用 WebSocket。
安装
使用 Composer 安装此包
composer require supportpal/pollcast
将 ServiceProvider 类添加到 config/app.php
文件中的 providers
数组。在 Laravel 5.5 及以上版本中,如果启用了包自动发现,则可以跳过此步骤。
\SupportPal\Pollcast\ServiceProvider::class,
在 .env
文件中更改默认广播驱动程序
BROADCAST_DRIVER=pollcast
添加数据库表
php artisan migrate --path=vendor/supportpal/pollcast/database/migrations
最后,如果需要,发布配置文件 config/pollcast.php
php artisan vendor:publish --provider="SupportPal\Pollcast\ServiceProvider"
用法
要求 pollcast-js 包
npm i --save pollcast-js laravel-echo
创建一个新的 Laravel Echo
实例,并使用 PollcastConnector
作为广播器
import Echo from 'laravel-echo'; import PollcastConnector from 'pollcast-js' window.Echo = new Echo({ broadcaster: PollcastConnector, csrfToken: "{{ csrf_token() }}", routes: { connect: "{{ route('supportpal.pollcast.connect') }}", receive: "{{ route('supportpal.pollcast.receive') }}", publish: "{{ route('supportpal.pollcast.publish') }}", subscribe: "{{ route('supportpal.pollcast.subscribe') }}", unsubscribe: "{{ route('supportpal.pollcast.unsubscribe') }}" }, polling: {{ Config.get('pollcast.polling_interval', 5000) }} });