diff --git a/package.json b/package.json index 8f23107c..b398a11e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plugnmeet-client", - "version": "1.4.2", + "version": "1.4.3", "author": "Jibon L. Costa", "license": "MIT", "scripts": { diff --git a/src/components/virtual-background/helpers/timerHelper.ts b/src/components/virtual-background/helpers/timerHelper.ts index 05351489..b74f87b8 100644 --- a/src/components/virtual-background/helpers/timerHelper.ts +++ b/src/components/virtual-background/helpers/timerHelper.ts @@ -8,10 +8,29 @@ export type TimerWorker = { terminate(): void; }; +// we'll have to write like this way, otherwise browser won't load because of cross origin error +const timerWorker = ` +const timeoutIds = new Map(); +self.onmessage = (event) => { + if (event.data.timeoutMs !== undefined) { + const timeoutId = self.setTimeout(() => { + self.postMessage({ callbackId: event.data.callbackId }); + timeoutIds.delete(event.data.callbackId); + }, event.data.timeoutMs); + timeoutIds.set(event.data.callbackId, timeoutId); + } else { + const timeoutId = timeoutIds.get(event.data.callbackId); + self.clearTimeout(timeoutId); + timeoutIds.delete(event.data.callbackId); + } +}; +`; + export function createTimerWorker(): TimerWorker { const callbacks = new Map void>(); - - const worker = new Worker(new URL('./timerWorker', import.meta.url)); + const worker = new Worker( + URL.createObjectURL(new Blob([timerWorker], { type: 'text/javascript' })), + ); worker.onmessage = (event: MessageEvent) => { const callback = callbacks.get(event.data.callbackId); diff --git a/src/components/virtual-background/helpers/timerWorker.ts b/src/components/virtual-background/helpers/timerWorker.ts deleted file mode 100644 index 23345384..00000000 --- a/src/components/virtual-background/helpers/timerWorker.ts +++ /dev/null @@ -1,24 +0,0 @@ -declare const self: DedicatedWorkerGlobalScope; - -type TimerData = { - callbackId: number; - timeoutMs?: number; -}; - -const timeoutIds = new Map(); - -self.onmessage = (event: MessageEvent) => { - if (event.data.timeoutMs !== undefined) { - const timeoutId = self.setTimeout(() => { - self.postMessage({ callbackId: event.data.callbackId }); - timeoutIds.delete(event.data.callbackId); - }, event.data.timeoutMs); - timeoutIds.set(event.data.callbackId, timeoutId); - } else { - const timeoutId = timeoutIds.get(event.data.callbackId); - self.clearTimeout(timeoutId); - timeoutIds.delete(event.data.callbackId); - } -}; - -export {};