ipcInterface.ts 1.02 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Deshui Yu's avatar
Deshui Yu committed
3

4
import { IpcInterface } from './tuner_command_channel/common';
5
export { IpcInterface } from './tuner_command_channel/common';
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
export { createDispatcherPipeInterface, encodeCommand } from './tuner_command_channel/legacy';
import * as shim from './tuner_command_channel/shim';

let tunerDisabled: boolean = false;

class DummyIpcInterface implements IpcInterface {
    public sendCommand(_commandType: string, _content?: string): void { /* empty */ }
    public onCommand(_listener: (commandType: string, content: string) => void): void { /* empty */ }
    public onError(_listener: (error: Error) => void): void { /* empty */ }
}

export async function createDispatcherInterface(): Promise<IpcInterface> {
    if (!tunerDisabled) {
        return await shim.createDispatcherInterface();
    } else {
        return new DummyIpcInterface();
    }
}

export namespace UnitTestHelpers {
    export function disableTuner(): void {
        tunerDisabled = true;
    }
}