-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpc.ts
27 lines (25 loc) · 888 Bytes
/
rpc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { JsonRpcParams, JsonRpcResult } from "./jsonrpccommon.ts";
import { JsonRpcClientWin } from "./jsonrpcwin.ts";
import type { JsonRpcClient } from "./mod.ts";
import { SmokeviewProcess } from "./process.ts";
export class SmvRpc {
public rpc: JsonRpcClient;
constructor(private process: SmokeviewProcess) {
this.rpc = new JsonRpcClientWin(process.socketPath);
}
async call(method: string, params?: JsonRpcParams): Promise<JsonRpcResult> {
return await this.rpc.call(method, params);
}
async notify(method: string, params?: JsonRpcParams): Promise<JsonRpcResult> {
return await this.rpc.notify(method, params);
}
close() {
this.rpc.close();
this.process.close();
}
}
export async function startSmvRpc(smvPath: string): Promise<SmvRpc> {
const smv = new SmokeviewProcess(smvPath);
const smvRpc = await smv.launch();
return smvRpc;
}