(sid: string, reason = 'closed')
| 209 | } |
| 210 | |
| 211 | function closeSession(sid: string, reason = 'closed'): void { |
| 212 | const session = sessions.get(sid); |
| 213 | if (!session) return; |
| 214 | if (session.hbTimer !== null) { |
| 215 | clearTimer(session.hbTimer); |
| 216 | session.hbTimer = null; |
| 217 | } |
| 218 | if (session.ws) { |
| 219 | try { |
| 220 | session.ws.close(1000, reason); |
| 221 | } catch { |
| 222 | // Close may throw if already closed; that's fine. |
| 223 | } |
| 224 | session.ws = null; |
| 225 | } |
| 226 | if (session.pollResolver) { |
| 227 | const resolve = session.pollResolver; |
| 228 | session.pollResolver = null; |
| 229 | // Emit a disconnect frame so the polling client tears down. |
| 230 | resolve(encodeFrame({ type: PacketType.Disconnect })); |
| 231 | } |
| 232 | sessions.delete(sid); |
| 233 | } |
| 234 | |
| 235 | return { |
| 236 | handleHandshake(request: Request): Response { |
no test coverage detected