p-sam / real-time-bundle
从服务器到浏览器和移动设备的实时事件
1.3.0
2020-03-25 13:52 UTC
Requires
- php: ^7.2
- ext-json: *
- ably/ably-php: ^1.0
- predis/predis: ^1.1
- ramsey/uuid: ^3.0|^4.0
- symfony/config: ^4.4|^5.0
- symfony/event-dispatcher: ^4.4|^5.0
- symfony/framework-bundle: ^4.4|^5.0
Requires (Dev)
- symfony/console: ^4.4|^5.0
Suggests
- symfony/console: If you want to use commands to interact with any channel
README
通过 "通道" 从服务器到浏览器和移动设备的实时事件
请注意,此包使用了 ably.io 和 Redis 通过 Predis。
安装
使用composer安装
$ composer require p-sam/real-time-bundle
然后在 AppKernel.php
文件中注册该包
public function registerBundles() { $bundles = array( // ... new SP\RealTimeBundle\SPRealTimeBundle(), // ... ); return $bundles; }
然后在您的 routing.yml
中添加以下内容
sp_realtime: resource: "@SPRealTimeBundle/Controller/" type: annotation
注意:如果您使用Symfony Flex,则自动完成包和路由的注册
配置
在您的 config.yml
中配置 predis
客户端和 ably
密钥
sp_realtime: ably: api_key: '- ably key here -' ttl: 3600 # in seconds redis: key_prefix: 'app:' presence_check: true
用法
从PHP
该包提供了一些服务
sp_real_time.sender
: 允许向通道发送消息sp_real_time.presence
: 允许通过提供令牌进行订阅,并在通道中检查存在性
以下事件将被触发
sp_real_time.event.subscribe
: 当为通道生成令牌时,将发出SubscribeEvent
sp_real_time.event.message
: 当消息向上游发送到 ably.io 时,将发出MessageEvent