AudioWorkletProcessor 和 Polymer 3.4.1 和“窗口”未定义

发布于 2025-01-12 00:53:46 字数 1650 浏览 1 评论 0原文

尝试使用 lit element/Polymer Web 组件和 Audioworklet/AudioWorklet 处理器时,我收到此错误:

boot-c9e09360.js:20 Uncaught ReferenceError: window is not defined
at boot-c9e09360.js:20:1

在我的代码中的这一行:

await aw.audioContext.audioWorklet.addModule("micSpkrAwp.js") //micSpkrAwp is the audio-worklet-processor running in different process. 

boot-c9e09360.js 是一个聚合物文件,其中包含:

/**

@license 版权所有 (c) 2017 聚合物项目作者。版权所有。 ... */

/* eslint-disable no-unused-vars / /*

  • 当使用 Closure Compiler 时,JSCompiler_renameProperty(property, object) 被替换为 object[property] 的 munged 名称。
  • 我们不能给这个函数起别名,所以我们必须使用一个在不编译时具有相同行为的小垫片。
  • @param {?} prop 属性名称
  • @param {*} obj 引用对象
  • @return {string} 可能重命名的属性名称 */ window.JSCompiler_renameProperty = 函数(prop, obj) { 返回道具; };

我一直在使用 lit element/Polymer Web 组件,效果很好。我移除了聚合物组件,AudioWorkletProcessor 运行良好。 我认为问题是Polymer假设窗口已定义(因为Polymer与DOM一起工作),但是当遇到javascript文件 - AudioWorkletProcessor 没有引用DOM(只是提供音频处理接口的文件)时,会发生此错误。 有什么建议吗? micSpkrAwp.js 代码:

import {frameBufferQBRes } from "./queue.js" 从“./config.js”导入{config}

class MicSpkrProcessor extends AudioWorkletProcessor {

constructor() {
    super()
/** ..**/


process (inputs, outputs, parameters){
      console.log(`micSpkrAws - this.stopImmediateFlag ${this.stopImmediateFlag}`)
      if (this.stopImmediateFlag) return false
      const retVal=this.processFromQueue(inputs,outputs,parameters)
      return retVal
    }
  }
  registerProcessor('mic-spkr-processor', MicSpkrProcessor)

Trying to use lit element/Polymer Web components AND an Audioworklet/AudioWorklet processor, I got this error:

boot-c9e09360.js:20 Uncaught ReferenceError: window is not defined
at boot-c9e09360.js:20:1

at this line in my code:

await aw.audioContext.audioWorklet.addModule("micSpkrAwp.js") //micSpkrAwp is the audio-worklet-processor running in different process. 

The boot-c9e09360.js is a polymer file that contains:

/**

@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
...
*/

/* eslint-disable no-unused-vars /
/
*

  • When using Closure Compiler, JSCompiler_renameProperty(property, object) is replaced by the munged name for object[property]
  • We cannot alias this function, so we have to use a small shim that has the same behavior when not compiling.
  • @param {?} prop Property name
  • @param {*} obj Reference object
  • @return {string} Potentially renamed property name
    */
    window.JSCompiler_renameProperty = function(prop, obj) {
    return prop;
    };

I have been using lit element/Polymer web components and it works well. I removed the polymer components and the AudioWorkletProcessor works well.
I think that the problem is that Polymer assumes that window is defined (since polymer works with DOM), but when encountering a javascript file - the AudioWorkletProcessor which has no reference to DOM (just a file that provides the audio process interface) this error occurs.
Any suggestions?
Code of micSpkrAwp.js:

import { frameBufferQBRes } from "./queue.js"
import {config} from "./config.js"

class MicSpkrProcessor extends AudioWorkletProcessor {

constructor() {
    super()
/** ..**/


process (inputs, outputs, parameters){
      console.log(`micSpkrAws - this.stopImmediateFlag ${this.stopImmediateFlag}`)
      if (this.stopImmediateFlag) return false
      const retVal=this.processFromQueue(inputs,outputs,parameters)
      return retVal
    }
  }
  registerProcessor('mic-spkr-processor', MicSpkrProcessor)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

信仰 2025-01-19 00:53:46

感谢 Kaiido 提供的解决方案!
答案:由于导入,Polymer 脚本被注入到 AudioWorkletProcessor 代码中:

import { calculateSplices } from '@polymer/polymer/lib/utils/array-splice';

这不会立即可见,因为它是嵌套导入(导入的文件包含此导入语句)。删除此导入,问题就解决了!

Thanks to Kaiido for the solution!
Answer: Polymer scripts got injected into the AudioWorkletProcessor code due to importing :

import { calculateSplices } from '@polymer/polymer/lib/utils/array-splice';

This was not immediately visible since it was a nested import (imported file contained this import statement). This import was removed, and the problem solved!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文