socket = $socketConnection; $this->proxyManager = $proxyManager; $this->socket->on('data', function ($data) { $jsonStrings = explode("||", $data); $decodedEntries = []; foreach ($jsonStrings as $jsonString) { try { $decodedJsonObject = json_decode($jsonString); if (is_object($decodedJsonObject)) { $decodedEntries[] = $decodedJsonObject; } } catch (Throwable $e) { // Ignore payload } } foreach ($decodedEntries as $decodedEntry) { if (method_exists($this, $decodedEntry->event ?? '')) { $this->socket->emit($decodedEntry->event, [$decodedEntry]); call_user_func([$this, $decodedEntry->event], $decodedEntry); } } }); } public function authenticated($data) { $this->socket->_id = $data->client_id; $this->createProxy($data); } public function createProxy($data) { $this->proxyManager->createProxy($this->socket, $data); } public function authenticate(string $sharedHost, string $subdomain) { $this->socket->write(json_encode([ 'event' => 'authenticate', 'data' => [ 'host' => $sharedHost, 'subdomain' => empty($subdomain) ? null : $subdomain, ], ])); } }