2017 © Pedro Peláez
 

library socketio-redis-adapter

image

valeriitropin/socketio-redis-adapter

  • Monday, December 18, 2017
  • by valeriitropin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PHP socket.io redis adapter

Partial port of socket.io redis adapter, async, allows to get clients/rooms and to manage them. The main goal of this project is possibility to communicate between php and socket.io applications. Built on top of ReactPHP components., (*1)

Installation

composer require valeriitropin/socketio-redis-adapter

How to use

use React\EventLoop\Factory as ReactFactory;
use ValeriiTropin\Socketio\RedisAdapter;
use Clue\React\Block;
use React\Promise;

$loop = ReactFactory::create();
$client = new RedisAdapter($loop);

$promise = $client->allRooms()->then(function ($rooms) use ($client) {
    $promises = [];
    foreach ($rooms as $room) {
        $promises[] = $client->clients([$room])->then(function ($clients) use ($room) {
            foreach ($clients as $client) {
                echo $room . ' ' . $client . "\n";
            }
        });
    }
    return Promise\all($promises);
})->otherwise(function ($error) {
    echo ($error->getMessage()) . "\n";
});

Block\await($promise, $loop);

API

RedisAdapter

__construct(React\EventLoop\LoopInterface $loop, $options = [])

$options:
  • prefix: pub/sub events prefix (socket.io)
  • requestsTimeout: timeout in milliseconds, float (5)
  • namespace: socket.io namespace (/)
  • pubClient: pub client
  • subClient: pub client
  • customHook: callable
  • uri: Redis connection string, see docs (localhost)

clients($rooms = []): React\Promise\Promise

Returns the list of client IDs connected to rooms across all nodes., (*2)

$adapter->clients($rooms)
    ->then(function ($clients) {
        var_dump($clients);
    })
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

clientRooms($id): React\Promise\Promise

Returns the list of rooms the client with the given ID has joined (even on another node)., (*3)

$adapter->clients($id)
    ->then(function ($rooms) {
        var_dump($rooms);
    })
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

allRooms(): React\Promise\Promise

Returns the list of all rooms from all nodes., (*4)

$adapter->allRooms()
    ->then(function ($allRooms) {
        var_dump($allRooms);
    })
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

remoteJoin($id, $room): React\Promise\Promise

$adapter->remoteJoin($id, $room)
    ->then(function () {})
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

remoteLeave($id, $room): React\Promise\Promise

$adapter->remoteLeave($id, $room)
    ->then(function () {})
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

remoteDisconnect($id, $close): React\Promise\Promise

$adapter->remoteDisconnect($id, $close)
    ->then(function () {})
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

customRequest($data): React\Promise\Promise

Sends a request to every nodes, that will respond through the customHook method., (*5)

$adapter->customRequest($data)
    ->then(function ($replies) {})
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

getLoop(): React\EventLoop\LoopInterface

Returns loop instance., (*6)

getPub(): Clue\React\Redis\StreamingClient

Returns pub client., (*7)

getSub(): Clue\React\Redis\StreamingClient

Returns sub client., (*8)

unsubscribeFromRequestChannel(): React\Promise\Promise

Unsubscribes the adapter instance from request channel., (*9)

The Versions

18/12 2017

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

by Valerii Tropin

redis adapter socket.io

18/12 2017

1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

by Valerii Tropin

redis adapter socket.io