-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathios-device-base.ts
84 lines (66 loc) · 2.42 KB
/
ios-device-base.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import * as net from "net";
export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
private cachedSockets: IDictionary<net.Socket> = {};
protected abstract $errors: IErrors;
protected abstract $iOSDebuggerPortService: IIOSDebuggerPortService;
protected abstract $processService: IProcessService;
protected abstract $lockService: ILockService;
abstract deviceInfo: Mobile.IDeviceInfo;
abstract applicationManager: Mobile.IDeviceApplicationManager;
abstract fileSystem: Mobile.IDeviceFileSystem;
abstract isEmulator: boolean;
abstract openDeviceLogStream(): Promise<void>;
public getApplicationInfo(applicationIdentifier: string): Promise<Mobile.IApplicationInfo> {
return this.applicationManager.getApplicationInfo(applicationIdentifier);
}
public async getLiveSyncSocket(appId: string): Promise<net.Socket> {
return this.getSocket(appId);
}
public async getDebugSocket(appId: string): Promise<net.Socket> {
return this.getSocket(appId);
}
public async getSocket(appId: string): Promise<net.Socket> {
return this.$lockService.executeActionWithLock(async () => {
if (this.cachedSockets[appId]) {
return this.cachedSockets[appId];
}
this.cachedSockets[appId] = await this.getSocketCore(appId);
if (this.cachedSockets[appId]) {
this.cachedSockets[appId].on("close", () => {
this.destroySocket(appId);
});
this.$processService.attachToProcessExitSignals(this, () => this.destroySocket(appId));
}
return this.cachedSockets[appId];
}, "ios-debug-socket.lock");
}
public destroyLiveSyncSocket(appId: string) {
this.destroySocket(appId);
}
public destroyDebugSocket(appId: string) {
this.destroySocket(appId);
}
protected abstract async getSocketCore(appId: string): Promise<net.Socket>;
protected async getDebuggerPort(appId: string): Promise<number> {
const port = await this.$iOSDebuggerPortService.getPort({ deviceId: this.deviceInfo.identifier, appId });
if (!port) {
this.$errors.failWithoutHelp("Device socket port cannot be found.");
}
return port;
}
public destroyAllSockets() {
for (const appId in this.cachedSockets) {
this.destroySocketSafe(this.cachedSockets[appId]);
}
this.cachedSockets = {};
}
private destroySocket(appId: string) {
this.destroySocketSafe(this.cachedSockets[appId]);
this.cachedSockets[appId] = null;
}
private destroySocketSafe(socket: net.Socket) {
if (socket && !socket.destroyed) {
socket.destroy();
}
}
}