Page MenuHomePhabricator

D6987.diff
No OneTemporary

D6987.diff

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 === 'database') {
+ workerPath = 'database.build.js';
}
if (!workerPath) {
diff --git a/web/database/worker/db-worker.js b/web/database/worker/db-worker.js
new file mode 100644
--- /dev/null
+++ b/web/database/worker/db-worker.js
@@ -0,0 +1,19 @@
+// @flow
+
+import { type SharedWorkerMessageEvent } from '../../types/worker-types.js';
+
+function connectHandler(event: SharedWorkerMessageEvent) {
+ if (!event.ports.length) {
+ return;
+ }
+ 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,6 @@
+// @flow
+
+export type SharedWorkerMessageEvent = MessageEvent & {
+ +ports: $ReadOnlyArray<MessagePort>,
+ ...
+};
diff --git a/web/webpack.config.cjs b/web/webpack.config.cjs
--- a/web/webpack.config.cjs
+++ b/web/webpack.config.cjs
@@ -103,6 +103,7 @@
],
entry: {
pushNotif: './push-notif/service-worker.js',
+ database: './database/worker/db-worker.js',
},
output: {
filename: '[name].build.js',

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 6:07 AM (21 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2574235
Default Alt Text
D6987.diff (1 KB)

Event Timeline