Skip to content

Commit

Permalink
fixed: cross origin error for worker (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 authored Jun 9, 2023
1 parent 7c0fbd7 commit d3aba38
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plugnmeet-client",
"version": "1.4.2",
"version": "1.4.3",
"author": "Jibon L. Costa",
"license": "MIT",
"scripts": {
Expand Down
23 changes: 21 additions & 2 deletions src/components/virtual-background/helpers/timerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, () => 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<TimerData>) => {
const callback = callbacks.get(event.data.callbackId);
Expand Down
24 changes: 0 additions & 24 deletions src/components/virtual-background/helpers/timerWorker.ts

This file was deleted.

0 comments on commit d3aba38

Please sign in to comment.