<?php
class WebSocketTest extends AppInstance {
public $sessions = array();
public function onReady() {
if ($this->config->enable->value) {
$this->WS = Daemon::$appResolver->getInstanceByAppName('WebSocketServer');
if ($this->WS) {
$this->WS->routes['exampleApp'] = array($this, 'onHandShake');
}
}
}
public function onHandShake($client) {
return $this->sessions[$client->connId] = new ChatSession($client, $this);
}
}
class ChatSession {
public $client;
public $appInstance;
public function __construct($client, $appInstance) {
$this->client = $client;
$this->appInstance = $appInstance;
}
public function onFrame($data, $type) {
$this->appInstance->sessions[2]->client->sendFrame($data);
$this->client->sendFrame(implode(' ', array_keys($this->appInstance->sessions)));
}
public function gracefulShutdown() {
return true;
}
}