-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextensionClient.ts
69 lines (55 loc) · 2.46 KB
/
extensionClient.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import * as extProtocol from './extensionProtocol';
import {Services} from "../services/debugAdapterServices";
import {getSocketId} from "./sockedId";
const ipc = require('node-ipc');
export class ExtensionClient {
private _appRoot: string;
private _idCounter = 0;
private _pendingRequests: Object;
private _socketId: string;
private _ipcClientInitialized: Promise<any>;
constructor(appRoot: string) {
this._appRoot = appRoot;
this._idCounter = 0;
this._pendingRequests = {};
this._socketId = getSocketId();
ipc.config.id = 'debug-adapter-' + process.pid;
ipc.config.retry = 1500;
ipc.config.maxRetries = 5;
this._ipcClientInitialized = new Promise((res, rej) => {
ipc.connectTo(
this._socketId,
() => {
ipc.of[this._socketId].on('connect', () => {
res();
});
ipc.of[this._socketId].on('error', error => {
Services.logger().log(`[ExtensionClient] error: ${JSON.stringify(error)}\n`);
});
ipc.of[this._socketId].on('extension-protocol-message', (response: extProtocol.Response) => {
(<(result: Object) => void>this._pendingRequests[response.requestId])(response.result);
});
}
);
});
}
private callRemoteMethod(method: string, args?: Object): Promise<Object> {
let request: extProtocol.Request = {id: 'req' + (++this._idCounter), method: method, args: args};
return new Promise<Object>((res, rej) => {
this._pendingRequests[request.id] = res;
ipc.of[this._socketId].emit('extension-protocol-message', request);
});
}
public getInitSettings(): Promise<extProtocol.InitSettingsResult> {
return <Promise<extProtocol.InitSettingsResult>>(this.callRemoteMethod('getInitSettings'));
}
public analyticsLaunchDebugger(args: extProtocol.AnalyticsLaunchDebuggerArgs): Promise<any> {
return this.callRemoteMethod('analyticsLaunchDebugger', args);
}
public runRunCommand(args: extProtocol.AnalyticsRunRunCommandArgs): Promise<any> {
return this.callRemoteMethod('runRunCommand', args);
}
public selectTeam(): Promise<{ id: string, name: string }> {
return <Promise<{ id: string, name: string }>>(this.callRemoteMethod('selectTeam'));
}
}