Skip to content

Add setTimeout/setInterval support to the QuickJS plugin runtime - #215

Open
fluffy637 wants to merge 1 commit into
NuvioMedia:Devfrom
fluffy637:fix/plugin-runtime-timers
Open

fluffy637 wants to merge 1 commit into
NuvioMedia:Devfrom
fluffy637:fix/plugin-runtime-timers

Conversation

@fluffy637

Copy link
Copy Markdown

Fixes #190 (and likely most "plugin works on mobile but returns 0 streams on desktop" reports).

Problem: plugins written for the mobile app commonly call setTimeout (fetch timeouts, retry backoff). The QuickJS runtime injects fetch, AbortController, etc., but no timers — so those plugins throw ReferenceError: setTimeout is not defined inside their own try/catch blocks and silently return zero streams on desktop.

Fix:

  • New TimerBridge host module exposing an async __native_delay binding backed by kotlinx.coroutines.delay (capped at the plugin timeout, cancelled with the QuickJs instance)
  • Timer polyfill in JsBindings (setTimeout/clearTimeout/setInterval/clearInterval/setImmediate) built on __native_delay, with JS-side cancellation and exception containment
  • Desktop test covering callback firing, extra args, and cancellation

Same approach as the official quickjs-kt setTimeout sample.

Note: the JS polyfill was validated standalone (firing, cancellation, intervals, exception containment); the Kotlin side follows the existing HostModule pattern but was not compiled locally — please let CI run.

🤖 Generated with Claude Code

Plugins written for the mobile app commonly call setTimeout for fetch
timeouts and retry backoff. The QuickJS runtime has no timers, so those
plugins throw ReferenceError inside their own try/catch blocks and
silently return zero streams on desktop (see NuvioMedia#190).

- TimerBridge exposes an async __native_delay binding backed by
  kotlinx.coroutines.delay, capped at the plugin timeout
- JsBindings gains a timer polyfill (setTimeout, clearTimeout,
  setInterval, clearInterval, setImmediate) built on __native_delay,
  with JS-side cancellation and exception containment
- Desktop test covering timer firing and cancellation

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

[Bug]: Can't load any streams using plugin

2 participants