aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/~partytown/debug/partytown-sw.js
diff options
context:
space:
mode:
authorKevin Hoerr <kjhoerr@protonmail.com>2022-11-18 19:56:28 -0500
committerGitHub <noreply@github.com>2022-11-18 19:56:28 -0500
commit1bbecf5d56f103784aa32c550c87048090da0ec1 (patch)
tree645ce26fbfa164a384e54b087e0918e5794b1a02 /public/~partytown/debug/partytown-sw.js
parent866a9f7991f43242995879c18fa7fc717cc3e8b6 (diff)
downloadsubmelon.dev-1bbecf5d56f103784aa32c550c87048090da0ec1.tar.gz
submelon.dev-1bbecf5d56f103784aa32c550c87048090da0ec1.tar.bz2
submelon.dev-1bbecf5d56f103784aa32c550c87048090da0ec1.zip
Site updates (#1)
* Add current page as reference * Upgrade dependencies: Gatsby 5.0.1 * Refactor components and styles to be consistent * Switch tense of BlockBody prop * Remove header on stylesheet * move timestamp to package version * Commit public dir for use with static site builders * Remove 1.0.7 file ref
Diffstat (limited to 'public/~partytown/debug/partytown-sw.js')
-rw-r--r--public/~partytown/debug/partytown-sw.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/public/~partytown/debug/partytown-sw.js b/public/~partytown/debug/partytown-sw.js
new file mode 100644
index 0000000..14b09e1
--- /dev/null
+++ b/public/~partytown/debug/partytown-sw.js
@@ -0,0 +1,59 @@
+/* Partytown 0.5.4 - MIT builder.io */
+const resolves = new Map;
+
+const swMessageError = (accessReq, $error$) => ({
+ $msgId$: accessReq.$msgId$,
+ $error$: $error$
+});
+
+const httpRequestFromWebWorker = req => new Promise((async resolve => {
+ const accessReq = await req.clone().json();
+ const responseData = await (accessReq => new Promise((async resolve => {
+ const clients = await self.clients.matchAll();
+ const client = [ ...clients ].sort(((a, b) => a.url > b.url ? -1 : a.url < b.url ? 1 : 0))[0];
+ if (client) {
+ const timeout = 12e4;
+ const msgResolve = [ resolve, setTimeout((() => {
+ resolves.delete(accessReq.$msgId$);
+ resolve(swMessageError(accessReq, "Timeout"));
+ }), timeout) ];
+ resolves.set(accessReq.$msgId$, msgResolve);
+ client.postMessage(accessReq);
+ } else {
+ resolve(swMessageError(accessReq, "NoParty"));
+ }
+ })))(accessReq);
+ resolve(response(JSON.stringify(responseData), "application/json"));
+}));
+
+const response = (body, contentType) => new Response(body, {
+ headers: {
+ "content-type": contentType || "text/html",
+ "Cache-Control": "no-store"
+ }
+});
+
+self.oninstall = () => self.skipWaiting();
+
+self.onactivate = () => self.clients.claim();
+
+self.onmessage = ev => {
+ const accessRsp = ev.data;
+ const r = resolves.get(accessRsp.$msgId$);
+ if (r) {
+ resolves.delete(accessRsp.$msgId$);
+ clearTimeout(r[1]);
+ r[0](accessRsp);
+ }
+};
+
+self.onfetch = ev => {
+ const req = ev.request;
+ const url = new URL(req.url);
+ const pathname = url.pathname;
+ if (pathname.endsWith("sw.html")) {
+ ev.respondWith(response('<!DOCTYPE html><html><head><meta charset="utf-8"><script src="./partytown-sandbox-sw.js?v=0.5.4"><\/script></head></html>'));
+ } else {
+ pathname.endsWith("proxytown") && ev.respondWith(httpRequestFromWebWorker(req));
+ }
+};