Skip to content

Commit

Permalink
Merge pull request #1721 from flexn-io/fix/android_notfoundip
Browse files Browse the repository at this point in the history
[android] Fix non-existing-IP error
  • Loading branch information
pauliusguzas authored Sep 27, 2024
2 parents 67ef77e + 7341e7a commit 6db16c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/sdk-android/src/__tests__/deviceManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('connectToWifiDevice', () => {
//THEN
expect(execCLI).toHaveBeenCalledTimes(1);
expect(result).toBeFalsy();
});
}, 15000);
it('pass when connect to correct IP address', async () => {
//GIVEN
jest.mocked(execCLI).mockResolvedValue('connected to 1.1.1.1:5555');
Expand Down
26 changes: 20 additions & 6 deletions packages/sdk-android/src/deviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,18 +455,32 @@ export const connectToWifiDevice = async (target: string) => {

const deviceResponse = await execCLI(CLI_ANDROID_ADB, connect_str);

if (deviceResponse.includes('connected')) return true;
if (deviceResponse.includes('connected to')) return true;

if (deviceResponse.includes('Connection refused')) {
try {
await new Promise((resolve, reject) => {
child_process.execFile(
'ping',
isSystemWin ? [target.split(':')[0]] : ['-c', '1', target.split(':')[0]],
(error, stdout) => {
if (error) {
reject(error);
} else {
resolve(stdout);
}
}
);
});
logWarning(
`You'll need to pair your device before installing app. \nFor more information: https://developer.android.com/studio/run/device`
);
return await _pairDevices(target);
} catch (error) {
logError(`Failed to ${connect_str}. Connection refused. Make sure to that ip and port are correct.`, {
skipAnalytics: true,
});
return false;
}
logWarning(
`You'll need to pair your device before installing app. \nFor more information: https://developer.android.com/studio/run/device`
);
return await _pairDevices(target);
};

const _pairDevices = async (target: string) => {
Expand Down
1 change: 0 additions & 1 deletion packages/sdk-apple/src/__tests__/deviceManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ describe('getAppleDevices', () => {
jest.mocked(listIOSDevices).mockResolvedValueOnce(devices);
// WHEN
const result = await getAppleDevices(true, false);
console.log(result);
// THEN
expect(result).toHaveLength(2);
expect(result[0].name).toBe('iPhone 15 Pro');
Expand Down

0 comments on commit 6db16c3

Please sign in to comment.