| 317 | } |
| 318 | |
| 319 | export class MockChannel { |
| 320 | public topic: string; |
| 321 | public params: Record<string, any>; |
| 322 | public joinPayload: Record<string, any> | null = null; |
| 323 | public pushLog: Array<{ event: string; payload: any; push: MockPush }> = []; |
| 324 | public left = false; |
| 325 | |
| 326 | private handlers = new Map< |
| 327 | string, |
| 328 | Array<{ ref: number; callback: (payload: any) => void }> |
| 329 | >(); |
| 330 | private joinPush = new MockPush(); |
| 331 | private errorHandlers: Array<(reason?: any) => void> = []; |
| 332 | private nextRef = 1; |
| 333 | |
| 334 | constructor(topic: string = "", params: Record<string, any> = {}) { |
| 335 | this.topic = topic; |
| 336 | this.params = params; |
| 337 | } |
| 338 | |
| 339 | on(event: string, callback: (payload: any) => void): number { |
| 340 | if (!this.handlers.has(event)) { |
| 341 | this.handlers.set(event, []); |
| 342 | } |
| 343 | const ref = this.nextRef++; |
| 344 | this.handlers.get(event)!.push({ ref, callback }); |
| 345 | return ref; |
| 346 | } |
| 347 | |
| 348 | off(event: string, ref?: number): void { |
| 349 | if (!this.handlers.has(event)) return; |
| 350 | if (ref === undefined) { |
| 351 | this.handlers.delete(event); |
| 352 | } else { |
| 353 | const filtered = this.handlers.get(event)!.filter((h) => h.ref !== ref); |
| 354 | this.handlers.set(event, filtered); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | onError(callback: (reason?: any) => void): void { |
| 359 | this.errorHandlers.push(callback); |
| 360 | } |
| 361 | |
| 362 | join(payload?: Record<string, any>): MockPush { |
| 363 | this.joinPayload = payload ?? null; |
| 364 | return this.joinPush; |
| 365 | } |
| 366 | |
| 367 | push(event: string, payload: any): MockPush { |
| 368 | const mockPush = new MockPush(); |
| 369 | this.pushLog.push({ event, payload, push: mockPush }); |
| 370 | return mockPush; |
| 371 | } |
| 372 | |
| 373 | leave(): void { |
| 374 | this.left = true; |
| 375 | } |
| 376 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…