()
| 276 | } |
| 277 | |
| 278 | private async tick(): Promise<void> { |
| 279 | const now = Date.now(); |
| 280 | if (this.o.source === "api" && now < this.apiBackoffUntil) { |
| 281 | const waitS = Math.ceil((this.apiBackoffUntil - now) / 1000); |
| 282 | this.status = { |
| 283 | ...this.status, |
| 284 | ok: false, |
| 285 | message: `API rate limited — retrying in ${waitS}s`, |
| 286 | }; |
| 287 | this.o.onStatus(this.status); |
| 288 | return; |
| 289 | } |
| 290 | const primary = await this.fetchList(this.o.source, now); |
| 291 | if (primary === null) { |
| 292 | this.status = { |
| 293 | ...this.status, |
| 294 | ok: false, |
| 295 | message: this.lastError ?? "source fetch failed", |
| 296 | }; |
| 297 | this.o.onStatus(this.status); |
| 298 | return; |
| 299 | } |
| 300 | const supplement = this.o.source === "radio" && this.o.supplementApi; |
| 301 | const merged = supplement ? mergeSources(primary, this.lastApi) : primary; |
| 302 | for (const ac of merged) this.enrich(ac, now); |
| 303 | this.last = merged; |
| 304 | this.pruneSticky(now); |
| 305 | this.status = { |
| 306 | source: this.o.source, |
| 307 | ok: true, |
| 308 | count: merged.length, |
| 309 | lastOk: now, |
| 310 | message: supplement ? `radio + ${this.lastApi.length} via API` : undefined, |
| 311 | }; |
| 312 | this.o.onSnapshot(now, merged); |
| 313 | this.o.onStatus(this.status); |
| 314 | } |
| 315 | |
| 316 | private enrich(ac: Aircraft, now: number): void { |
| 317 | // Instant table lookups first. |
no test coverage detected