Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
Co-authored-by: SrinivasanTarget <srinivasan.sekar1990@gmail.com>
  • Loading branch information
saikrishna321 and SrinivasanTarget committed Jan 20, 2025
1 parent e5a4530 commit bb6ef6e
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,29 +467,12 @@ export class XCUITestDriver extends BaseDriver {
// ensure WDA gets our defaults instead of whatever its own might be
await this.updateSettings(wdaSettings);

if(this.opts.mjpegServerPort) {
this.log.debug(
`MJPEG broadcasting requested, forwarding MJPEG server port ${this.opts.mjpegServerPort} ` +
`to local port ${this.opts.mjpegServerPort}`
);
try {
await DEVICE_CONNECTIONS_FACTORY.requestConnection(caps.udid, this.opts.mjpegServerPort, {
devicePort: this.opts.mjpegServerPort,
usePortForwarding: true,
});
} catch {
this.log.warn(
`Cannot forward the local port ${this.opts.mjpegServerPort} to ${this.opts.mjpegServerPort} ` +
`on the device ${caps.udid}.`,
);
}
}
// turn on mjpeg stream reading if requested
if (this.opts.mjpegScreenshotUrl) {
this.log.info(`Starting MJPEG stream reading URL: '${this.opts.mjpegScreenshotUrl}'`);
this.mjpegStream = new mjpeg.MJpegStream(this.opts.mjpegScreenshotUrl);
await this.mjpegStream.start();
if (this.isRealDevice() && this.opts.mjpegServerPort) {
await this.allocateMjpegServerPort(caps);
}

await this.startMjpegStream();

return /** @type {[string, import('@appium/types').DriverCaps<XCUITestDriverConstraints>]} */ ([
sessionId,
caps,
Expand All @@ -501,6 +484,33 @@ export class XCUITestDriver extends BaseDriver {
}
}

async startMjpegStream() {
// turn on mjpeg stream reading if requested
if (this.opts.mjpegScreenshotUrl) {
this.log.info(`Starting MJPEG stream reading URL: '${this.opts.mjpegScreenshotUrl}'`);
this.mjpegStream = new mjpeg.MJpegStream(this.opts.mjpegScreenshotUrl);
await this.mjpegStream.start();
}
}

async allocateMjpegServerPort(caps) {
this.log.debug(
`MJPEG broadcasting requested, forwarding MJPEG server port ${this.opts.mjpegServerPort} ` +
`to local port ${this.opts.mjpegServerPort}`
);
try {
await DEVICE_CONNECTIONS_FACTORY.requestConnection(caps.udid, this.opts.mjpegServerPort, {
devicePort: this.opts.mjpegServerPort,
usePortForwarding: true,
});
} catch {
throw new Error(
`Cannot forward the local port ${this.opts.mjpegServerPort} to ${this.opts.mjpegServerPort} ` +
`on the device ${caps.udid}.`
);
}
}

/**
* Returns the default URL for Safari browser
* @returns {string} The default URL
Expand Down

0 comments on commit bb6ef6e

Please sign in to comment.