websockets in faces3.php

This commit is contained in:
Ruben 2016-11-01 22:42:45 +01:00
parent 7e53e1666a
commit be6bec92c0
1 changed files with 8 additions and 4 deletions

View File

@ -31,10 +31,14 @@ class Websockets implements MessageComponentInterface
echo sprintf('Connection %d sending message "%s"' . "\n"
, $from->resourceId, $msg);
foreach ($this->clients as $client) {
if ($from !== $client) {
// The sender is not the receiver, send to each client connected
$client->send("update");
$data = @json_decode($msg);
if(!empty($data) && $data['action'] == 'update' && isset($data['method']))
{
foreach ($this->clients as $client) {
if ($from !== $client) {
// The sender is not the receiver, send to each client connected
$client->send(json_encode(['action'=>"update", 'method'=>$data['method']]));
}
}
}
}