(raw: string)
| 101 | } |
| 102 | |
| 103 | private onMessage(raw: string): void { |
| 104 | let msg: ServerMessage; |
| 105 | try { |
| 106 | msg = JSON.parse(raw) as ServerMessage; |
| 107 | } catch { |
| 108 | return; |
| 109 | } |
| 110 | if (msg.type === "config") { |
| 111 | this.config = mergeConfig(DEFAULT_CONFIG, msg.config); |
| 112 | this.events.onConfig?.(this.config); |
| 113 | } else if (msg.type === "aircraft") { |
| 114 | this.aircraft.clear(); |
| 115 | for (const ac of msg.aircraft) { |
| 116 | if (ac.ts == null) ac.ts = msg.now; |
| 117 | this.aircraft.set(ac.hex, ac); |
| 118 | } |
| 119 | this.events.onSnapshot?.(msg.now, msg.aircraft); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
no test coverage detected