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

Worklet support #29130

Open
hillin opened this issue Dec 11, 2024 · 1 comment
Open

Worklet support #29130

hillin opened this issue Dec 11, 2024 · 1 comment
Labels
angular/build:application area: @angular/build feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature

Comments

@hillin
Copy link

hillin commented Dec 11, 2024

Which @angular/* package(s) are relevant/related to the feature request?

compiler

Description

The worklets are light weighted version of web workers. Currently Angular supports web workers, but not worklets, this makes us unable to make use of Angular's Typescript and bundling support when writing a worklet (i.e. we have to write the worklet in pure Javasctript, or deal with compiling and bundling ourselves).

Proposed solution

Support worklet like web workers.

Alternatives considered

For now we have come to a hacky workaround:

  1. Write the worklet as if it's a web worker. This is perfecly supported by Angular. Now the problem is, to load the compiled worker script, we don't have a trivial way to get its URL.

  2. Wrap the worker code like this:

if (typeof self !== "undefined") {
  postMessage(self.location.href);
} else {
  // do the worklet thing
}

When self is not undefined, we know this script is loaded as a webworker (in a worklet context it would be undefined). In this case, send the script's location by postMessage.

  1. When trying to load the worklet, first load it as a web worker, wait for it to report the location, then terminate the worker and use the location to load the worklet.

E.g. load an audio worklet:

// probe worker url
const worker = new Worker(
  new URL("path/to/the/worker", import.meta.url),
);

const url = await new Promise<string>((resolve, reject) => {
  worker.onmessage = (e) => {
    resolve(e.data);
    worker.terminate();
  };

  worker.onmessageerror = reject;
});

await audioContext.audioWorklet.addModule(url);
@alxhub alxhub transferred this issue from angular/angular Dec 13, 2024
@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Dec 17, 2024
Copy link
Contributor

angular-robot bot commented Dec 17, 2024

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
angular/build:application area: @angular/build feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

2 participants