Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit cfd19f2

Browse files
Fix tns debug ios issues
Since we use the ios-device-lib to connect to the device backend port for debugging, the socket returned from the device can be used only in the ios-device lib. That's why we need to change the logic for creating the Node.js socket in the CLI. The ios-device-lib will expose the device socket on a specific port in the localhost. After we connect to the exposed socket we can continue to work like we used to.
1 parent 6fd98a6 commit cfd19f2

File tree

5 files changed

+10
-73
lines changed

5 files changed

+10
-73
lines changed

definitions/mobile.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,7 @@ interface IIOSDeviceOperations extends IDisposable {
718718

719719
awaitNotificationResponse(awaitNotificationResponseArray: IOSDeviceLib.IAwaitNotificatioNResponseData[], errorHandler?: DeviceOperationErrorHandler): Promise<IOSDeviceResponse>;
720720

721-
sendMessageToSocket(sendMessageToSocketArray: IOSDeviceLib.ISendMessageToSocketData[], errorHandler?: DeviceOperationErrorHandler): Promise<IOSDeviceResponse>;
722-
723-
readMessageFromSocket(readMessageFromSocketArray: IOSDeviceLib.IReceiveMessagesFromSocketData[]): void;
724-
725-
connectToPort(connectToPortArray: IOSDeviceLib.IConnectToPortData[], errorHandler?: DeviceOperationErrorHandler): Promise<IOSDeviceResponse>;
721+
connectToPort(connectToPortArray: IOSDeviceLib.IConnectToPortData[], errorHandler?: DeviceOperationErrorHandler): Promise<IDictionary<IOSDeviceLib.IConnectToPortResponse[]>>;
726722

727723
setShouldDispose(shouldDispose: boolean): void;
728724
}

helpers.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,6 @@ export function connectEventually(factory: () => net.Socket, handler: (_socket:
352352
tryConnect();
353353
}
354354

355-
export async function connectEventuallyAsync(factory: () => Promise<net.Socket>, handler: (_socket: net.Socket) => void): Promise<void> {
356-
async function tryConnect() {
357-
let tryConnectAfterTimeout = setTimeout.bind(undefined, tryConnect, 1000);
358-
359-
let socket = await factory();
360-
socket.on("connect", () => {
361-
socket.removeListener("error", tryConnectAfterTimeout);
362-
handler(socket);
363-
});
364-
socket.on("error", tryConnectAfterTimeout);
365-
}
366-
367-
await tryConnect();
368-
}
369-
370-
371355
export async function connectEventuallyUntilTimeout(factory: () => net.Socket, timeout: number): Promise<net.Socket> {
372356
return new Promise<net.Socket>((resolve, reject) => {
373357
let lastKnownError: Error;

mobile/ios/device/ios-device-operations.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,14 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable {
159159
return this.getMultipleResults<IOSDeviceLib.IDeviceResponse>(() => this.deviceLib.awaitNotificationResponse(awaitNotificationResponseArray), errorHandler);
160160
}
161161

162-
public async sendMessageToSocket(sendMessageToSocketArray: IOSDeviceLib.ISendMessageToSocketData[], errorHandler?: DeviceOperationErrorHandler): Promise<IOSDeviceResponse> {
163-
this.assertIsInitialized();
164-
165-
_.each(sendMessageToSocketArray, s => {
166-
this.$logger.trace(`Sending message: ${s.message} to socket: ${s.socket}`);
167-
});
168-
169-
return this.getMultipleResults<IOSDeviceLib.IDeviceResponse>(() => this.deviceLib.sendMessageToSocket(sendMessageToSocketArray), errorHandler);
170-
}
171-
172-
public readMessageFromSocket(readMessageFromSocketArray: IOSDeviceLib.IReceiveMessagesFromSocketData[]): void {
173-
this.deviceLib.readMessagesFromSocket(readMessageFromSocketArray);
174-
}
175-
176-
public async connectToPort(connectToPortArray: IOSDeviceLib.IConnectToPortData[], errorHandler?: DeviceOperationErrorHandler): Promise<IOSDeviceResponse> {
162+
public async connectToPort(connectToPortArray: IOSDeviceLib.IConnectToPortData[], errorHandler?: DeviceOperationErrorHandler): Promise<IDictionary<IOSDeviceLib.IConnectToPortResponse[]>> {
177163
this.assertIsInitialized();
178164

179165
_.each(connectToPortArray, c => {
180166
this.$logger.trace(`Connecting to port ${c.port} on device with identifier: ${c.deviceId}`);
181167
});
182168

183-
return this.getMultipleResults<IOSDeviceLib.IDeviceResponse>(() => this.deviceLib.connectToPort(connectToPortArray), errorHandler);
169+
return this.getMultipleResults<IOSDeviceLib.IConnectToPortResponse>(() => this.deviceLib.connectToPort(connectToPortArray), errorHandler);
184170
}
185171

186172
public setShouldDispose(shouldDispose: boolean): void {

mobile/ios/device/ios-device-socket.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

mobile/ios/device/ios-device.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as applicationManagerPath from "./ios-application-manager";
22
import * as fileSystemPath from "./ios-device-file-system";
33
import * as constants from "../../../constants";
44
import * as net from "net";
5-
import { IOSDeviceSocket } from "./ios-device-socket";
65

76
export class IOSDevice implements Mobile.IiOSDevice {
87
public applicationManager: Mobile.IDeviceApplicationManager;
@@ -24,12 +23,13 @@ export class IOSDevice implements Mobile.IiOSDevice {
2423

2524
const productType = deviceActionInfo.productType;
2625
const isTablet = productType && productType.toLowerCase().indexOf("ipad") !== -1;
26+
const deviceStatus = deviceActionInfo.status || constants.UNREACHABLE_STATUS;
2727
this.deviceInfo = {
2828
identifier: deviceActionInfo.deviceId,
2929
vendor: "Apple",
3030
platform: this.$devicePlatformsConstants.iOS,
31-
status: constants.CONNECTED_STATUS,
32-
errorHelp: null,
31+
status: deviceStatus,
32+
errorHelp: deviceStatus === constants.UNREACHABLE_STATUS ? `Device ${deviceActionInfo.deviceId} is ${constants.UNREACHABLE_STATUS}` : null,
3333
type: "Device",
3434
isTablet: isTablet,
3535
displayName: this.$iOSDeviceProductNameMapper.resolveProductName(deviceActionInfo.deviceName) || deviceActionInfo.deviceName,
@@ -59,13 +59,11 @@ export class IOSDevice implements Mobile.IiOSDevice {
5959
// This function works only on OSX
6060
public async connectToPort(port: number): Promise<net.Socket> {
6161
const deviceId = this.deviceInfo.identifier;
62-
const deviceResponse = (await this.$iosDeviceOperations.connectToPort([{ deviceId: deviceId, port: port }]))[deviceId];
62+
const deviceResponse = _.first((await this.$iosDeviceOperations.connectToPort([{ deviceId: deviceId, port: port }]))[deviceId]);
6363

64-
// HACK to override the write method of net.Socket
65-
const fd = deviceResponse[0].response;
66-
const socket = new IOSDeviceSocket({ fd: fd });
67-
socket.initialize(fd, deviceId, this.$iosDeviceOperations);
68-
this._socket = <any>socket;
64+
const socket = new net.Socket();
65+
socket.connect(deviceResponse.port, deviceResponse.host);
66+
this._socket = socket;
6967

7068
this.$processService.attachToProcessExitSignals(this, this.destroySocket);
7169
return this._socket;

0 commit comments

Comments
 (0)