protected function addStream(WebSocketTransportInterface $user, $id, \React\Stream\Stream $stream) { $this->streams[$user->getId()][$id] = $stream; }
public function onMessage(WebSocketTransportInterface $user, WebSocketMessageInterface $msg) { //do nothing $this->logger->notice("User {$user->getId()} is not in a room but tried to say: {$msg->getData()}"); }
public function onMessage(WebSocketTransportInterface $user, WebSocketMessageInterface $msg) { //do nothing $this->logger->notice("Client is talking to the wind. ({$msg->getData()}, {$user->getId()})"); }
/** * Clean up after users who leave. * * @param WebSocketTransportInterface $user */ public function onDisconnect(WebSocketTransportInterface $user) { $this->logger->notice("Client skedaddled. ({$user->getId()})"); $mess = 0; foreach ($this->subscriptions['queries'] as $curQuery => &$curClients) { foreach ($curClients as $key => $curClient) { if ($key === 'current') { continue; } if ($user->getId() === $curClient['client']->getId()) { unset($curClients[$key]); if (RequirePHP::_('NymphPubSubConfig')['broadcast_counts']) { // Notify clients of the subscription count. $count = count($curClients) - 1; foreach ($curClients as $key => $curCountClient) { if ($key === 'current') { continue; } if ($curCountClient['count']) { $curCountClient['client']->sendString(json_encode(['query' => $curCountClient['query'], 'count' => $count])); } } } if (count($curClients) === 1) { unset($this->subscriptions['queries'][$curQuery]); } $mess++; } } } unset($curClients); foreach ($this->subscriptions['uids'] as $curUID => &$curClients) { foreach ($curClients as $key => $curClient) { if ($user->getId() === $curClient['client']->getId()) { unset($curClients[$key]); if (RequirePHP::_('NymphPubSubConfig')['broadcast_counts']) { // Notify clients of the subscription count. $count = count($curClients); foreach ($curClients as $curCountClient) { if ($curCountClient['count']) { $curCountClient['client']->sendString(json_encode(['uid' => $curUID, 'count' => $count])); } } } if (count($curClients) === 0) { unset($this->subscriptions['uids'][$curUID]); } $mess++; } } } unset($curClients); if ($mess) { $this->logger->notice("Cleaned up client's mess. ({$mess}, {$user->getId()})"); } }