From 2c412a3c47ee851ff64592c2b25aabcb9d170db1 Mon Sep 17 00:00:00 2001 From: Ulion Date: Wed, 6 Dec 2023 10:23:18 +0800 Subject: [PATCH] Fix assign to readonly. --- src/polyfill/audioworklet_polyfill.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/polyfill/audioworklet_polyfill.ts b/src/polyfill/audioworklet_polyfill.ts index e7efece..06761ba 100644 --- a/src/polyfill/audioworklet_polyfill.ts +++ b/src/polyfill/audioworklet_polyfill.ts @@ -21,17 +21,19 @@ if (typeof window !== "undefined") { if (typeof AudioWorkletNode !== 'function' || !('audioWorklet' in AudioContext.prototype)) { if (AudioContext) { - // @ts-ignore - AudioContext.prototype.audioWorklet = { - // eslint-disable-next-line - addModule: async function (moduleURL: string | URL, options?: WorkletOptions): Promise { - return; - }, - }; + if (!('audioWorklet' in AudioContext.prototype)) { + // @ts-ignore + AudioContext.prototype.audioWorklet = { + // eslint-disable-next-line + addModule: async function (moduleURL: string | URL, options?: WorkletOptions): Promise { + return; + }, + }; + } // @ts-ignore // eslint-disable-next-line no-native-reassign - window.AudioWorkletNode = function (context: AudioContext, processorName: string, options: any): ScriptProcessorNode { + window.AudioWorkletNode = window.AudioWorkletNode || function (context: AudioContext, processorName: string, options: any): ScriptProcessorNode { const {numberOfChannels = 1, frameLength = 512} = options && options.processorOptions; const scriptProcessor: ScriptProcessorNode & ProcessorPolyfill = context.createScriptProcessor(frameLength, numberOfChannels, numberOfChannels);