web-worker

How to import a node module inside an angular web worker?

一曲冷凌霜 提交于 2021-01-02 08:11:41
问题 I try to import a node module inside an Angular 8 web worker, but get an compile error 'Cannot find module'. Anyone know how to solve this? I created a new worker inside my electron project with ng generate web-worker app , like described in the above mentioned ng documentation. All works fine until i add some import like path or fs-extra e.g.: /// <reference lib="webworker" /> import * as path from 'path'; addEventListener('message', ({ data }) => { console.log(path.resolve('/')) const

Angular typescript typecheck issues when importing tensorflow in web worker

我是研究僧i 提交于 2020-12-05 11:44:16
问题 I am trying to use tensorflow/tfjs (TF) in a web-worker in an angular project. Creating a web-worker using the ng generate worker command works just fine. Importing TF in a component is fine too. However importing TF in the worker i.e. : import * as tf from '@tensorflow/tfjs' Generates a bunch of missing definition errors when building through the ng build command. Missing types are typically DOM-related types such as error TS2304: Cannot find name ImageData | HTMLImageElement |

Failed to execute 'fetch' on 'WorkerGlobalScope'

筅森魡賤 提交于 2020-11-29 19:24:07
问题 I trying to fetch data from the server inside of a web worker. But in dev tools every time I got the same error. Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Failed to parse URL from /api/books I saw this answer about service workers, but it's not working for me. WebWorker file code! // data-handling.web-worker.js const workercode = () => { onmessage = async e => { const res = await fetch('/api/books'); postMessage(res); } }; let code = workercode

Failed to execute 'fetch' on 'WorkerGlobalScope'

[亡魂溺海] 提交于 2020-11-29 19:21:45
问题 I trying to fetch data from the server inside of a web worker. But in dev tools every time I got the same error. Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Failed to parse URL from /api/books I saw this answer about service workers, but it's not working for me. WebWorker file code! // data-handling.web-worker.js const workercode = () => { onmessage = async e => { const res = await fetch('/api/books'); postMessage(res); } }; let code = workercode

Send offscreencanvas to webworker more than once

梦想的初衷 提交于 2020-07-22 08:33:48
问题 I want to be able to send my canvas offscreen to a webworker more than once. Here's an example code: render() { const worker = new Worker("some url"); const offscreen = this.canvasRef.current.transferControlToOffscreen(); this.worker.postMessage({ offscreen }, [offscreen]); return ( <canvas ref={this.canvasRef} height="800" width="1000" /> ); } The idea is to be able to kill the web worker if user decides to cancel the drawing. Put when I repost the message to a new web worker, I get the

Is there a way to send video data from a video tag/MediaStream to an OffscreenCanvas?

余生长醉 提交于 2020-07-16 07:40:34
问题 Basically I want to be able to perform effectively this same code: const video = document.getElementById('video'); const canvas = document.getElementById('canvas'); const context = canvas.getContext('2d'); const draw = () => { context.drawImage(video, 0, 0); requestAnimationFrame(draw); } video.onplay = () => { requestAnimationFrame(draw); } only using an offscreen canvas. I can send images over messages to the worker the offscreen canvas is on, but not video as it's directly tied to an

Is there a way to send video data from a video tag/MediaStream to an OffscreenCanvas?

扶醉桌前 提交于 2020-07-16 07:40:22
问题 Basically I want to be able to perform effectively this same code: const video = document.getElementById('video'); const canvas = document.getElementById('canvas'); const context = canvas.getContext('2d'); const draw = () => { context.drawImage(video, 0, 0); requestAnimationFrame(draw); } video.onplay = () => { requestAnimationFrame(draw); } only using an offscreen canvas. I can send images over messages to the worker the offscreen canvas is on, but not video as it's directly tied to an

Is there a way to send video data from a video tag/MediaStream to an OffscreenCanvas?

一笑奈何 提交于 2020-07-16 07:40:14
问题 Basically I want to be able to perform effectively this same code: const video = document.getElementById('video'); const canvas = document.getElementById('canvas'); const context = canvas.getContext('2d'); const draw = () => { context.drawImage(video, 0, 0); requestAnimationFrame(draw); } video.onplay = () => { requestAnimationFrame(draw); } only using an offscreen canvas. I can send images over messages to the worker the offscreen canvas is on, but not video as it's directly tied to an