(data: string)
| 354 | if (current <= 1) { |
| 355 | this.activeContexts.delete(ctx); |
| 356 | released.push(ctx); |
| 357 | } else { |
| 358 | this.activeContexts.set(ctx, current - 1); |
| 359 | } |
| 360 | } |
| 361 | if (released.length > 0 && this.isConnected()) { |
| 362 | const message = { |
| 363 | type: 'context.unsubscribe', |
| 364 | contexts: released, |
| 365 | } satisfies ClientMessage; |
| 366 | this.send(message); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | onReconnect(handler: () => void): () => void { |
| 371 | this.reconnectHandlers.add(handler); |
| 372 | return () => { |
| 373 | this.reconnectHandlers.delete(handler); |
| 374 | }; |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Registers a handler that fires every time the underlying WebSocket |
| 379 | * transitions to OPEN — including the very first successful connect. |
| 380 | * |
| 381 | * If the socket is already connected at call time, the handler is called |
| 382 | * synchronously before this method returns, then added to the set so it |
| 383 | * also fires on future connect transitions. |
| 384 | * |
| 385 | * Returns an unsubscribe function. Calling it removes the handler. |
| 386 | */ |
| 387 | onConnected(handler: () => void): () => void { |
| 388 | this.connectedHandlers.add(handler); |
no test coverage detected