diff --git a/keyserver/src/responders/webworker-responders.js b/keyserver/src/responders/webworker-responders.js --- a/keyserver/src/responders/webworker-responders.js +++ b/keyserver/src/responders/webworker-responders.js @@ -13,6 +13,8 @@ ...headers, 'Service-Worker-Allowed': '/', }; + } else if (req.params.worker === 'webDatabase') { + workerPath = 'webDatabase.build.js'; } if (!workerPath) { diff --git a/web/database/worker/web-db-worker.js b/web/database/worker/web-db-worker.js new file mode 100644 --- /dev/null +++ b/web/database/worker/web-db-worker.js @@ -0,0 +1,16 @@ +// @flow + +import { type SharedWorkerMessageEvent } from '../../types/worker-types.js'; + +function connectHandler(event: SharedWorkerMessageEvent) { + const port: MessagePort = event.ports[0]; + console.log('Web database worker alive!'); + + port.onmessage = async function (messageEvent: MessageEvent) { + console.log('message from main thread: ', messageEvent.data); + + port.postMessage({ message: 'response from worker' }); + }; +} + +self.addEventListener('connect', connectHandler); diff --git a/web/types/worker-types.js b/web/types/worker-types.js new file mode 100644 --- /dev/null +++ b/web/types/worker-types.js @@ -0,0 +1,5 @@ +// @flow + +export type SharedWorkerMessageEvent = MessageEvent & { + +ports: $ReadOnlyArray, +}; diff --git a/web/webpack.config.cjs b/web/webpack.config.cjs --- a/web/webpack.config.cjs +++ b/web/webpack.config.cjs @@ -88,6 +88,7 @@ const baseWebWorkersConfig = { entry: { pushNotif: './push-notif/service-worker.js', + webDatabase: './database/worker/web-db-worker.js', }, output: { filename: '[name].build.js',