completeUpgrade(key, extensions, req, socket, head, cb) {
        //
        // Destroy the socket if the client has already sent a FIN packet.
        //
        if (!socket.readable || !socket.writable) return socket.destroy();
        if (socket[$d11422b22cc93234$require$kWebSocket]) throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");
        if (this._state > $d11422b22cc93234$var$RUNNING) return $d11422b22cc93234$var$abortHandshake(socket, 503);
        const digest = $d11422b22cc93234$require$createHash('sha1').update(key + $d11422b22cc93234$require$GUID).digest('base64');
        const headers = [
            'HTTP/1.1 101 Switching Protocols',
            'Upgrade: websocket',
            'Connection: Upgrade',
            `Sec-WebSocket-Accept: ${digest}`
        ];
        const ws = new $bb7af8e8d7184be0$exports(null);
        let protocol = req.headers['sec-websocket-protocol'];
        if (protocol) {
            protocol = protocol.split(',').map($d11422b22cc93234$var$trim);
            //
            // Optionally call external protocol selection handler.
            //
            if (this.options.handleProtocols) protocol = this.options.handleProtocols(protocol, req);
            else protocol = protocol[0];
            if (protocol) {
                headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
                ws._protocol = protocol;
            }
        }
        if (extensions[$a3204058aeffecb3$exports.extensionName]) {
            const params = extensions[$a3204058aeffecb3$exports.extensionName].params;
            const value = $d11422b22cc93234$require$format({
                [$a3204058aeffecb3$exports.extensionName]: [
                    params
                ]
            });
            headers.push(`Sec-WebSocket-Extensions: ${value}`);
            ws._extensions = extensions;
        }
        //
        // Allow external modification/inspection of handshake headers.
        //
        this.emit('headers', headers, req);
        socket.write(headers.concat('\r\n').join('\r\n'));
        socket.removeListener('error', $d11422b22cc93234$var$socketOnError);
        ws.setSocket(socket, head, this.options.maxPayload);
        if (this.clients) {
            this.clients.add(ws);
            ws.on('close', ()=>this.clients.delete(ws)
            );
        }
        cb(ws, req);
    }
/**
   * Upgrade the connection to WebSocket.
   *
   * @param {String} key The value of the `Sec-WebSocket-Key` header
   * @param {Object} extensions The accepted extensions
   * @param {http.IncomingMessage} req The request object
   * @param {(net.Socket|tls.Socket)} socket The network socket between the
   *     server and client
   * @param {Buffer} head The first packet of the upgraded stream
   * @param {Function} cb Callback
   * @throws {Error} If called more than once with the same socket
   * @private
   */
Upgrade the connection to WebSocket.
Upgrade the connection to WebSocket .
completeUpgrade(key, extensions, req, socket, head, cb) {
         Destroy the socket if the client has already sent a FIN packet.
        if (!socket.readable || !socket.writable) return socket.destroy();
        if (socket[$d11422b22cc93234$require$kWebSocket]) throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");
        if (this._state > $d11422b22cc93234$var$RUNNING) return $d11422b22cc93234$var$abortHandshake(socket, 503);
        const digest = $d11422b22cc93234$require$createHash('sha1').update(key + $d11422b22cc93234$require$GUID).digest('base64');
        const headers = [
            'HTTP/1.1 101 Switching Protocols',
            'Upgrade: websocket',
            'Connection: Upgrade',
            `Sec-WebSocket-Accept: ${digest}`
        ];
        const ws = new $bb7af8e8d7184be0$exports(null);
        let protocol = req.headers['sec-websocket-protocol'];
        if (protocol) {
            protocol = protocol.split(',').map($d11422b22cc93234$var$trim);
             Optionally call external protocol selection handler.
            if (this.options.handleProtocols) protocol = this.options.handleProtocols(protocol, req);
            else protocol = protocol[0];
            if (protocol) {
                headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
                ws._protocol = protocol;
            }
        }
        if (extensions[$a3204058aeffecb3$exports.extensionName]) {
            const params = extensions[$a3204058aeffecb3$exports.extensionName].params;
            const value = $d11422b22cc93234$require$format({
                [$a3204058aeffecb3$exports.extensionName]: [
                    params
                ]
            });
            headers.push(`Sec-WebSocket-Extensions: ${value}`);
            ws._extensions = extensions;
        }
         Allow external modification/inspection of handshake headers.
        this.emit('headers', headers, req);
        socket.write(headers.concat('\r\n').join('\r\n'));
        socket.removeListener('error', $d11422b22cc93234$var$socketOnError);
        ws.setSocket(socket, head, this.options.maxPayload);
        if (this.clients) {
            this.clients.add(ws);
            ws.on('close', ()=>this.clients.delete(ws)
            );
        }
        cb(ws, req);
    }
completeUpgrade ( key , extensions , req , socket , head , cb ) { if ( ! socket . readable || ! socket . writable ) return socket . destroy ( ) ; if ( socket [ $d11422b22cc93234$require$kWebSocket ] ) throw new Error ( "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration" ) ; if ( this . _state > $d11422b22cc93234$var$RUNNING ) return $d11422b22cc93234$var$abortHandshake ( socket , 503 ) ; const digest = $d11422b22cc93234$require$createHash ( 'sha1' ) . update ( key + $d11422b22cc93234$require$GUID ) . digest ( 'base64' ) ; const headers = [ 'HTTP/1.1 101 Switching Protocols' , 'Upgrade: websocket' , 'Connection: Upgrade' , ` ${ digest } ` ] ; const ws = new $bb7af8e8d7184be0$exports ( null ) ; let protocol = req . headers [ 'sec-websocket-protocol' ] ; if ( protocol ) { protocol = protocol . split ( ',' ) . map ( $d11422b22cc93234$var$trim ) ; if ( this . options . handleProtocols ) protocol = this . options . handleProtocols ( protocol , req ) ; else protocol = protocol [ 0 ] ; if ( protocol ) { headers . push ( ` ${ protocol } ` ) ; ws . _protocol = protocol ; } } if ( extensions [ $a3204058aeffecb3$exports . extensionName ] ) { const params = extensions [ $a3204058aeffecb3$exports . extensionName ] . params ; const value = $d11422b22cc93234$require$format ( { [ $a3204058aeffecb3$exports . extensionName ] : [ params ] } ) ; headers . push ( ` ${ value } ` ) ; ws . _extensions = extensions ; } this . emit ( 'headers' , headers , req ) ; socket . write ( headers . concat ( '\r\n' ) . join ( '\r\n' ) ) ; socket . removeListener ( 'error' , $d11422b22cc93234$var$socketOnError ) ; ws . setSocket ( socket , head , this . options . maxPayload ) ; if ( this . clients ) { this . clients . add ( ws ) ; ws . on ( 'close' , ( ) => this . clients . delete ( ws ) ) ; } cb ( ws , req ) ; }
Upgrade the connection to WebSocket.
Upgrade the connection to WebSocket .
// // Destroy the socket if the client has already sent a FIN packet. // // // Optionally call external protocol selection handler. // // // Allow external modification/inspection of handshake headers. //