valeriitropin/socketio-emitter

1.0.0 2017-12-18 20:47 UTC

This package is not auto-updated.

Last update: 2022-08-06 17:15:53 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.

Links