@statewalker/webrun-http-browser 0.6.3 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +403 -495
- package/dist/index.js +1 -1
- package/dist/relay/index.d.ts.map +1 -1
- package/dist/sw/sw-dispatcher.d.ts +2 -1
- package/dist/sw/sw-dispatcher.d.ts.map +1 -1
- package/dist/sw.js +10 -7
- package/package.json +10 -6
- package/src/relay/index.ts +2 -2
- package/src/sw/sw-dispatcher.ts +11 -10
package/dist/index.js
CHANGED
|
@@ -2794,7 +2794,7 @@ async function callHttpService(request, { key, port }) {
|
|
|
2794
2794
|
* call the parent makes on that port is answered with the error, so the
|
|
2795
2795
|
* parent's `initHttpService` / `callHttpService` reject instead of waiting.
|
|
2796
2796
|
*/
|
|
2797
|
-
function getRelayWindowMessageHandler({ swUrl = `${new URL("./
|
|
2797
|
+
function getRelayWindowMessageHandler({ swUrl = `${new URL("./relay-sw.js", moduleUrl)}`, scopeUrl = `${new URL("./", moduleUrl)}`, timeout } = {}) {
|
|
2798
2798
|
let externalPort;
|
|
2799
2799
|
return async (ev) => {
|
|
2800
2800
|
if (ev.data?.type !== "CONNECT") return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAGpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAQ/D,cAAc,wBAAwB,CAAC;AAavC;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,CAAC,EAAE,yBAAyB,GAAG,WAAW,CAU1F;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB;;;;OAIG;IACH,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AAC,EAC1C,OAAgD,EAChD,GAAoC,EACpC,SAAyB,GAC1B,GAAE,yBAA8B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA+C9D;AAED,MAAM,WAAW,2BAA2B;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,iBAAiB,EAAE,aAAa,CAAC;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wBAAsB,oBAAoB,CAAC,EACzC,GAAG,EACH,iBAAiB,EACjB,GAAG,OAAO,EACX,EAAE,2BAA2B,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAc3D;AAED,MAAM,WAAW,iCAAiC;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/F,iBAAiB,EAAE,aAAa,CAAC;CAClC;AAED,wBAAsB,0BAA0B,CAAC,EAC/C,GAAG,EACH,IAAI,EACJ,OAAO,EACP,iBAAiB,GAClB,EAAE,iCAAiC,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAYzD"}
|
|
@@ -31,6 +31,7 @@ export declare class SwPortHandler {
|
|
|
31
31
|
private _serviceWorkerUrl?;
|
|
32
32
|
private _serviceWorker?;
|
|
33
33
|
private _registrationPromise?;
|
|
34
|
+
private _registration?;
|
|
34
35
|
private _cleanupRegistrations?;
|
|
35
36
|
constructor(options: SwPortHandlerOptions);
|
|
36
37
|
get key(): string;
|
|
@@ -40,7 +41,7 @@ export declare class SwPortHandler {
|
|
|
40
41
|
* own url when one is given, not against this module's: a bundle that is
|
|
41
42
|
* not an ES module (an IIFE, Theia's frontend) has no `import.meta.url`, and
|
|
42
43
|
* `new URL(scope, undefined)` threw `Invalid URL` there. Only without a
|
|
43
|
-
* worker url does the module's location decide (its default `
|
|
44
|
+
* worker url does the module's location decide (its default `sw-worker.js`
|
|
44
45
|
* sits next to it).
|
|
45
46
|
*/
|
|
46
47
|
get rootUrl(): URL;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sw-dispatcher.d.ts","sourceRoot":"","sources":["../../src/sw/sw-dispatcher.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,UAAU,WAAW;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACvC,OAAO,CAAC,iBAAiB,CAAC,CAAS;IACnC,OAAO,CAAC,cAAc,CAAC,CAAgB;IACvC,OAAO,CAAC,oBAAoB,CAAC,CAAgB;IAC7C,OAAO,CAAC,qBAAqB,CAAC,CAAa;IAE3C,YAAY,OAAO,EAAE,oBAAoB,EAIxC;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;;;;OAOG;IACH,IAAI,OAAO,IAAI,GAAG,CAGjB;IAED,IAAI,gBAAgB,IAAI,MAAM,CAa7B;IAED,UAAgB,wBAAwB,IAAI,OAAO,CAAC,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAG9E;IAED,UAA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,CAK1B;IAED,OAAO,CAAC,gBAAgB;YAOV,SAAS;YAgBT,kBAAkB;YAWlB,cAAc;YAOd,gBAAgB;CAY/B"}
|
package/dist/sw.js
CHANGED
|
@@ -1753,6 +1753,7 @@ var SwPortHandler = class {
|
|
|
1753
1753
|
_serviceWorkerUrl;
|
|
1754
1754
|
_serviceWorker;
|
|
1755
1755
|
_registrationPromise;
|
|
1756
|
+
_registration;
|
|
1756
1757
|
_cleanupRegistrations;
|
|
1757
1758
|
constructor(options) {
|
|
1758
1759
|
this.options = options;
|
|
@@ -1770,7 +1771,7 @@ var SwPortHandler = class {
|
|
|
1770
1771
|
* own url when one is given, not against this module's: a bundle that is
|
|
1771
1772
|
* not an ES module (an IIFE, Theia's frontend) has no `import.meta.url`, and
|
|
1772
1773
|
* `new URL(scope, undefined)` threw `Invalid URL` there. Only without a
|
|
1773
|
-
* worker url does the module's location decide (its default `
|
|
1774
|
+
* worker url does the module's location decide (its default `sw-worker.js`
|
|
1774
1775
|
* sits next to it).
|
|
1775
1776
|
*/
|
|
1776
1777
|
get rootUrl() {
|
|
@@ -1779,7 +1780,7 @@ var SwPortHandler = class {
|
|
|
1779
1780
|
}
|
|
1780
1781
|
get serviceWorkerUrl() {
|
|
1781
1782
|
if (!this._serviceWorkerUrl) {
|
|
1782
|
-
const url = this.options.serviceWorkerUrl ? resolveWorkerUrl(this.options.serviceWorkerUrl) : new URL("./
|
|
1783
|
+
const url = this.options.serviceWorkerUrl ? resolveWorkerUrl(this.options.serviceWorkerUrl) : new URL("./sw-worker.js", this.rootUrl);
|
|
1783
1784
|
this._serviceWorkerUrl = `${url}`;
|
|
1784
1785
|
}
|
|
1785
1786
|
return this._serviceWorkerUrl;
|
|
@@ -1817,7 +1818,7 @@ var SwPortHandler = class {
|
|
|
1817
1818
|
this._cleanupRegistrations = void 0;
|
|
1818
1819
|
});
|
|
1819
1820
|
const registration = await navigator.serviceWorker.register(this.serviceWorkerUrl, { scope: this.scope });
|
|
1820
|
-
|
|
1821
|
+
this._registration = registration;
|
|
1821
1822
|
const stopListening = handleChannelCalls(navigator.serviceWorker, "UPDATE_COMMUNICATION_PORT", async (_event, _params, port) => {
|
|
1822
1823
|
await this._setCommunicationPort(port);
|
|
1823
1824
|
return this._getRegistrationInfo();
|
|
@@ -1834,6 +1835,7 @@ var SwPortHandler = class {
|
|
|
1834
1835
|
} catch (error) {
|
|
1835
1836
|
stopListening();
|
|
1836
1837
|
this._cleanupRegistrations = void 0;
|
|
1838
|
+
this._registration = void 0;
|
|
1837
1839
|
this._registrationPromise = void 0;
|
|
1838
1840
|
throw error;
|
|
1839
1841
|
}
|
|
@@ -1842,11 +1844,12 @@ var SwPortHandler = class {
|
|
|
1842
1844
|
}
|
|
1843
1845
|
async stop() {
|
|
1844
1846
|
this._cleanupRegistrations?.();
|
|
1845
|
-
const
|
|
1846
|
-
|
|
1847
|
-
|
|
1847
|
+
const registration = this._registration;
|
|
1848
|
+
this._registration = void 0;
|
|
1849
|
+
try {
|
|
1850
|
+
await registration?.unregister();
|
|
1848
1851
|
} catch (error) {
|
|
1849
|
-
console.log("Service Worker
|
|
1852
|
+
console.log("Service Worker unregistration failed: ", error);
|
|
1850
1853
|
}
|
|
1851
1854
|
}
|
|
1852
1855
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statewalker/webrun-http-browser",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "ServiceWorker-based HTTP server for browsers, with relay and same-origin dispatch modes",
|
|
7
|
-
"
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/statewalker/webrun-wire/issues"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/statewalker/webrun-wire/tree/main/packages/webrun-http-browser#readme",
|
|
8
11
|
"author": {
|
|
9
12
|
"name": "Mikhail Kotelnikov",
|
|
10
13
|
"email": "mikhail.kotelnikov@gmail.com"
|
|
@@ -12,7 +15,8 @@
|
|
|
12
15
|
"license": "MIT",
|
|
13
16
|
"repository": {
|
|
14
17
|
"type": "git",
|
|
15
|
-
"url": "git
|
|
18
|
+
"url": "git+https://github.com/statewalker/webrun-wire.git",
|
|
19
|
+
"directory": "packages/webrun-http-browser"
|
|
16
20
|
},
|
|
17
21
|
"main": "./dist/index.js",
|
|
18
22
|
"module": "./dist/index.js",
|
|
@@ -49,9 +53,9 @@
|
|
|
49
53
|
],
|
|
50
54
|
"dependencies": {
|
|
51
55
|
"idb-keyval": "^6.3.0",
|
|
52
|
-
"@statewalker/webrun-http-streams": "^0.2.
|
|
53
|
-
"@statewalker/webrun-
|
|
54
|
-
"@statewalker/webrun-
|
|
56
|
+
"@statewalker/webrun-http-streams": "^0.2.5",
|
|
57
|
+
"@statewalker/webrun-streams": "^0.2.2",
|
|
58
|
+
"@statewalker/webrun-rpc": "^0.4.3"
|
|
55
59
|
},
|
|
56
60
|
"devDependencies": {
|
|
57
61
|
"@biomejs/biome": "^2.5.15",
|
package/src/relay/index.ts
CHANGED
|
@@ -135,8 +135,8 @@ export interface RelayWindowHandlerOptions {
|
|
|
135
135
|
* parent's `initHttpService` / `callHttpService` reject instead of waiting.
|
|
136
136
|
*/
|
|
137
137
|
export function getRelayWindowMessageHandler({
|
|
138
|
-
swUrl = `${new URL("./
|
|
139
|
-
scopeUrl = `${new URL("
|
|
138
|
+
swUrl = `${new URL("./relay-sw.js", moduleUrl)}`,
|
|
139
|
+
scopeUrl = `${new URL("./", moduleUrl)}`,
|
|
140
140
|
timeout,
|
|
141
141
|
}: RelayWindowHandlerOptions = {}): (ev: MessageEvent) => Promise<void> {
|
|
142
142
|
let externalPort: MessagePort | undefined;
|
package/src/sw/sw-dispatcher.ts
CHANGED
|
@@ -44,6 +44,7 @@ export class SwPortHandler {
|
|
|
44
44
|
private _serviceWorkerUrl?: string;
|
|
45
45
|
private _serviceWorker?: ServiceWorker;
|
|
46
46
|
private _registrationPromise?: Promise<void>;
|
|
47
|
+
private _registration?: ServiceWorkerRegistration;
|
|
47
48
|
private _cleanupRegistrations?: () => void;
|
|
48
49
|
|
|
49
50
|
constructor(options: SwPortHandlerOptions) {
|
|
@@ -65,7 +66,7 @@ export class SwPortHandler {
|
|
|
65
66
|
* own url when one is given, not against this module's: a bundle that is
|
|
66
67
|
* not an ES module (an IIFE, Theia's frontend) has no `import.meta.url`, and
|
|
67
68
|
* `new URL(scope, undefined)` threw `Invalid URL` there. Only without a
|
|
68
|
-
* worker url does the module's location decide (its default `
|
|
69
|
+
* worker url does the module's location decide (its default `sw-worker.js`
|
|
69
70
|
* sits next to it).
|
|
70
71
|
*/
|
|
71
72
|
get rootUrl(): URL {
|
|
@@ -82,7 +83,7 @@ export class SwPortHandler {
|
|
|
82
83
|
// use — `"/sw-worker.js"` — threw a bare `Invalid URL` naming
|
|
83
84
|
// neither the option nor the value.
|
|
84
85
|
resolveWorkerUrl(this.options.serviceWorkerUrl)
|
|
85
|
-
: new URL("./
|
|
86
|
+
: new URL("./sw-worker.js", this.rootUrl);
|
|
86
87
|
this._serviceWorkerUrl = `${url}`;
|
|
87
88
|
}
|
|
88
89
|
return this._serviceWorkerUrl;
|
|
@@ -133,7 +134,7 @@ export class SwPortHandler {
|
|
|
133
134
|
const registration = await navigator.serviceWorker.register(this.serviceWorkerUrl, {
|
|
134
135
|
scope: this.scope,
|
|
135
136
|
});
|
|
136
|
-
|
|
137
|
+
this._registration = registration;
|
|
137
138
|
|
|
138
139
|
const stopListening = handleChannelCalls(
|
|
139
140
|
navigator.serviceWorker,
|
|
@@ -170,6 +171,7 @@ export class SwPortHandler {
|
|
|
170
171
|
// that is not controlled, and other pages may be using the worker.
|
|
171
172
|
stopListening();
|
|
172
173
|
this._cleanupRegistrations = undefined;
|
|
174
|
+
this._registration = undefined;
|
|
173
175
|
this._registrationPromise = undefined;
|
|
174
176
|
throw error;
|
|
175
177
|
}
|
|
@@ -180,13 +182,12 @@ export class SwPortHandler {
|
|
|
180
182
|
|
|
181
183
|
async stop(): Promise<void> {
|
|
182
184
|
this._cleanupRegistrations?.();
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
185
|
+
const registration = this._registration;
|
|
186
|
+
this._registration = undefined;
|
|
187
|
+
try {
|
|
188
|
+
await registration?.unregister();
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.log("Service Worker unregistration failed: ", error);
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
}
|