Skip to content

Conversation

@myandrienko
Copy link
Contributor

@myandrienko myandrienko commented Nov 5, 2024

Browsers start throttling timers (intervals, timeouts) in background tabs after a period of inactivity. We use timers to send health checks, and missing health checks cause participant to be disconnected.

An active WebRTC connection on a page usually means the page is never considered inactive by the browser, and therefore timers are not throttled. But it's still possible to be in a call and not have an active connection, e.g. if nobody is publishing neither audio nor video. Also, some browsers (like Edge) might be more aggressive about timer throttling.

To handle situations like this, we move timers to a web worker, which are never throttled. Web worker then posts messages to the page on the specified intervals.

This feature is currently opt-in and hidden behind a feature toggle, which can be enabled when creating a client instance. Also, web workers might not be available (banned by CSP, running on Node, etc), so there's also a fallback mode that uses regular timers on the page side even when enabled.

@myandrienko myandrienko marked this pull request as ready for review November 6, 2024 12:14
* Create Web Worker to initiate timer events like health checks. Can possibly prevent
* timer throttling issues in inactive browser tabs.
*/
expertimental_enableTimerWorker?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature toggle

@myandrienko myandrienko merged commit c11c3ca into main Dec 3, 2024
16 checks passed
@myandrienko myandrienko deleted the worker-timers branch December 3, 2024 16:16
myandrienko added a commit that referenced this pull request Dec 11, 2024
Dropping the `experimental_` prefix since this feature was confirmed
working.

Since the timer worker (introduced in #1557) is not going to be updated
too often, we can skip an additional built step and just check in the
prebuilt worker.

The "source" file `worker.ts` and the script to generate worker are
still there, but they are not used during build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants