public function handleWsClose($op, $reason)
    {
        $this->connected = false;

        if (! is_null($this->heartbeatTimer)) {
            $this->heartbeatTimer->cancel();
            $this->heartbeatTimer = null;
        }

        if (! is_null($this->heartbeatAckTimer)) {
            $this->heartbeatAckTimer->cancel();
            $this->heartbeatAckTimer = null;
        }

        if ($this->closing) {
            return;
        }

        $this->logger->warning('websocket closed', ['op' => $op, 'reason' => $reason]);

        if ($op == Op::CLOSE_INVALID_TOKEN) {
            $this->emit('error', ['token is invalid', $this]);
            $this->logger->error('the token you provided is invalid');

            return;
        }

        ++$this->reconnectCount;
        $this->reconnecting = true;
        $this->logger->info('starting reconnect', ['reconnect_count' => $this->reconnectCount]);
        $this->connectWs();
    }