Skip to content

Commit 096b50d

Browse files
committed
perf: retry replay
1 parent a964f13 commit 096b50d

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

src/app/elements/replay/guacamole/guacamole.component.ts

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,23 +240,48 @@ export class ElementReplayGuacamoleComponent
240240
let retryCount = 0;
241241

242242
const tryApplyScale = () => {
243-
if (this.recordingDisplay && this.screenRef) {
244-
const width = this.recordingDisplay.getWidth();
245-
const height = this.recordingDisplay.getHeight();
246-
247-
if (width > 0 && height > 0) {
248-
const scale = this.getPropScale();
249-
this.recordingDisplay.scale(scale);
250-
return true;
251-
} else if (retryCount < maxRetries) {
243+
if (!this.recordingDisplay || !this.screenRef) {
244+
if (retryCount < maxRetries) {
245+
retryCount++;
246+
setTimeout(tryApplyScale, delay);
247+
}
248+
return false;
249+
}
250+
251+
const width = this.recordingDisplay.getWidth();
252+
const height = this.recordingDisplay.getHeight();
253+
const { width: containerWidth, height: containerHeight } =
254+
this.screenRef.getBoundingClientRect();
255+
256+
if (width <= 0 || height <= 0 || containerWidth <= 0 || containerHeight <= 0) {
257+
if (retryCount < maxRetries) {
258+
retryCount++;
259+
setTimeout(tryApplyScale, delay);
260+
}
261+
return false;
262+
}
263+
264+
const scale = this.getPropScale();
265+
266+
if (!Number.isFinite(scale) || scale <= 0) {
267+
if (retryCount < maxRetries) {
252268
retryCount++;
253269
setTimeout(tryApplyScale, delay);
254-
return false;
255-
} else {
256-
return false;
257270
}
271+
return false;
258272
}
259-
return false;
273+
274+
try {
275+
this.recordingDisplay.scale(scale);
276+
} catch (error) {
277+
if (retryCount < maxRetries) {
278+
retryCount++;
279+
setTimeout(tryApplyScale, delay);
280+
}
281+
return false;
282+
}
283+
284+
return true;
260285
};
261286

262287
setTimeout(tryApplyScale, delay);

0 commit comments

Comments
 (0)