mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 07:20:02 -04:00
return fake serviceworkerregistration
This commit is contained in:
parent
91dc2f96cd
commit
f2fe8c1d5e
5 changed files with 87 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
import { FakeServiceWorker } from "./fakesw";
|
||||
import { swfetch } from "./fetch";
|
||||
import { ScramjetThreadpool } from "./threadpool";
|
||||
|
||||
|
@ -15,6 +16,8 @@ export class ScramjetServiceWorker {
|
|||
syncPool: Record<number, (val?: any) => void> = {};
|
||||
synctoken = 0;
|
||||
|
||||
serviceWorkers: FakeServiceWorker[] = [];
|
||||
|
||||
constructor(config = self.$scramjet.config) {
|
||||
this.client = new self.$scramjet.shared.util.BareClient();
|
||||
if (!config.prefix) config.prefix = "/scramjet/";
|
||||
|
@ -23,6 +26,14 @@ export class ScramjetServiceWorker {
|
|||
this.threadpool = new ScramjetThreadpool();
|
||||
|
||||
addEventListener("message", ({ data }) => {
|
||||
if (!("scramjet$type" in data)) return;
|
||||
|
||||
if (data.scramjet$type === "registerServiceWorker") {
|
||||
this.serviceWorkers.push(new FakeServiceWorker(data.port));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!("scramjet$token" in data)) return;
|
||||
|
||||
const resolve = this.syncPool[data.scramjet$token];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue