* Handshakes a new client. * * @param {String} transportName * @param {Object} req - the request object * @param {Function} closeConnection * * @protected
(
transportName: TransportName,
req: EngineRequest,
closeConnection: ErrorCallback,
)
| 433 | * @protected |
| 434 | */ |
| 435 | protected async handshake( |
| 436 | transportName: TransportName, |
| 437 | req: EngineRequest, |
| 438 | closeConnection: ErrorCallback, |
| 439 | ) { |
| 440 | const protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default |
| 441 | if (protocol === 3 && !this.opts.allowEIO3) { |
| 442 | debug("unsupported protocol version"); |
| 443 | this.emit("connection_error", { |
| 444 | req, |
| 445 | code: Server.errors.UNSUPPORTED_PROTOCOL_VERSION, |
| 446 | message: |
| 447 | Server.errorMessages[Server.errors.UNSUPPORTED_PROTOCOL_VERSION], |
| 448 | context: { |
| 449 | protocol, |
| 450 | }, |
| 451 | }); |
| 452 | closeConnection(Server.errors.UNSUPPORTED_PROTOCOL_VERSION); |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | let id; |
| 457 | try { |
| 458 | id = await this.generateId(req); |
| 459 | } catch (e) { |
| 460 | debug("error while generating an id"); |
| 461 | this.emit("connection_error", { |
| 462 | req, |
| 463 | code: Server.errors.BAD_REQUEST, |
| 464 | message: Server.errorMessages[Server.errors.BAD_REQUEST], |
| 465 | context: { |
| 466 | name: "ID_GENERATION_ERROR", |
| 467 | error: e, |
| 468 | }, |
| 469 | }); |
| 470 | closeConnection(Server.errors.BAD_REQUEST); |
| 471 | return; |
| 472 | } |
| 473 | |
| 474 | debug('handshaking client "%s"', id); |
| 475 | |
| 476 | try { |
| 477 | var transport = this.createTransport(transportName, req); |
| 478 | if ("polling" === transportName) { |
| 479 | transport.maxHttpBufferSize = this.opts.maxHttpBufferSize; |
| 480 | transport.httpCompression = this.opts.httpCompression; |
| 481 | } else if ("websocket" === transportName) { |
| 482 | transport.perMessageDeflate = this.opts.perMessageDeflate; |
| 483 | } |
| 484 | } catch (e) { |
| 485 | debug('error handshaking to transport "%s"', transportName); |
| 486 | this.emit("connection_error", { |
| 487 | req, |
| 488 | code: Server.errors.BAD_REQUEST, |
| 489 | message: Server.errorMessages[Server.errors.BAD_REQUEST], |
| 490 | context: { |
| 491 | name: "TRANSPORT_HANDSHAKE_ERROR", |
| 492 | error: e, |
nothing calls this directly
no test coverage detected