Skip to content

RuslanMelnychenko/socket.io-php-emitter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ruslanmelnychenko/socket.io-php-emitter Build Status

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);

Credits

Watch all forks

About

PHP implementation of socket.io-emitter (PhpRedis)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%