Skip to content

Commit 7445a9d

Browse files
committed
fix: execute only attach request in order to enable the ios debugging
We don't need the AttachAvailability response as now we don't need different actions based on the response. We just need to get the debug port which is printed by the AttachRequest and the Runtime is now accepting connections regardless of its state. This also allows us to remove the availability calls from the runtime.
1 parent 233e6aa commit 7445a9d

File tree

4 files changed

+14
-54
lines changed

4 files changed

+14
-54
lines changed

lib/declarations.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ interface IiOSNotification extends NodeJS.EventEmitter {
755755
}
756756

757757
interface IiOSSocketRequestExecutor {
758-
executeLaunchRequest(deviceIdentifier: string, timeout: number, readyForAttachTimeout: number, projectId: string, debugOptions: IDebugOptions): Promise<void>;
758+
executeLaunchRequest(device: Mobile.IiOSDevice, timeout: number, readyForAttachTimeout: number, projectId: string, debugOptions: IDebugOptions): Promise<void>;
759759
executeAttachRequest(device: Mobile.IiOSDevice, timeout: number, projectId: string): Promise<void>;
760760
}
761761

lib/device-sockets/ios/app-debug-socket-proxy-factory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
123123
this.$logger.trace(err);
124124
this.emit(CONNECTION_ERROR_EVENT_NAME, err);
125125
acceptHandshake = false;
126-
this.$logger.warn(`Cannot connect to device socket. The error message is '${err.message}'. Try starting the application manually.`);
126+
this.$logger.warn(`Cannot connect to device socket. The error message is '${err.message}'.`);
127127
}
128128

129129
callback(acceptHandshake);

lib/device-sockets/ios/socket-request-executor.ts

+11-51
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,21 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
88

99
public async executeAttachRequest(device: Mobile.IiOSDevice, timeout: number, projectId: string): Promise<void> {
1010
const deviceIdentifier = device.deviceInfo.identifier;
11-
12-
const observeNotificationSockets = [
13-
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getAlreadyConnected(projectId), constants.IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE),
14-
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getReadyForAttach(projectId), constants.IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE),
15-
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getAttachAvailable(projectId), constants.IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE)
16-
];
17-
18-
const observeNotificationPromises = _(observeNotificationSockets)
19-
.uniq()
20-
.map(s => {
21-
return this.$iOSNotificationService.awaitNotification(deviceIdentifier, s, timeout);
22-
})
23-
.value();
24-
25-
// Trigger the notifications update.
26-
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getAttachAvailabilityQuery(projectId));
27-
28-
let receivedNotification: string;
2911
try {
30-
receivedNotification = await Promise.race(observeNotificationPromises);
12+
// We should create this promise here because we need to send the ObserveNotification on the device
13+
// before we send the PostNotification.
14+
const readyForAttachSocket = await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getReadyForAttach(projectId), constants.IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE);
15+
const readyForAttachPromise = this.$iOSNotificationService.awaitNotification(deviceIdentifier, +readyForAttachSocket, timeout);
16+
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getAttachRequest(projectId, deviceIdentifier));
17+
await readyForAttachPromise;
3118
} catch (e) {
32-
this.$errors.failWithoutHelp(`The application ${projectId} does not appear to be running on ${device.deviceInfo.displayName} or is not built with debugging enabled.`);
33-
}
34-
35-
switch (receivedNotification) {
36-
case this.$iOSNotification.getAlreadyConnected(projectId):
37-
this.$errors.failWithoutHelp("A client is already connected.");
38-
break;
39-
case this.$iOSNotification.getAttachAvailable(projectId):
40-
await this.executeAttachAvailable(deviceIdentifier, projectId, timeout);
41-
break;
42-
case this.$iOSNotification.getReadyForAttach(projectId):
43-
break;
44-
default:
45-
this.$logger.trace("Response from attach availability query:");
46-
this.$logger.trace(receivedNotification);
47-
this.$errors.failWithoutHelp("No notification received while executing attach request.");
19+
this.$errors.failWithoutHelp(`The application ${projectId} does not appear to be running on ${deviceIdentifier} or is not built with debugging enabled. Try starting the application manually.`);
4820
}
4921
}
5022

51-
public async executeLaunchRequest(deviceIdentifier: string, timeout: number, readyForAttachTimeout: number, projectId: string, debugOptions: IDebugOptions): Promise<void> {
23+
public async executeLaunchRequest(device: Mobile.IiOSDevice, timeout: number, readyForAttachTimeout: number, projectId: string, debugOptions: IDebugOptions): Promise<void> {
24+
const deviceIdentifier = device.deviceInfo.identifier;
25+
5226
try {
5327
if (!debugOptions.skipHandshake) {
5428
await this.executeHandshake(deviceIdentifier, projectId, timeout);
@@ -58,27 +32,13 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
5832
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getWaitForDebug(projectId));
5933
}
6034

61-
await this.executeAttachAvailable(deviceIdentifier, projectId, readyForAttachTimeout);
35+
await this.executeAttachRequest(device, readyForAttachTimeout, projectId);
6236
} catch (e) {
6337
this.$logger.trace("Launch request error: ", e);
6438
this.$errors.failWithoutHelp("Error while waiting for response from NativeScript runtime.");
6539
}
6640
}
6741

68-
private async executeAttachAvailable(deviceIdentifier: string, projectId: string, timeout: number): Promise<void> {
69-
try {
70-
// We should create this promise here because we need to send the ObserveNotification on the device
71-
// before we send the PostNotification.
72-
const readyForAttachSocket = await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getReadyForAttach(projectId), constants.IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE);
73-
const readyForAttachPromise = this.$iOSNotificationService.awaitNotification(deviceIdentifier, +readyForAttachSocket, timeout);
74-
await this.$iOSNotificationService.postNotification(deviceIdentifier, this.$iOSNotification.getAttachRequest(projectId, deviceIdentifier));
75-
await readyForAttachPromise;
76-
} catch (e) {
77-
this.$logger.trace("Attach available error: ", e);
78-
this.$errors.failWithoutHelp(`The application ${projectId} timed out when performing the socket handshake.`);
79-
}
80-
}
81-
8242
private async executeHandshake(deviceIdentifier: string, projectId: string, timeout: number): Promise<void> {
8343
// This notification will be send only once by the runtime during application start.
8444
// In case app is already running, we'll fail here as we'll not receive it.

lib/services/android-device-debug-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class AndroidDeviceDebugService extends DebugServiceBase implements IDevi
147147

148148
private async validateRunningApp(deviceId: string, packageName: string): Promise<void> {
149149
if (!(await this.isAppRunning(packageName, deviceId))) {
150-
this.$errors.failWithoutHelp(`The application ${packageName} does not appear to be running on ${deviceId} or is not built with debugging enabled.`);
150+
this.$errors.failWithoutHelp(`The application ${packageName} does not appear to be running on ${deviceId} or is not built with debugging enabled. Try starting the application manually.`);
151151
}
152152
}
153153

0 commit comments

Comments
 (0)