ElephantIO\Engine\SocketIO\Version1X::handshake PHP Method

handshake() protected method

Does the handshake with the Socket.io server and populates the session value object
protected handshake ( )
    protected function handshake()
    {
        if (null !== $this->session) {
            return;
        }
        $query = ['use_b64' => $this->options['use_b64'], 'EIO' => $this->options['version'], 'transport' => $this->options['transport']];
        if (isset($this->url['query'])) {
            $query = array_replace($query, $this->url['query']);
        }
        $context = $this->context;
        if (!isset($context[$this->url['secured'] ? 'ssl' : 'http'])) {
            $context[$this->url['secured'] ? 'ssl' : 'http'] = [];
        }
        $context[$this->url['secured'] ? 'ssl' : 'http']['timeout'] = (double) $this->options['timeout'];
        $url = sprintf('%s://%s:%d/%s/?%s', $this->url['scheme'], $this->url['host'], $this->url['port'], trim($this->url['path'], '/'), http_build_query($query));
        $result = @file_get_contents($url, false, stream_context_create($context));
        if (false === $result) {
            throw new ServerConnectionFailureException();
        }
        $decoded = json_decode(substr($result, strpos($result, '{')), true);
        if (!in_array('websocket', $decoded['upgrades'])) {
            throw new UnsupportedTransportException('websocket');
        }
        $cookies = [];
        foreach ($http_response_header as $header) {
            if (preg_match('/^Set-Cookie:\\s*([^;]*)/i', $header, $matches)) {
                $cookies[] = $matches[1];
            }
        }
        $this->cookies = $cookies;
        $this->session = new Session($decoded['sid'], $decoded['pingInterval'], $decoded['pingTimeout'], $decoded['upgrades']);
    }