Adding config and file for shared worker.
Details
- Reviewers
michal tomek - Commits
- rCOMM5e8770bd0377: [web-db] add Shared Worker config
Run this code:
const webDbWorker = new SharedWorker('/worker/webDatabase'); webDbWorker.port.onmessage = function (e) { console.log('message from worker: ', e.data); }; webDbWorker.port.postMessage('hello there from main thread');
and check results in browser, desktop and shared worker consoles.
Diff Detail
- Repository
- rCOMM Comm
- Branch
- db-on-web-2
- Lint
No Lint Coverage - Unit
No Test Coverage
Event Timeline
web/types/worker-types.js | ||
---|---|---|
3–5 | I'm surprised this type works... the second part of the union is an object that contains only only property (props), so it is likely incompatible with MessageEvent. Does my inline edit work? Or perhaps even better (but less likely to work): export type SharedWorkerMessageEvent = { ...MessageEvent, +ports: $ReadOnlyArray<MessagePort>, }; |
keyserver/src/responders/webworker-responders.js | ||
---|---|---|
16 | I'm wondering if it is beneficial to have web as a prefix because it all lives in web directory. Also it might be a little confusing because desktop is also going to use webDatabase, right? | |
web/database/worker/web-db-worker.js | ||
6 | Should we check if this array has at least one element? |
- update type
- update worker path
- add check
keyserver/src/responders/webworker-responders.js | ||
---|---|---|
16 | right, good call, updating to simple database | |
web/database/worker/web-db-worker.js | ||
6 | I think it's impossible for this callback to be called when there is no connection (no MessagePort) and there are no checks everywhere in the docs examples. | |
web/types/worker-types.js | ||
3–5 | I think it works because of problems with how SharedWorkers are typed in the flow, but you're right - this shouldn't work. I'll make this type inexact as you suggested |
keyserver/src/responders/webworker-responders.js | ||
---|---|---|
14 ↗ | (On Diff #23694) | Why do we have to specify this for notif worker and not for database one? |
keyserver/src/responders/webworker-responders.js | ||
---|---|---|
14 ↗ | (On Diff #23694) | The Service-Worker-Allowed header narrows the scope (more detailed scope is specified on registering) from which the Service Worker can intercept requests (where it's a proxy). Shared Worker is not capable of intercepting calls at all, it just exists for the entire origin so there is no need for that, For notifs we use Service Worker, for database we use Shared Worker. |