| 484 | } |
| 485 | |
| 486 | private _tryUpgrade( |
| 487 | transport: Transport, |
| 488 | onSuccess: () => void, |
| 489 | onError: () => void, |
| 490 | ) { |
| 491 | debug(class="st">"starting upgrade process"); |
| 492 | |
| 493 | const upgradeTimeoutTimer = setTimeout(() => { |
| 494 | debug(class="st">"client did not complete upgrade - closing transport"); |
| 495 | transport.close(); |
| 496 | transport.removeAllListeners(); |
| 497 | onError(); |
| 498 | }, this.opts.upgradeTimeout); |
| 499 | |
| 500 | transport.on(class="st">"packet", (packet) => { |
| 501 | if (packet.type === class="st">"ping" && packet.data === class="st">"probe") { |
| 502 | debug(class="st">"got probe ping packet, sending pong"); |
| 503 | transport.send([{ type: class="st">"pong", data: class="st">"probe" }]); |
| 504 | } else if (packet.type === class="st">"upgrade") { |
| 505 | clearTimeout(upgradeTimeoutTimer); |
| 506 | transport.removeAllListeners(); |
| 507 | onSuccess(); |
| 508 | } else { |
| 509 | transport.removeAllListeners(); |
| 510 | transport.close(); |
| 511 | onError(); |
| 512 | } |
| 513 | }); |
| 514 | |
| 515 | transport.on(class="st">"error", () => { |
| 516 | transport.removeAllListeners(); |
| 517 | onError(); |
| 518 | }); |
| 519 | |
| 520 | transport.on(class="st">"close", () => { |
| 521 | transport.removeAllListeners(); |
| 522 | onError(); |
| 523 | }); |
| 524 | } |
| 525 | |
| 526 | private _onPacket(sid: SessionId, senderId: NodeId, packet: Packet) { |
| 527 | this.publishMessage({ |