/** * @see Wrench\Application.Application::onData() */ public function onData($data, $client) { try { $command = Protocol::fromString((string) $data); } catch (Exception $e) { $this->log($e, 'err', $client); return; } if (!$command) { $this->log('No command', 'err', $client); return; } list($type, $topic, $payload) = $command; switch ($type) { case Protocol::TYPE_SUBSCRIBE: $this->log('Client asked to be subscribed to ' . $topic, 'info'); $this->getChannel($topic)->subscribeClient($client); return; case Protocol::TYPE_MESSAGE: if (!$payload) { $this->log('No payload', $client); return; } $this->log('Received message on ' . $topic . ': ' . $payload, 'info'); $this->getChannel($topic)->receive($payload, $client); return; case Protocol::TYPE_UNSUBSCRIBE: $this->log('Client asked to be unsubscribed from ' . $topic, 'info'); $this->getChannel($topic)->unsubscribeClient($client); return; default: $this->log('Unknown type: ' . $type, 'err', $client); break; } }