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

importScripts in an AudioWorklet #2194

Closed
danhab99 opened this issue Apr 20, 2020 · 1 comment
Closed

importScripts in an AudioWorklet #2194

danhab99 opened this issue Apr 20, 2020 · 1 comment
Labels
Needs Discussion The issue needs more discussion before it can be fixed.

Comments

@danhab99
Copy link

Describe the issue

I can't use importScripts in my audioWorklet

importScripts('audioEncoder.js') // <-- importScripts undefined

class Worker extends AudioWorkletProcessor {
  constructor(opts) {
    super()
  }
  
  process(inputs, outputs, parameters) {
    importedEncodingFunction(inputs, outputs)
    return true
  }
}

registerProcessor('WebcastWorker', WebcastWorker)

From what I understand importScripts would add scripts to the "WorkerGlobalScope", but the AudioWorkletGlobalScope docs mention nothing about being associated with the WorkerGlobalScope leading me to understand that they're two different things. There's no mention in any WebAudioApi docs about importing scripts so my question is how can I go about importing scripts into an audioWorklet?

If that's not possible, is there anyway I can give my audioWorklet an arbitrary function that it's suppose to use?

@danhab99 danhab99 added Needs Discussion The issue needs more discussion before it can be fixed. Untriaged labels Apr 20, 2020
@padenot
Copy link
Member

padenot commented Apr 21, 2020

This is intentional. You can use import (aka static imports), but it's sub-optimal, since it's going to do unnecessary work on the real-time thread that you can easily avoid. I would recommend against it. The difference is that I don't think static import can be disabled in a worklet, because they're part of the ES Module syntax.

It's best to prepare your source file ahead of time and load that, if you want to do things at runtime, or you can use a packer if you already have a build step in your project. I've pointed to a code example on the slack channel, where you've asked the question, happy to talk about this there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Discussion The issue needs more discussion before it can be fixed.
Projects
None yet
Development

No branches or pull requests

3 participants