(message: unknown, generation: number)
| 702 | } |
| 703 | |
| 704 | private async handleWsMessage(message: unknown, generation: number) { |
| 705 | if (generation !== this.connectionGeneration) return; |
| 706 | this.stallWatchdog.recordInbound(); |
| 707 | |
| 708 | if ( |
| 709 | typeof message === "object" && |
| 710 | message !== null && |
| 711 | "type" in message && |
| 712 | message.type === "Close" |
| 713 | ) { |
| 714 | this.resetConnection(new Error("Relay connection closed.")); |
| 715 | return; |
| 716 | } |
| 717 | |
| 718 | if ( |
| 719 | typeof message === "object" && |
| 720 | message !== null && |
| 721 | "type" in message && |
| 722 | message.type === "Error" |
| 723 | ) { |
| 724 | this.resetConnection(new Error("Relay connection errored.")); |
| 725 | return; |
| 726 | } |
| 727 | |
| 728 | const payload = getTextPayload(message); |
| 729 | if (!payload) { |
| 730 | return; |
| 731 | } |
| 732 | |
| 733 | let data: unknown; |
| 734 | try { |
| 735 | data = JSON.parse(payload); |
| 736 | } catch { |
| 737 | return; |
| 738 | } |
| 739 | |
| 740 | if (!Array.isArray(data) || data.length === 0) { |
| 741 | return; |
| 742 | } |
| 743 | |
| 744 | const [type, ...rest] = data; |
| 745 | if (type === "AUTH" && typeof rest[0] === "string") { |
| 746 | await this.handleAuthChallenge(rest[0], generation); |
| 747 | return; |
| 748 | } |
| 749 | if (type === "EVENT" && typeof rest[0] === "string" && rest[1]) { |
| 750 | this.handleEvent(rest[0], rest[1] as RelayEvent); |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | if ( |
| 755 | type === "OK" && |
| 756 | typeof rest[0] === "string" && |
| 757 | typeof rest[1] === "boolean" |
| 758 | ) { |
| 759 | this.handleOk( |
| 760 | rest[0], |
| 761 | rest[1], |
no test coverage detected