+ socket.on('error', onSocketError)
+ this.authenticate(req, err => {
+ if (err != null) {
+ socket.write(`HTTP/1.1 ${StatusCodes.UNAUTHORIZED} Unauthorized\r\n\r\n`)
+ socket.destroy()
+ return
+ }
+ try {
+ this.webSocketServer.handleUpgrade(req, socket, head, (ws: WebSocket) => {
+ this.webSocketServer.emit('connection', ws, req)
+ })
+ } catch (error) {
+ logger.error(
+ `${this.logPrefix(
+ moduleName,
+ 'start.httpServer.on.upgrade'
+ )} Error at connection upgrade event handling:`,
+ error
+ )
+ }
+ })
+ socket.removeListener('error', onSocketError)
+ })
+ this.startHttpServer()