valeriitropin / socketio-emitter
1.0.0
2017-12-18 20:47 UTC
Requires
- clue/block-react: ^1.2
- clue/redis-react: ^2.1
- rybakit/msgpack: ^0.2.2
This package is not auto-updated.
Last update: 2025-03-30 07:56:39 UTC
README
Async implementation of socket.io emitter written in php. Built on top of ReactPHP components.
Installation
composer require valeriitropin/socketio-emitter
How to use
use React\EventLoop\Factory as ReactFactory; use ValeriiTropin\Socketio\Emitter; $loop = ReactFactory::create(); $emitter = new Emitter($loop); $promise = $emitter->to($room)->emit($event, $data) ->then(function () {}) ->otherwise(function ($error) {});
API
Emitter
__construct(React\EventLoop\LoopInterface $loop, $options = [], ValeriiTropin\Socketio\PackerInterface $packer = null)
$options:
key
: pub/sub events prefix (socket.io
)namespace
: socket.io namespace (/
)uri
: Redis connection string, see docs (localhost
)client
: pub client
to($room): ValeriiTropin\Socketio\Emitter
Adds room and returns current Emitter
instance
$emitter->to($room);
of($namespace): ValeriiTropin\Socketio\Emitter
Creates new Emitter
instance with given namespace.
$emitter->of($namespace);
emit($event, ...$args): React\Promise\Promise
Emits event with data to set rooms.
$emitter->emit($event, $data) ->then(function () {}) ->otherwise(function ($error) {});
getLoop(): React\EventLoop\LoopInterface
Returns loop instance.