Skip to content

Commit 0aaeb7e

Browse files
committed
fix: fix PR comments
1 parent 0128264 commit 0aaeb7e

15 files changed

+238
-237
lines changed

Diff for: lib/bootstrap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ $injector.requirePublic("previewQrCodeService", "./services/livesync/playground/
144144
$injector.requirePublic("sysInfo", "./sys-info");
145145

146146
$injector.require("iOSNotificationService", "./services/ios-notification-service");
147-
$injector.require("socketProxyFactory", "./device-sockets/ios/socket-proxy-factory");
147+
$injector.require("debugAppSocketProxyFactory", "./device-sockets/ios/app-debug-socket-proxy-factory");
148148
$injector.require("iOSNotification", "./device-sockets/ios/notification");
149149
$injector.require("iOSSocketRequestExecutor", "./device-sockets/ios/socket-request-executor");
150150
$injector.require("messages", "./common/messages/messages");

Diff for: lib/common/definitions/mobile.d.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,14 @@ declare module Mobile {
111111
}
112112

113113
interface IiOSDevice extends IDevice {
114-
getLiveSyncSocket(appId: string, projectDir: string): Promise<any>;
115-
getDebugSocket(appId: string, projectDir: string): Promise<any>;
114+
getLiveSyncSocket(appId: string): Promise<any>;
115+
destroyLiveSyncSocket(appId: string): void;
116+
117+
getDebugSocket(appId: string): Promise<any>;
118+
destroyDebugSocket(appId: string): void;
119+
116120
openDeviceLogStream(options?: IiOSLogStreamOptions): Promise<void>;
121+
destroyAllSockets(): void;
117122
}
118123

119124
interface IAndroidDevice extends IDevice {

Diff for: lib/common/mobile/ios/device/ios-device.ts

+21-55
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,28 @@ import * as constants from "../../../../constants";
55
import * as net from "net";
66
import { cache } from "../../../decorators";
77
import * as helpers from "../../../../common/helpers";
8+
import { IOSDeviceBase } from "../ios-device-base";
89

9-
export class IOSDevice implements Mobile.IiOSDevice {
10+
export class IOSDevice extends IOSDeviceBase {
1011
public applicationManager: Mobile.IDeviceApplicationManager;
1112
public fileSystem: Mobile.IDeviceFileSystem;
1213
public deviceInfo: Mobile.IDeviceInfo;
13-
private socket: net.Socket;
14-
1514
private _deviceLogHandler: (...args: any[]) => void;
1615

1716
constructor(private deviceActionInfo: IOSDeviceLib.IDeviceActionInfo,
18-
private $errors: IErrors,
17+
protected $errors: IErrors,
1918
private $injector: IInjector,
20-
private $iOSDebuggerPortService: IIOSDebuggerPortService,
19+
protected $iOSDebuggerPortService: IIOSDebuggerPortService,
2120
private $iOSSocketRequestExecutor: IiOSSocketRequestExecutor,
22-
private $processService: IProcessService,
21+
protected $processService: IProcessService,
2322
private $deviceLogProvider: Mobile.IDeviceLogProvider,
2423
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
2524
private $iOSDeviceProductNameMapper: Mobile.IiOSDeviceProductNameMapper,
2625
private $iosDeviceOperations: IIOSDeviceOperations,
2726
private $mobileHelper: Mobile.IMobileHelper) {
28-
27+
super();
2928
this.applicationManager = this.$injector.resolve(applicationManagerPath.IOSApplicationManager, { device: this, devicePointer: this.deviceActionInfo });
3029
this.fileSystem = this.$injector.resolve(fileSystemPath.IOSDeviceFileSystem, { device: this, devicePointer: this.deviceActionInfo });
31-
3230
const productType = deviceActionInfo.productType;
3331
const isTablet = this.$mobileHelper.isiOSTablet(productType);
3432
const deviceStatus = deviceActionInfo.status || commonConstants.UNREACHABLE_STATUS;
@@ -52,16 +50,6 @@ export class IOSDevice implements Mobile.IiOSDevice {
5250
return false;
5351
}
5452

55-
public getApplicationInfo(applicationIdentifier: string): Promise<Mobile.IApplicationInfo> {
56-
return this.applicationManager.getApplicationInfo(applicationIdentifier);
57-
}
58-
59-
private actionOnDeviceLog(response: IOSDeviceLib.IDeviceLogData): void {
60-
if (response.deviceId === this.deviceInfo.identifier) {
61-
this.$deviceLogProvider.logData(response.message, this.$devicePlatformsConstants.iOS, this.deviceInfo.identifier);
62-
}
63-
}
64-
6553
@cache()
6654
public async openDeviceLogStream(): Promise<void> {
6755
if (this.deviceInfo.status !== commonConstants.UNREACHABLE_STATUS) {
@@ -71,33 +59,11 @@ export class IOSDevice implements Mobile.IiOSDevice {
7159
}
7260
}
7361

74-
public detach(): void {
75-
if (this._deviceLogHandler) {
76-
this.$iosDeviceOperations.removeListener(commonConstants.DEVICE_LOG_EVENT_NAME, this._deviceLogHandler);
77-
}
78-
}
79-
80-
public async getLiveSyncSocket(appId: string, projectDir: string): Promise<net.Socket> {
81-
return this.getSocket(appId, projectDir);
82-
}
83-
84-
public async getDebugSocket(appId: string, projectDir: string): Promise<net.Socket> {
85-
return this.getSocket(appId, projectDir);
86-
}
87-
88-
private async getSocket(appId: string, projectDir: string): Promise<net.Socket> {
89-
if (this.socket) {
90-
return this.socket;
91-
}
92-
62+
protected async getSocketCore(appId: string): Promise<net.Socket> {
9363
await this.$iOSSocketRequestExecutor.executeAttachRequest(this, constants.AWAIT_NOTIFICATION_TIMEOUT_SECONDS, appId);
94-
const port = await this.$iOSDebuggerPortService.getPort({ projectDir, deviceId: this.deviceInfo.identifier, appId });
95-
if (!port) {
96-
this.$errors.failWithoutHelp("Device socket port cannot be found.");
97-
}
98-
64+
const port = await this.getDebuggerPort(appId);
9965
const deviceId = this.deviceInfo.identifier;
100-
this.socket = await helpers.connectEventuallyUntilTimeout(
66+
const socket = await helpers.connectEventuallyUntilTimeout(
10167
async () => {
10268
const deviceResponse = _.first((await this.$iosDeviceOperations.connectToPort([{ deviceId: deviceId, port: port }]))[deviceId]);
10369
const _socket = new net.Socket();
@@ -106,12 +72,19 @@ export class IOSDevice implements Mobile.IiOSDevice {
10672
},
10773
commonConstants.SOCKET_CONNECTION_TIMEOUT_MS);
10874

109-
this.socket.on("close", () => {
110-
this.socket = null;
111-
});
75+
return socket;
76+
}
11277

113-
this.$processService.attachToProcessExitSignals(this, this.destroySocket);
114-
return this.socket;
78+
private actionOnDeviceLog(response: IOSDeviceLib.IDeviceLogData): void {
79+
if (response.deviceId === this.deviceInfo.identifier) {
80+
this.$deviceLogProvider.logData(response.message, this.$devicePlatformsConstants.iOS, this.deviceInfo.identifier);
81+
}
82+
}
83+
84+
public detach(): void {
85+
if (this._deviceLogHandler) {
86+
this.$iosDeviceOperations.removeListener(commonConstants.DEVICE_LOG_EVENT_NAME, this._deviceLogHandler);
87+
}
11588
}
11689

11790
private getActiveArchitecture(productType: string): string {
@@ -135,13 +108,6 @@ export class IOSDevice implements Mobile.IiOSDevice {
135108

136109
return activeArchitecture;
137110
}
138-
139-
private destroySocket() {
140-
if (this.socket) {
141-
this.socket.destroy();
142-
this.socket = null;
143-
}
144-
}
145111
}
146112

147113
$injector.register("iOSDevice", IOSDevice);

Diff for: lib/common/mobile/ios/ios-device-base.ts

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import * as net from "net";
2+
3+
export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
4+
private cachedSockets: IDictionary<net.Socket> = {};
5+
protected abstract $errors: IErrors;
6+
protected abstract $iOSDebuggerPortService: IIOSDebuggerPortService;
7+
protected abstract $processService: IProcessService;
8+
abstract deviceInfo: Mobile.IDeviceInfo;
9+
abstract applicationManager: Mobile.IDeviceApplicationManager;
10+
abstract fileSystem: Mobile.IDeviceFileSystem;
11+
abstract isEmulator: boolean;
12+
abstract openDeviceLogStream(): Promise<void>;
13+
14+
public getApplicationInfo(applicationIdentifier: string): Promise<Mobile.IApplicationInfo> {
15+
return this.applicationManager.getApplicationInfo(applicationIdentifier);
16+
}
17+
18+
public async getLiveSyncSocket(appId: string): Promise<net.Socket> {
19+
return this.getSocket(appId);
20+
}
21+
22+
public async getDebugSocket(appId: string): Promise<net.Socket> {
23+
return this.getSocket(appId);
24+
}
25+
26+
public async getSocket(appId: string): Promise<net.Socket> {
27+
if (this.cachedSockets[appId]) {
28+
return this.cachedSockets[appId];
29+
}
30+
31+
this.cachedSockets[appId] = await this.getSocketCore(appId);
32+
33+
if (this.cachedSockets[appId]) {
34+
this.cachedSockets[appId].on("close", () => {
35+
this.destroySocket(appId);
36+
});
37+
38+
this.$processService.attachToProcessExitSignals(this, () => this.destroySocket(appId));
39+
}
40+
41+
return this.cachedSockets[appId];
42+
}
43+
44+
public destroyLiveSyncSocket(appId: string) {
45+
this.destroySocket(appId);
46+
}
47+
48+
public destroyDebugSocket(appId: string) {
49+
this.destroySocket(appId);
50+
}
51+
52+
protected abstract async getSocketCore(appId: string): Promise<net.Socket>;
53+
54+
protected async getDebuggerPort(appId: string): Promise<number> {
55+
const port = await this.$iOSDebuggerPortService.getPort({ deviceId: this.deviceInfo.identifier, appId });
56+
if (!port) {
57+
this.$errors.failWithoutHelp("Device socket port cannot be found.");
58+
}
59+
60+
return port;
61+
}
62+
63+
public destroyAllSockets() {
64+
let appId;
65+
for (appId in this.cachedSockets) {
66+
this.destroySocketSafe(this.cachedSockets[appId]);
67+
}
68+
69+
this.cachedSockets = {};
70+
}
71+
72+
private destroySocket(appId: string) {
73+
this.destroySocketSafe(this.cachedSockets[appId]);
74+
this.cachedSockets[appId] = null;
75+
}
76+
77+
private destroySocketSafe(socket: net.Socket) {
78+
if (socket && !socket.destroyed) {
79+
socket.destroy();
80+
}
81+
}
82+
}

Diff for: lib/common/mobile/ios/simulator/ios-simulator-device.ts

+29-67
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,28 @@ import * as constants from "../../../constants";
44
import * as net from "net";
55
import { cache } from "../../../decorators";
66
import * as helpers from "../../../../common/helpers";
7+
import { IOSDeviceBase } from "../ios-device-base";
78

8-
export class IOSSimulator implements Mobile.IiOSDevice {
9-
private _applicationManager: Mobile.IDeviceApplicationManager;
10-
private _fileSystem: Mobile.IDeviceFileSystem;
11-
private socket: net.Socket;
9+
export class IOSSimulator extends IOSDeviceBase implements Mobile.IiOSDevice {
10+
public applicationManager: Mobile.IDeviceApplicationManager;
11+
public fileSystem: Mobile.IDeviceFileSystem;
12+
public deviceInfo: Mobile.IDeviceInfo;
1213

1314
constructor(private simulator: Mobile.IiSimDevice,
1415
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
15-
private $errors: IErrors,
16+
protected $errors: IErrors,
1617
private $injector: IInjector,
17-
private $iOSDebuggerPortService: IIOSDebuggerPortService,
18+
protected $iOSDebuggerPortService: IIOSDebuggerPortService,
1819
private $iOSSimResolver: Mobile.IiOSSimResolver,
1920
private $iOSEmulatorServices: Mobile.IiOSSimulatorService,
2021
private $iOSNotification: IiOSNotification,
2122
private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
22-
private $logger: ILogger) { }
23-
24-
public async getLiveSyncSocket(appId: string, projectDir: string): Promise<net.Socket> {
25-
return this.getSocket(appId, projectDir);
26-
}
27-
28-
public async getDebugSocket(appId: string, projectDir: string): Promise<net.Socket> {
29-
return this.getSocket(appId, projectDir);
30-
}
31-
32-
private async getSocket(appId: string, projectDir: string): Promise<net.Socket> {
33-
if (this.socket) {
34-
return this.socket;
35-
}
36-
37-
const attachRequestMessage = this.$iOSNotification.getAttachRequest(appId, this.deviceInfo.identifier);
38-
await this.$iOSEmulatorServices.postDarwinNotification(attachRequestMessage, this.deviceInfo.identifier);
39-
const port = await this.$iOSDebuggerPortService.getPort({ projectDir, deviceId: this.deviceInfo.identifier, appId });
40-
if (!port) {
41-
this.$errors.failWithoutHelp("Device socket port cannot be found.");
42-
}
43-
44-
try {
45-
this.socket = await helpers.connectEventuallyUntilTimeout(
46-
async () => { return this.$iOSEmulatorServices.connectToPort({ port }) },
47-
constants.SOCKET_CONNECTION_TIMEOUT_MS);
48-
} catch (e) {
49-
this.$logger.warn(e);
50-
}
51-
52-
if (this.socket) {
53-
this.socket.on("close", () => {
54-
this.socket = null;
55-
});
56-
}
57-
58-
return this.socket;
59-
}
60-
61-
public get deviceInfo(): Mobile.IDeviceInfo {
62-
return {
23+
private $logger: ILogger,
24+
protected $processService: IProcessService) {
25+
super();
26+
this.applicationManager = this.$injector.resolve(applicationManagerPath.IOSSimulatorApplicationManager, { iosSim: this.$iOSSimResolver.iOSSim, device: this });
27+
this.fileSystem = this.$injector.resolve(fileSystemPath.IOSSimulatorFileSystem, { iosSim: this.$iOSSimResolver.iOSSim });
28+
this.deviceInfo = {
6329
imageIdentifier: this.simulator.id,
6430
identifier: this.simulator.id,
6531
displayName: this.simulator.name,
@@ -78,30 +44,26 @@ export class IOSSimulator implements Mobile.IiOSDevice {
7844
return true;
7945
}
8046

81-
public async getApplicationInfo(applicationIdentifier: string): Promise<Mobile.IApplicationInfo> {
82-
return this.applicationManager.getApplicationInfo(applicationIdentifier);
83-
}
84-
85-
public get applicationManager(): Mobile.IDeviceApplicationManager {
86-
if (!this._applicationManager) {
87-
this._applicationManager = this.$injector.resolve(applicationManagerPath.IOSSimulatorApplicationManager, { iosSim: this.$iOSSimResolver.iOSSim, device: this });
88-
}
89-
90-
return this._applicationManager;
91-
}
92-
93-
public get fileSystem(): Mobile.IDeviceFileSystem {
94-
if (!this._fileSystem) {
95-
this._fileSystem = this.$injector.resolve(fileSystemPath.IOSSimulatorFileSystem, { iosSim: this.$iOSSimResolver.iOSSim });
96-
}
97-
98-
return this._fileSystem;
99-
}
100-
10147
@cache()
10248
public async openDeviceLogStream(options?: Mobile.IiOSLogStreamOptions): Promise<void> {
10349
options = options || {};
10450
options.predicate = options.hasOwnProperty("predicate") ? options.predicate : constants.IOS_LOG_PREDICATE;
10551
return this.$iOSSimulatorLogProvider.startLogProcess(this.simulator.id, options);
10652
}
53+
54+
protected async getSocketCore(appId: string): Promise<net.Socket> {
55+
let socket: net.Socket;
56+
const attachRequestMessage = this.$iOSNotification.getAttachRequest(appId, this.deviceInfo.identifier);
57+
await this.$iOSEmulatorServices.postDarwinNotification(attachRequestMessage, this.deviceInfo.identifier);
58+
const port = await this.getDebuggerPort(appId);
59+
try {
60+
socket = await helpers.connectEventuallyUntilTimeout(
61+
async () => { return this.$iOSEmulatorServices.connectToPort({ port }); },
62+
constants.SOCKET_CONNECTION_TIMEOUT_MS);
63+
} catch (e) {
64+
this.$logger.warn(e);
65+
}
66+
67+
return socket;
68+
}
10769
}

Diff for: lib/declarations.d.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,9 @@ interface IEnvOptions {
537537

538538
interface IAndroidBuildOptionsSettings extends IAndroidReleaseOptions, IRelease, IHasAndroidBundle { }
539539

540-
interface IHasAndroidBundle {
540+
interface IHasAndroidBundle {
541541
androidBundle?: boolean;
542-
}
542+
}
543543

544544
interface IAppFilesUpdaterOptions extends IBundle, IRelease, IOptionalWatchAllFiles, IHasUseHotModuleReloadOption { }
545545

@@ -702,12 +702,12 @@ interface IAndroidToolsInfoValidateInput extends IAndroidToolsInfoOptions {
702702
validateTargetSdk: boolean;
703703
}
704704

705-
interface ISocketProxyFactory extends NodeJS.EventEmitter {
706-
getTCPSocketProxy(deviceIdentifier: string): any;
707-
addTCPSocketProxy(factory: () => Promise<any>, deviceIdentifier: string): Promise<any>;
705+
interface IDebugAppSocketProxyFactory extends NodeJS.EventEmitter {
706+
getTCPSocketProxy(deviceIdentifier: string, appId: string): any;
707+
addTCPSocketProxy(device: Mobile.IiOSDevice, appId: string): Promise<any>;
708708

709-
getWebSocketProxy(deviceIdentifier: string): any;
710-
addWebSocketProxy(factory: () => Promise<any>, deviceIdentifier: string): Promise<any>;
709+
getWebSocketProxy(deviceIdentifier: string, appId: string): any;
710+
addWebSocketProxy(device: Mobile.IiOSDevice, appId: string): Promise<any>;
711711

712712
removeAllProxies(): void;
713713
}

0 commit comments

Comments
 (0)