ruslanmelnychenko / socket.io-php-emitter
PHP socket.io event emitter (PhpRedis)
1.0.0
2022-05-22 14:32 UTC
Requires
- php: ^7.1.1|^8
- ext-json: *
- ext-redis: *
- rybakit/msgpack: ^0.7.1
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^5.0
This package is not auto-updated.
Last update: 2025-03-25 02:38:11 UTC
README
A PHP implementation of node.js socket.io-emitter. Use PhpRedis client.
Installation
composer require ruslanmelnychenko/socket.io-php-emitter
Usage
Emit payload message
use RuslanMelnychenko\SocketIO\Emitter; ... $client = new \Redis(); (new Emitter($client)) ->of('namespace')->emit('event', 'payload message');
Flags
Possible flags
- json
- volatile
- broadcast
To use flags, just call it like in examples bellow
use RuslanMelnychenko\SocketIO\Emitter; ... $client = new \Redis(); $client->connect('127.0.0.1'); (new Emitter($client)) ->broadcast->emit('broadcast-event', 'payload message'); (new Emitter($client)) ->flag('broadcast')->emit('broadcast-event', 'payload message');
Emit an object
use RuslanMelnychenko\SocketIO\Emitter; ... $client = new \Redis(); $client->connect('127.0.0.1'); (new Emitter($client)) ->emit('broadcast-event', ['param1' => 'value1', 'param2' => 'value2', ]);
Emit an object in multiple rooms
use RuslanMelnychenko\SocketIO\Emitter; ... $client = new \Redis(); $client->connect('127.0.0.1'); (new Emitter($client)) ->in(['room1', 'room2']) ->emit('broadcast-event', ['param1' => 'value1', 'param2' => 'value2', ]);
Emit an object in multiple rooms with except rooms
use RuslanMelnychenko\SocketIO\Emitter; ... $client = new \Redis(); $client->connect('127.0.0.1'); (new Emitter($client)) ->in(['room1', 'room2']) ->except(['room3']) ->emit('broadcast-event', ['param1' => 'value1', 'param2' => 'value2', ]);
Send remote commands
use RuslanMelnychenko\SocketIO\Emitter; ... $client = new \Redis(); $client->connect('127.0.0.1'); (new Emitter($client)) ->in(['room1', 'room2']) ->except(['room3']) ->socketsJoin('room4'); (new Emitter($client)) ->in(['room4']) ->socketsLeave('room3'); (new Emitter($client)) ->in(['room1']) ->disconnectSockets(); (new Emitter($client)) ->of('/tasks') ->serverSideEmit('taskDone', 1);