Fix mpv protocol/transport typing and test regressions

This commit is contained in:
2026-02-15 17:35:43 -08:00
parent 396fde3011
commit 42b5b6ef89
6 changed files with 1076 additions and 1370 deletions

View File

@@ -73,11 +73,13 @@ export interface MpvSocketTransportOptions {
onData: (data: Buffer) => void;
onError: (error: Error) => void;
onClose: () => void;
socketFactory?: () => net.Socket;
}
export class MpvSocketTransport {
private socketPath: string;
private readonly callbacks: MpvSocketTransportEvents;
private readonly socketFactory: () => net.Socket;
private socketRef: net.Socket | null = null;
public socket: net.Socket | null = null;
public connected = false;
@@ -85,6 +87,7 @@ export class MpvSocketTransport {
constructor(options: MpvSocketTransportOptions) {
this.socketPath = options.socketPath;
this.socketFactory = options.socketFactory ?? (() => new net.Socket());
this.callbacks = {
onConnect: options.onConnect,
onData: options.onData,
@@ -107,7 +110,7 @@ export class MpvSocketTransport {
}
this.connecting = true;
this.socketRef = new net.Socket();
this.socketRef = this.socketFactory();
this.socket = this.socketRef;
this.socketRef.on("connect", () => {