Skip to content

Commit

Permalink
Fix ios streaming for real device (#1232)
Browse files Browse the repository at this point in the history
* fix ios streaming for real device

* bump version
  • Loading branch information
saikrishna321 authored Jul 8, 2024
1 parent 43fce98 commit af0ff02
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 37 deletions.
2 changes: 1 addition & 1 deletion dashboard-frontend
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appium-device-farm",
"version": "9.0.0",
"version": "9.0.1",
"description": "An appium 2.0 plugin that manages and create driver session on available devices",
"main": "./lib/src/main.js",
"scripts": {
Expand Down
67 changes: 37 additions & 30 deletions src/iProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,35 +190,7 @@ class DeviceConnectionsFactory {
for (const key of this._releaseProxiedConnections(connectionsOnPort)) {
delete this._connectionsMapping[key];
}
const timer = new timing.Timer().start();
try {
await waitForCondition(
async () => {
try {
if ((await checkPortStatus(port, LOCALHOST)) !== 'open') {
log.info(
`Port #${port} has been successfully released after ` +
`${timer.getDuration().asMilliSeconds.toFixed(0)}ms`,
);
isPortBusy = false;
return true;
}
} catch (ign) {
/* empty */
}
return false;
},
{
waitMs: PORT_CLOSE_TIMEOUT,
intervalMs: 300,
},
);
} catch (ign) {
log.warn(
`Did not know how to release port #${port} in ` +
`${timer.getDuration().asMilliSeconds.toFixed(0)}ms`,
);
}
isPortBusy = await this.waitForPortTobeReleased(port, isPortBusy);
}
}

Expand Down Expand Up @@ -249,7 +221,41 @@ class DeviceConnectionsFactory {
log.info(`Successfully requested the connection for ${currentKey}`);
}

releaseConnection(udid = null, port = null) {
private async waitForPortTobeReleased(port: any, isPortBusy: boolean) {
const timer = new timing.Timer().start();
try {
await waitForCondition(
async () => {
try {
if ((await checkPortStatus(port, LOCALHOST)) !== 'open') {
log.info(
`Port #${port} has been successfully released after ` +
`${timer.getDuration().asMilliSeconds.toFixed(0)}ms`,
);
isPortBusy = false;
return true;
}
} catch (ign) {
/* empty */
}
return false;
},
{
waitMs: PORT_CLOSE_TIMEOUT,
intervalMs: 300,
},
);
} catch (ign) {
log.warn(
`Did not know how to release port #${port} in ` +
`${timer.getDuration().asMilliSeconds.toFixed(0)}ms`,
);
}
return isPortBusy;
}

async releaseConnection(udid: any, port: any) {
const isPortBusy = (await checkPortStatus(port, LOCALHOST)) === 'open';
if (!udid && !port) {
log.warn(
'Neither device UDID nor local port is set. ' +
Expand All @@ -269,6 +275,7 @@ class DeviceConnectionsFactory {
for (const key of keys) {
delete this._connectionsMapping[key];
}
await this.waitForPortTobeReleased(port, isPortBusy);
log.debug(`Cached connections count: ${_.size(this._connectionsMapping)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules
7 changes: 5 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ class DevicePlugin extends BasePlugin {
: SessionType.LOCAL;

await EventBus.fire(new BeforeSessionCreatedEvent({ device, sessionType: sessionType }));

session = await next();
if (device.platform === 'ios' && device.realDevice) {
log.info(`📱 Forwarding ios port to real device ${device.udid} for manual interaction`);
await DEVICE_CONNECTIONS_FACTORY.requestConnection(device.udid, device.mjpegServerPort, {
usePortForwarding: true,
devicePort: device.mjpegServerPort,
});
}
session = await next();

debugLog(`📱 Session response: ${JSON.stringify(session)}`);
}

Expand Down Expand Up @@ -576,6 +576,9 @@ class DevicePlugin extends BasePlugin {
log.info(`📱 Unblocking the device that is blocked for session ${sessionId}`);
const res = await next();
await EventBus.fire(new AfterSessionDeletedEvent({ sessionId: sessionId, device: device }));
if (device?.platform === 'ios' && device.realDevice) {
await DEVICE_CONNECTIONS_FACTORY.releaseConnection(device.udid, device.mjpegServerPort);
}
return res;
}
}
Expand Down

0 comments on commit af0ff02

Please sign in to comment.