UNPKG

msw

Version:

Seamless REST/GraphQL API mocking library for browser and Node.js.

26 lines (20 loc) • 826 B
import type { WebSocketClientHandle } from '@mswjs/interceptors/WebSocket' import type { WebSocketClientStore } from './websocket-client-store' import type { SerializedWebSocketClient } from './websocket-client-store' export class WebSocketMemoryClientStore implements WebSocketClientStore { private store: Map<string, SerializedWebSocketClient> constructor() { this.store = new Map() } public async add(client: WebSocketClientHandle): Promise<void> { this.store.set(client.id, { id: client.id, url: client.url.href }) } public getAll(): Promise<Array<SerializedWebSocketClient>> { return Promise.resolve(Array.from(this.store.values())) } public async deleteMany(clientIds: Array<string>): Promise<void> { for (const clientId of clientIds) { this.store.delete(clientId) } } }