dev-master
9999999-dev
MIT
The Requires
by Valerii Tropin
redis adapter socket.io
1.0.0
1.0.0.0
MIT
The Requires
by Valerii Tropin
redis adapter socket.io
Wallogit.com
2017 © Pedro Peláez
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)
composer require valeriitropin/socketio-redis-adapter
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);
prefix: pub/sub events prefix (socket.io)requestsTimeout: timeout in milliseconds, float (5)namespace: socket.io namespace (/)pubClient: pub clientsubClient: pub clientcustomHook: callableuri: Redis connection string, see docs (localhost)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";
});
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";
});
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";
});
$adapter->remoteJoin($id, $room)
->then(function () {})
->otherwise(function ($error) {
echo ($error->getMessage()) . "\n";
});
$adapter->remoteLeave($id, $room)
->then(function () {})
->otherwise(function ($error) {
echo ($error->getMessage()) . "\n";
});
$adapter->remoteDisconnect($id, $close)
->then(function () {})
->otherwise(function ($error) {
echo ($error->getMessage()) . "\n";
});
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";
});
Returns loop instance., (*6)
Returns pub client., (*7)
Returns sub client., (*8)
Unsubscribes the adapter instance from request channel., (*9)
MIT
redis adapter socket.io
MIT
redis adapter socket.io