soundcraft-ui-connection
Version:
Library for controlling the Soundcraft Ui series audio mixers
66 lines (65 loc) • 2.51 kB
TypeScript
/**
* Mock WebSocket for testing MixerConnection without a real network connection.
* Implements the subset of the WebSocket API that rxjs/webSocket relies on
* (direct onopen/onclose/onmessage/onerror handlers, not addEventListener).
*
* Pass as `webSocketCtor` in SoundcraftUIOptions to inject it.
* Use `simulateOpen()`, `simulateMessage()`, or `simulateClose()`
* to drive the connection lifecycle from tests.
*/
export declare class MockWebSocket {
static readonly CONNECTING = 0;
static readonly OPEN = 1;
static readonly CLOSING = 2;
static readonly CLOSED = 3;
readonly CONNECTING = 0;
readonly OPEN = 1;
readonly CLOSING = 2;
readonly CLOSED = 3;
url: string;
readyState: number;
binaryType: string;
onopen: ((event: Event) => void) | null;
onclose: ((event: Event) => void) | null;
onmessage: ((event: MessageEvent) => void) | null;
onerror: ((event: Event) => void) | null;
send: import('vitest').Mock<import('@vitest/spy').Procedure>;
close: import('vitest').Mock<() => void>;
/**
* Creates a subclass that calls `onCapture` with each new instance.
* Use this to get a reference to the WebSocket created internally by rxjs.
*/
static withCapture(onCapture: (instance: MockWebSocket) => void): {
new (url: string): {
readonly CONNECTING: 0;
readonly OPEN: 1;
readonly CLOSING: 2;
readonly CLOSED: 3;
url: string;
readyState: number;
binaryType: string;
onopen: ((event: Event) => void) | null;
onclose: ((event: Event) => void) | null;
onmessage: ((event: MessageEvent) => void) | null;
onerror: ((event: Event) => void) | null;
send: import('vitest').Mock<import('@vitest/spy').Procedure>;
close: import('vitest').Mock<() => void>;
addEventListener(): void;
removeEventListener(): void;
simulateOpen(): void;
simulateMessage(data: string): void;
simulateClose(): void;
};
readonly CONNECTING: 0;
readonly OPEN: 1;
readonly CLOSING: 2;
readonly CLOSED: 3;
withCapture(onCapture: (instance: MockWebSocket) => void): /*elided*/ any;
};
constructor(url: string);
addEventListener(): void;
removeEventListener(): void;
simulateOpen(): void;
simulateMessage(data: string): void;
simulateClose(): void;
}