sperrichon / 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
This package is not auto-updated.
Last update: 2024-09-29 05:01:48 UTC
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:当为通道生成令牌时,会发出SubscribeEventsp_real_time.event.message:当向上游发送到ably.io的消息时,会发出MessageEvent