* Destroy all subscribers for an agent. * Called when an agent stops.
(agentId: string)
| 220 | * Called when an agent stops. |
| 221 | */ |
| 222 | public destroySubscribersForAgent(agentId: string): void { |
| 223 | const keysToDelete: string[] = []; |
| 224 | |
| 225 | const router = TranscriptionRouter.getInstance(); |
| 226 | for (const [key, subscriber] of this.subscribers) { |
| 227 | if (key.startsWith(`${agentId}:`)) { |
| 228 | // Remove from transcription service |
| 229 | const service = router.getActiveService(subscriber.streamType); |
| 230 | if (service) { |
| 231 | service.removeSubscriber(subscriber); |
| 232 | } |
| 233 | |
| 234 | subscriber.destroy(); |
| 235 | keysToDelete.push(key); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | keysToDelete.forEach(key => this.subscribers.delete(key)); |
| 240 | |
| 241 | if (keysToDelete.length > 0) { |
| 242 | Logger.debug("StreamManager", `Destroyed ${keysToDelete.length} subscriber(s) for agent ${agentId}`); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | public addListener(listener: StreamListener): void { this.listeners.add(listener); listener(this.getCurrentState()); } |
| 247 | public removeListener(listener: StreamListener): void { this.listeners.delete(listener); } |
no test coverage detected