Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion WebDriverAgentLib/Utilities/FBMjpegServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

static const NSUInteger MAX_FPS = 60;
static const NSTimeInterval FRAME_TIMEOUT = 1.;
static const NSTimeInterval FAILURE_BACKOFF_MIN = 1.0;
static const NSTimeInterval FAILURE_BACKOFF_MAX = 10.0;

static NSString *const SERVER_NAME = @"WDA MJPEG Server";
static const char *QUEUE_NAME = "JPEG Screenshots Provider Queue";
Expand All @@ -32,6 +34,7 @@ @interface FBMjpegServer()
@property (nonatomic, readonly) NSMutableArray<GCDAsyncSocket *> *listeningClients;
@property (nonatomic, readonly) FBImageProcessor *imageProcessor;
@property (nonatomic, readonly) long long mainScreenID;
@property (nonatomic, assign) NSUInteger consecutiveScreenshotFailures;

@end

Expand All @@ -41,6 +44,7 @@ @implementation FBMjpegServer
- (instancetype)init
{
if ((self = [super init])) {
_consecutiveScreenshotFailures = 0;
_listeningClients = [NSMutableArray array];
dispatch_queue_attr_t queueAttributes = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_UTILITY, 0);
_backgroundQueue = dispatch_queue_create(QUEUE_NAME, queueAttributes);
Expand Down Expand Up @@ -91,10 +95,16 @@ - (void)streamScreenshot
error:&error];
if (nil == screenshotData) {
[FBLogger logFmt:@"%@", error.description];
[self scheduleNextScreenshotWithInterval:timerInterval timeStarted:timeStarted];
self.consecutiveScreenshotFailures++;
NSTimeInterval backoffSeconds = MIN(FAILURE_BACKOFF_MAX,
FAILURE_BACKOFF_MIN * (1 << MIN(self.consecutiveScreenshotFailures, 4)));
uint64_t backoffInterval = (uint64_t)(backoffSeconds * NSEC_PER_SEC);
[self scheduleNextScreenshotWithInterval:backoffInterval timeStarted:timeStarted];
return;
}

self.consecutiveScreenshotFailures = 0;

CGFloat scalingFactor = FBConfiguration.mjpegScalingFactor / 100.0;
[self.imageProcessor submitImageData:screenshotData
scalingFactor:scalingFactor
Expand Down
6 changes: 4 additions & 2 deletions lib/webdriveragent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,13 @@

private async parseBundleId(wdaBundlePath: string): Promise<string> {
const infoPlistPath = path.join(wdaBundlePath, 'Info.plist');
const infoPlist = await plist.parsePlist(await fs.readFile(infoPlistPath));
const infoPlist = (await plist.parsePlist(await fs.readFile(infoPlistPath))) as {
CFBundleIdentifier?: string;
};
if (!infoPlist.CFBundleIdentifier) {
throw new Error(`Could not find bundle id in '${infoPlistPath}'`);
}
return infoPlist.CFBundleIdentifier as string;
return infoPlist.CFBundleIdentifier;
}

private async fetchWDABundle(): Promise<string> {
Expand Down Expand Up @@ -407,11 +409,11 @@
get url(): url.UrlWithStringQuery {
if (!this._url) {
if (this.webDriverAgentUrl) {
this._url = url.parse(this.webDriverAgentUrl);

Check warning on line 412 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (22)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 412 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (22)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 412 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (24)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 412 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (20)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 412 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (24)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 412 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (20)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead
} else {
const port = this.wdaLocalPort || WDA_AGENT_PORT;
const {protocol, hostname} = url.parse(this.wdaBaseUrl || WDA_BASE_URL);

Check warning on line 415 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (22)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 415 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (22)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 415 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (24)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 415 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (20)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 415 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (24)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 415 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (20)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead
this._url = url.parse(`${protocol}//${this.wdaBindingIP || hostname}:${port}`);

Check warning on line 416 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (22)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 416 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (22)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 416 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (24)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 416 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (20)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 416 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (24)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 416 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (20)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead
}
}
return this._url;
Expand All @@ -422,7 +424,7 @@
* @param _url - The URL string to parse and set
*/
set url(_url: string) {
this._url = url.parse(_url);

Check warning on line 427 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (22)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 427 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (22)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 427 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (24)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 427 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (20)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 427 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (24)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 427 in lib/webdriveragent.ts

View workflow job for this annotation

GitHub Actions / node_test (20)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead
}

/**
Expand Down
Loading