Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify event handling with algorithms #56

Open
jan-ivar opened this issue May 2, 2022 · 3 comments
Open

Specify event handling with algorithms #56

jan-ivar opened this issue May 2, 2022 · 3 comments

Comments

@jan-ivar
Copy link
Member

jan-ivar commented May 2, 2022

"The user agent fires an event" is under-specified, in ways that raises questions around timing.

Event handling is tricky and requires algorithms, since JS isn't allowed to observe things progressing in background processes naturally. For external occurrences, I recommend what WebRTC uses (as a minimum):

  • When something happens, the user agent MUST queue a task that runs the following steps:
    • Check state, and abort these steps if unnecessary
    • Update JS-observable state
    • Fire an event named foo at target.
    • Don't do anything after this (to avoid UAFs)

This makes it easy to abide by the following design rule: "Where possible, use a plain Event with a specified type, and capture any state information in the target object." — because state is updated on the same task the event fires on (event dispatch is synchronous).

@eladalon1983
Copy link
Member

The eureka moment for me is the realization that there is no queue of events, but rather, events can be fired either directly or from a queued task, but do not otherwise form a queue. Thank you @jan-ivar for bring it up, and thank you @alvestrand for clarifying.

With that in mind:

  • Yes, let's go for a vanilla event.
  • I think we should fire the event synchronously, and not from a queued task. This would make it easy to guarantee that track.getCaptureHandle() always returns the value associated with the latest event.

@jan-ivar
Copy link
Member Author

jan-ivar commented May 3, 2022

For a user agent to trigger anything JS-observable, we must start from "When something happens, the user agent MUST queue a task" as I show above, to preserve run-to-completion semantics.

The "Update JS-observable state" step would be to set a [[CaptureHandle]] internal slot to its new value. We'd then update the getCaptureHandle method to simply return[[CaptureHandle]].

See "When the underlying DTLS transport needs to update the state" for an example.

@beaufortfrancois
Copy link
Contributor

beaufortfrancois commented May 9, 2022

I'm leaving this comment there as well to not keep track of it.

the user agent MUST queue a task to fire an event with the name "capturehandlechange" at track.

Originally posted by @beaufortfrancois in #57 (comment)

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

No branches or pull requests

3 participants