(sid: string, raw: string)
| 186 | } |
| 187 | |
| 188 | function processInboundFrame(sid: string, raw: string): void { |
| 189 | const packet = decodeFrame(raw); |
| 190 | if (!packet) return; |
| 191 | switch (packet.type) { |
| 192 | case PacketType.Disconnect: |
| 193 | closeSession(sid, 'client disconnected'); |
| 194 | return; |
| 195 | case PacketType.Heartbeat: |
| 196 | // Clients echo the heartbeat; nothing to do — the fact that we |
| 197 | // received any frame already proves liveness. |
| 198 | return; |
| 199 | case PacketType.Event: { |
| 200 | const msg = socketIoEventToNative(packet); |
| 201 | if (msg) opts.onClientMessage(msg, sid); |
| 202 | return; |
| 203 | } |
| 204 | // Connect/Json/Message/Ack/Error/Noop: ignored. We only care about |
| 205 | // Event frames for the EtherCalc protocol. |
| 206 | default: |
| 207 | return; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | function closeSession(sid: string, reason = 'closed'): void { |
| 212 | const session = sessions.get(sid); |
no test coverage detected