AudioWorkletProcessor and Polymer 3.4.1 and 'window' not defined

301 views Asked by At

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)
1

There are 1 answers

0
giwyni On

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!