(room: string)
| 107 | } |
| 108 | |
| 109 | private createHeartbeat(room: string) { |
| 110 | const heartbeat = { |
| 111 | sender: setInterval(async () => { |
| 112 | |
| 113 | await fetch(`${this.redisUrl}/publish/${room}`, { |
| 114 | method: 'POST', |
| 115 | headers: { |
| 116 | 'Authorization': `Bearer ${this.redisToken}`, |
| 117 | 'Content-Type': 'application/json' |
| 118 | }, |
| 119 | body: JSON.stringify(["ping", null]) |
| 120 | }) |
| 121 | }, 30000), |
| 122 | |
| 123 | monitor: setInterval(() => { |
| 124 | const lastPingTime = this.lastPingTimes.get(room) ?? 0 |
| 125 | |
| 126 | if (Date.now() - lastPingTime > 45000) { |
| 127 | logger.warn("Heartbeat timeout detected") |
| 128 | this.unsubscribe(room).then(() => this.subscribe(room)) |
| 129 | } |
| 130 | }, 5000), |
| 131 | } |
| 132 | |
| 133 | this.heartbeatTimers.set(room, heartbeat) |
| 134 | } |
| 135 | |
| 136 | private async subscribe(room: string): Promise<void> { |
| 137 | return new Promise(async (resolve, reject) => { |
no test coverage detected