@dasl/tile-loader 2.5.0 → 3.0.0
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 +53 -8
- package/dist/at.d.ts +18 -0
- package/dist/at.d.ts.map +1 -1
- package/dist/at.js +86 -3
- package/dist/at.js.map +1 -1
- package/dist/content-scheme.d.ts +6 -0
- package/dist/content-scheme.d.ts.map +1 -1
- package/dist/content-scheme.js.map +1 -1
- package/dist/data.js +2 -2
- package/dist/data.js.map +1 -1
- package/dist/index.d.ts +23 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +67 -43
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +61 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +142 -0
- package/dist/link.js.map +1 -0
- package/dist/size.d.ts.map +1 -1
- package/dist/size.js +29 -10
- package/dist/size.js.map +1 -1
- package/package.json +7 -2
- package/src/at.ts +76 -3
- package/src/content-scheme.ts +6 -0
- package/src/data.ts +2 -2
- package/src/index.ts +81 -48
- package/src/link.ts +179 -0
- package/src/size.ts +27 -9
package/README.md
CHANGED
|
@@ -34,18 +34,31 @@ document.body.append(await tile.renderCard()); // lightweight, metadata-only
|
|
|
34
34
|
document.body.append(tile.renderContent()); // sandboxed iframe
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
A tile opens no window and its frame shows the tile and nothing else. A link
|
|
38
|
+
out of it is a request to your page, which opens nothing unless you say so:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { tileLinks, linkPrompt } from '@dasl/tile-loader/link';
|
|
42
|
+
tileLinks(tile, { open: linkPrompt(document.querySelector('#under-the-tile')) });
|
|
43
|
+
```
|
|
44
|
+
|
|
37
45
|
`loadDomain` must point at a running [`@dasl/tile-server`](../tile-server) — that's
|
|
38
46
|
the origin the sandboxed content is loaded from.
|
|
39
47
|
|
|
40
48
|
## Architecture
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
Four cooperating layers, all talking over `postMessage`:
|
|
43
51
|
|
|
44
52
|
- **Mothership** (this module, in your page) — the entry point. You configure it
|
|
45
53
|
with loaders, hand it a URL, and it produces a `Tile`. It holds all the
|
|
46
54
|
privileged capabilities (fetching, file access via loaders); the other layers
|
|
47
55
|
stay generic.
|
|
48
|
-
- **
|
|
56
|
+
- **Dock** (served by the tile server, on its own host) — the frame the
|
|
57
|
+
mothership makes. It frames the shuttle on a fresh random origin and keeps it
|
|
58
|
+
there: the tile can script its shuttle but not the dock, whose policy lets
|
|
59
|
+
that frame be at the runtime's URL and nowhere else. It relays messages
|
|
60
|
+
between the mothership and that one shuttle.
|
|
61
|
+
- **Shuttle** (served by the tile server) — a sandboxed iframe on the tile's
|
|
49
62
|
origin. It installs the service worker and hosts the inner iframe the tile
|
|
50
63
|
renders into, shuttling messages between the worker and the mothership.
|
|
51
64
|
- **Worker** (a service worker, served by the tile server) — intercepts the inner
|
|
@@ -58,6 +71,10 @@ Three cooperating layers, all talking over `postMessage`:
|
|
|
58
71
|
|
|
59
72
|
- `conf.loadDomain`: the host of your tile server (defaults to `load.webtil.es`);
|
|
60
73
|
give a full origin (`http://load.localhost:4321`) when it is not https on 443.
|
|
74
|
+
- `conf.tileHost`: a tile origin to run tiles on, by name
|
|
75
|
+
(`notes.tiles.example`), instead of a fresh random one per load; for a
|
|
76
|
+
deployment whose tiles share an origin or keep their storage. The tile server
|
|
77
|
+
has to recognise the name.
|
|
61
78
|
- `conf.webrtcGuard`: `'exhaust'` (default) has the shuttle spend Chromium's
|
|
62
79
|
per-process WebRTC budget before the tile loads (see Security model); `'none'`
|
|
63
80
|
skips it, for hosts that block WebRTC themselves (an Electron app with the
|
|
@@ -77,6 +94,9 @@ Three cooperating layers, all talking over `postMessage`:
|
|
|
77
94
|
(metadata only; safe to render many at once). `options.contentHeight` presets the
|
|
78
95
|
height used when the card is clicked to expand.
|
|
79
96
|
- **`renderContent(height?)`** — the sandboxed iframe that runs the tile.
|
|
97
|
+
- The **`stopped`** event (`ev.reason`: `blocked` or `navigated`) — the dock
|
|
98
|
+
stopped the tile because its runtime tried to leave its frame. The tile is
|
|
99
|
+
gone; render it again if you want it back.
|
|
80
100
|
- **`sendProtocol(protocol, kind, payload?)`** and the **`protocol`** event
|
|
81
101
|
(`ev.protocol`, `ev.kind`, `ev.payload`) — talk to the rendered tile over
|
|
82
102
|
[tiles protocols](https://dasl.ing/tiles-protocols.html). The loader attaches
|
|
@@ -90,11 +110,22 @@ Three cooperating layers, all talking over `postMessage`:
|
|
|
90
110
|
the tile what it got. `apply: false` is for a host that sizes its own box
|
|
91
111
|
(it gets each request in `onRequest`); `width: 'tile'` hands the width over
|
|
92
112
|
too. The rules are `resolveSize` in `@dasl/tile-lexicon`.
|
|
113
|
+
- For [tp-link](https://dasl.ing/tp-link.html), `@dasl/tile-loader/link` is
|
|
114
|
+
the context's side of a tile asking for a link to be opened:
|
|
115
|
+
`tileLinks(tile, { open })` calls `open(url, { activated, id })` for each
|
|
116
|
+
request (the user followed a link out of the tile, or the tile asked from
|
|
117
|
+
script) and tells the tile whether you opened it. Without `open`, nothing
|
|
118
|
+
opens. The URL is the tile's to choose, so show the user where it leads:
|
|
119
|
+
`linkPrompt(container)` is a handler that puts the whole address in
|
|
120
|
+
`container` as a link of your own for the user to follow, and refuses
|
|
121
|
+
requests made when the user had not touched the page. `openInNewTab(url)`
|
|
122
|
+
opens a web link cut off from your page. Only `http:` and `https:` reach
|
|
123
|
+
`open` unless you pass `schemes`.
|
|
93
124
|
- For [tp-data](https://dasl.ing/tp-data.html), `@dasl/tile-loader/data` names
|
|
94
125
|
the two kinds: `const data = tileData(tile)`, then `data.send(payload)`,
|
|
95
126
|
`data.onData(fn)` and `data.onReady(fn)` (each `on…` returns a function that
|
|
96
|
-
stops it). `Tile.sendData()` and the `data` / `data-ready` events
|
|
97
|
-
|
|
127
|
+
stops it). `Tile.sendData()` and the `data` / `data-ready` events, deprecated
|
|
128
|
+
in 2.4, are gone in 3.0.
|
|
98
129
|
- **`url`**, **`manifest`** — the tile's URL and MASL metadata.
|
|
99
130
|
|
|
100
131
|
### Loaders
|
|
@@ -103,7 +134,7 @@ Each is a subpath export; add the ones you need:
|
|
|
103
134
|
|
|
104
135
|
| Import | Loads | Matches |
|
|
105
136
|
| --- | --- | --- |
|
|
106
|
-
| `@dasl/tile-loader/at` — `ATTileLoader` | tiles from AT Protocol records, in `did:plc` and `did:web` repos | `at://…` |
|
|
137
|
+
| `@dasl/tile-loader/at` — `ATTileLoader` | tiles from AT Protocol records, in `did:plc` and `did:web` repos, named by DID or by handle | `at://…` |
|
|
107
138
|
| `@dasl/tile-loader/car` — `CARTileLoader` | CAR `.tile` files over HTTP | `http(s)://…` |
|
|
108
139
|
| `@dasl/tile-loader/webxdc` — `WebXDCTileLoader` | WebXDC `.xdc` bundles over HTTP | `http(s)://…` |
|
|
109
140
|
| `@dasl/tile-loader/memory` — `MemoryTileLoader` | in-memory manifests (testing/experiments) | `memory://<id>` |
|
|
@@ -125,7 +156,8 @@ A tile's origin is a dead end, by three layers that all read one policy
|
|
|
125
156
|
every response it resolves with the tile CSP: `connect-src` for WebSocket,
|
|
126
157
|
EventSource, beacons and WebTransport; `frame-src` and `form-action` for
|
|
127
158
|
navigations to other origins; `webrtc 'block'` for the day browsers implement
|
|
128
|
-
it; the `sandbox` flags
|
|
159
|
+
it; the `sandbox` flags, with no popups and no top navigation;
|
|
160
|
+
`X-DNS-Prefetch-Control: off`. A CSP the tile declares
|
|
129
161
|
stays and is enforced alongside. The worker's own improvised responses, and
|
|
130
162
|
the server's 404s, carry a `default-src 'none'; sandbox` dead end.
|
|
131
163
|
- **WebRTC is spent before the tile loads.** No browser implements CSP's
|
|
@@ -141,9 +173,22 @@ A tile's origin is a dead end, by three layers that all read one policy
|
|
|
141
173
|
host that can block it at the engine level should (mollusc's `network:
|
|
142
174
|
"loopback"`, say).
|
|
143
175
|
|
|
176
|
+
- **The runtime's frame goes nowhere.** The tile shares an origin with its
|
|
177
|
+
shuttle and can script it, into following a link for one. What governs where
|
|
178
|
+
a frame goes is its parent's `frame-src`, so the shuttle's parent is not
|
|
179
|
+
your page but the dock, on the tile server's own origin: its policy names the
|
|
180
|
+
runtime's URL on that tile's origin and nothing else, and it stops a tile
|
|
181
|
+
whose runtime tries to leave (the `stopped` event). A `frame-src` of your
|
|
182
|
+
own that only allows the tile server's host is a second lock on the same
|
|
183
|
+
door.
|
|
184
|
+
- **A tile opens nothing.** No popups in the sandbox, so no window to send
|
|
185
|
+
anywhere. A link out is a request over the link protocol, and your page
|
|
186
|
+
decides (`tileLinks`), opening it somewhere of its own.
|
|
187
|
+
|
|
144
188
|
The mothership's side of the contract is to only ever answer a worker's
|
|
145
|
-
`resolve-path` with `{ status, headers, body }`,
|
|
146
|
-
|
|
189
|
+
`resolve-path` with `{ status, headers, body }`, to act on messages only from
|
|
190
|
+
the docks it created, on the tile server's origin, and to post to that origin
|
|
191
|
+
alone. [`@dasl/containment-tile`](../containment-tile)
|
|
147
192
|
is the red-team tile that checks all of this end to end, in a real browser.
|
|
148
193
|
|
|
149
194
|
## Part of DASL tiles
|
package/dist/at.d.ts
CHANGED
|
@@ -11,6 +11,24 @@ type Fetch = typeof globalThis.fetch;
|
|
|
11
11
|
* the document is that host's `/.well-known/did.json`.
|
|
12
12
|
*/
|
|
13
13
|
export declare function didDocumentUrl(did: string): string | false;
|
|
14
|
+
/** The resolver handles are looked up with unless a loader is told otherwise. */
|
|
15
|
+
export declare const DEFAULT_DNS_OVER_HTTPS = "https://cloudflare-dns.com/dns-query";
|
|
16
|
+
/**
|
|
17
|
+
* The DID an AT handle names, or false. AT has two places for a handle to say
|
|
18
|
+
* so, and both are tried: a TXT record at `_atproto.<handle>` (asked of a
|
|
19
|
+
* DNS-over-HTTPS resolver, since a page has no DNS), and the handle's own
|
|
20
|
+
* `https://<handle>/.well-known/atproto-did` (which a page can only read if
|
|
21
|
+
* the host allows it across origins).
|
|
22
|
+
*
|
|
23
|
+
* Neither is taken at its word. A handle is only the DID's if the DID says so
|
|
24
|
+
* too: its document has to list `at://<handle>` in `alsoKnownAs`. Without
|
|
25
|
+
* that, anyone with a domain could point at somebody else's repo, or a
|
|
26
|
+
* resolver could.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveHandle(handle: string, options?: {
|
|
29
|
+
fetch?: Fetch;
|
|
30
|
+
dnsOverHttps?: string | false;
|
|
31
|
+
}): Promise<string | false>;
|
|
14
32
|
export declare class ATTileLoader {
|
|
15
33
|
#private;
|
|
16
34
|
constructor(options?: LoaderOptions);
|
package/dist/at.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"at.d.ts","sourceRoot":"","sources":["../src/at.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,KAAK,KAAK,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"at.d.ts","sourceRoot":"","sources":["../src/at.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,KAAK,KAAK,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;AAUrC;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAK3D;AAUD,iFAAiF;AACjF,eAAO,MAAM,sBAAsB,yCAAyC,CAAC;AAK7E;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;CAAO,GAAG,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAwC5I;AAiCD,qBAAa,YAAY;;gBAGV,OAAO,GAAE,aAAkB;IAIlC,IAAI,CAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,GAAG,SAAS,CAAC;CAexF;AACD,qBAAa,YAAY;;gBAIV,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,GAAE,KAA8C;IAK/F,WAAW,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CASxD"}
|
package/dist/at.js
CHANGED
|
@@ -15,14 +15,89 @@ export function didDocumentUrl(did) {
|
|
|
15
15
|
return `https://${web[1].toLowerCase()}/.well-known/did.json`;
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
|
-
async function
|
|
18
|
+
async function didDocument(fetch, did) {
|
|
19
19
|
const where = didDocumentUrl(did);
|
|
20
20
|
if (!where)
|
|
21
21
|
return false;
|
|
22
22
|
const res = await fetch(where);
|
|
23
23
|
if (!res.ok)
|
|
24
24
|
return false;
|
|
25
|
-
|
|
25
|
+
return await res.json();
|
|
26
|
+
}
|
|
27
|
+
/** The resolver handles are looked up with unless a loader is told otherwise. */
|
|
28
|
+
export const DEFAULT_DNS_OVER_HTTPS = 'https://cloudflare-dns.com/dns-query';
|
|
29
|
+
const HANDLE = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
30
|
+
const DID = /^did:[a-z]+:[A-Za-z0-9._:%-]+$/;
|
|
31
|
+
/**
|
|
32
|
+
* The DID an AT handle names, or false. AT has two places for a handle to say
|
|
33
|
+
* so, and both are tried: a TXT record at `_atproto.<handle>` (asked of a
|
|
34
|
+
* DNS-over-HTTPS resolver, since a page has no DNS), and the handle's own
|
|
35
|
+
* `https://<handle>/.well-known/atproto-did` (which a page can only read if
|
|
36
|
+
* the host allows it across origins).
|
|
37
|
+
*
|
|
38
|
+
* Neither is taken at its word. A handle is only the DID's if the DID says so
|
|
39
|
+
* too: its document has to list `at://<handle>` in `alsoKnownAs`. Without
|
|
40
|
+
* that, anyone with a domain could point at somebody else's repo, or a
|
|
41
|
+
* resolver could.
|
|
42
|
+
*/
|
|
43
|
+
export async function resolveHandle(handle, options = {}) {
|
|
44
|
+
const fetch = options.fetch ?? ((...args) => globalThis.fetch(...args));
|
|
45
|
+
const name = handle.toLowerCase();
|
|
46
|
+
if (!HANDLE.test(name) || name.length > 253)
|
|
47
|
+
return false;
|
|
48
|
+
const doh = options.dnsOverHttps === undefined ? DEFAULT_DNS_OVER_HTTPS : options.dnsOverHttps;
|
|
49
|
+
const claims = [];
|
|
50
|
+
if (doh) {
|
|
51
|
+
claims.push(async () => {
|
|
52
|
+
const url = new URL(doh);
|
|
53
|
+
url.searchParams.set('name', `_atproto.${name}`);
|
|
54
|
+
url.searchParams.set('type', 'TXT');
|
|
55
|
+
const res = await fetch(url.toString(), { headers: { accept: 'application/dns-json' } });
|
|
56
|
+
if (!res.ok)
|
|
57
|
+
return;
|
|
58
|
+
const { Answer } = await res.json();
|
|
59
|
+
// TXT data comes quoted, and split into quoted chunks when long.
|
|
60
|
+
const found = (Answer ?? [])
|
|
61
|
+
.filter(a => a.type === 16 && typeof a.data === 'string')
|
|
62
|
+
.map(a => a.data.replace(/"\s*"/g, '').replace(/^"|"$/g, ''))
|
|
63
|
+
.filter(txt => txt.startsWith('did='))
|
|
64
|
+
.map(txt => txt.slice(4));
|
|
65
|
+
// More than one answer is no answer: AT says so.
|
|
66
|
+
return found.length === 1 ? found[0] : undefined;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
claims.push(async () => {
|
|
70
|
+
const res = await fetch(`https://${name}/.well-known/atproto-did`);
|
|
71
|
+
if (!res.ok)
|
|
72
|
+
return;
|
|
73
|
+
return (await res.text()).trim();
|
|
74
|
+
});
|
|
75
|
+
for (const claim of claims) {
|
|
76
|
+
let did;
|
|
77
|
+
try {
|
|
78
|
+
did = await claim();
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
continue;
|
|
82
|
+
} // unreachable, or not readable from here: try the other
|
|
83
|
+
if (!did || !DID.test(did))
|
|
84
|
+
continue;
|
|
85
|
+
let doc;
|
|
86
|
+
try {
|
|
87
|
+
doc = await didDocument(fetch, did);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (doc && Array.isArray(doc.alsoKnownAs) && doc.alsoKnownAs.some(aka => typeof aka === 'string' && aka.toLowerCase() === `at://${name}`))
|
|
93
|
+
return did;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
async function did2pds(fetch, did) {
|
|
98
|
+
const doc = await didDocument(fetch, did);
|
|
99
|
+
if (!doc)
|
|
100
|
+
return false;
|
|
26
101
|
// The id is "#atproto_pds", or the same spelled out with the DID in front.
|
|
27
102
|
const pds = doc.service?.find(s => s.id === '#atproto_pds' || s.id === `${did}#atproto_pds`)?.serviceEndpoint;
|
|
28
103
|
return typeof pds === 'string' ? pds : false;
|
|
@@ -52,17 +127,25 @@ async function getBlob(fetch, did, cid) {
|
|
|
52
127
|
// ### AT Loader
|
|
53
128
|
// at://did:plc:izttpdp3l6vss5crelt5kcux/ing.dasl.masl/3mceykgxbkk2r
|
|
54
129
|
// at://did:web:example.com/ing.dasl.masl/3mceykgxbkk2r
|
|
130
|
+
// at://robin.berjon.com/ing.dasl.masl/3mceykgxbkk2r (a handle: see resolveHandle)
|
|
55
131
|
export class ATTileLoader {
|
|
56
132
|
#fetch;
|
|
133
|
+
#dnsOverHttps;
|
|
57
134
|
constructor(options = {}) {
|
|
58
135
|
this.#fetch = options.fetch ?? ((...args) => globalThis.fetch(...args));
|
|
136
|
+
this.#dnsOverHttps = options.dnsOverHttps;
|
|
59
137
|
}
|
|
60
138
|
async load(url, mothership) {
|
|
61
139
|
if (!/^at:\/\//.test(url))
|
|
62
140
|
return false;
|
|
63
|
-
const [
|
|
141
|
+
const [authority, collection, rkey] = url.replace(/^at:\/\//, '').split('/');
|
|
64
142
|
if (collection !== 'ing.dasl.masl')
|
|
65
143
|
return;
|
|
144
|
+
// The repo is a DID; a handle is a name for one. The tile keeps the URL
|
|
145
|
+
// it was asked for by, and everything of it is fetched by DID.
|
|
146
|
+
const repo = authority.startsWith('did:') ? authority : await resolveHandle(authority, { fetch: this.#fetch, dnsOverHttps: this.#dnsOverHttps });
|
|
147
|
+
if (!repo)
|
|
148
|
+
return false;
|
|
66
149
|
const res = await getRecord(this.#fetch, repo, collection, rkey);
|
|
67
150
|
if (!res)
|
|
68
151
|
return false;
|
package/dist/at.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"at.js","sourceRoot":"","sources":["../src/at.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"at.js","sourceRoot":"","sources":["../src/at.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAcxD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAE,GAAW;IACzC,IAAI,wBAAwB,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,yBAAyB,GAAG,EAAE,CAAC;IAC9E,MAAM,GAAG,GAAG,GAAG,CAAC,KA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MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,OAAO,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;CACF"}
|
package/dist/content-scheme.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import type { Tile, TileMothership } from "./index.js";
|
|
|
2
2
|
export interface LoaderOptions {
|
|
3
3
|
/** How to fetch: a host whose page has no network of its own routes these through its backend. */
|
|
4
4
|
fetch?: typeof globalThis.fetch;
|
|
5
|
+
/**
|
|
6
|
+
* A DNS-over-HTTPS resolver that answers in JSON, for looking up AT handles
|
|
7
|
+
* (a page cannot ask the DNS itself). Cloudflare's by default; `false`
|
|
8
|
+
* leaves the DNS out, and handles to their own `/.well-known/atproto-did`.
|
|
9
|
+
*/
|
|
10
|
+
dnsOverHttps?: string | false;
|
|
5
11
|
}
|
|
6
12
|
export declare abstract class ContentSchemeTileLoader {
|
|
7
13
|
#private;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-scheme.d.ts","sourceRoot":"","sources":["../src/content-scheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAKvD,MAAM,WAAW,aAAa;IAC5B,kGAAkG;IAClG,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"content-scheme.d.ts","sourceRoot":"","sources":["../src/content-scheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAKvD,MAAM,WAAW,aAAa;IAC5B,kGAAkG;IAClG,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC/B;AAED,8BAAsB,uBAAuB;;gBAG9B,OAAO,GAAE,MAAM,EAAqB,EAAE,OAAO,GAAE,aAAkB;IAIxE,IAAI,CAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,GAAG,SAAS,CAAC;IAkBvF,QAAQ,CAAC,cAAc,CAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;CAC5H"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-scheme.js","sourceRoot":"","sources":["../src/content-scheme.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"content-scheme.js","sourceRoot":"","sources":["../src/content-scheme.ts"],"names":[],"mappings":"AAiBA,MAAM,OAAgB,uBAAuB;IAC3C,QAAQ,CAAc;IACtB,MAAM,CAA0B;IAChC,YAAa,UAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,UAAyB,EAAE;QAC5E,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAC1E,CAAC;IACD,KAAK,CAAC,IAAI,CAAE,GAAW,EAAE,UAA0B;QACjD,IAAI,CAAM,CAAC;QACX,IAAI,CAAC;YAAC,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAAC,CAAC;QACzB,MAAM,CAAC;YAAC,OAAO,KAAK,CAAC;QAAC,CAAC,CAAC,kDAAkD;QAC1E,IAAI,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YACtD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC7C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,OAAO,KAAK,CAAC;YAC1B,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QACzF,CAAC;QACD,IAAI,CAAC,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YAC3B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC7C,MAAM;YACN,kBAAkB;YAClB,+BAA+B;QACjC,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CAEF"}
|
package/dist/data.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
// data.onReady(() => data.send({ name: 'world' }));
|
|
13
13
|
// const stop = data.onData((payload) => console.log(payload));
|
|
14
14
|
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
15
|
+
// (Before 3.0 the loader had `Tile.sendData()` and `data` / `data-ready`
|
|
16
|
+
// events for this. They are gone: this module is the way.)
|
|
17
17
|
/** The tiles protocol this module speaks. */
|
|
18
18
|
export const DATA_PROTOCOL = 'data';
|
|
19
19
|
/** tp-data on a tile: send it payloads, hear the ones it sends and when it is ready. */
|
package/dist/data.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,0EAA0E;AAC1E,wBAAwB;AACxB,EAAE;AACF,+EAA+E;AAC/E,yEAAyE;AACzE,6EAA6E;AAC7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EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;KACnD,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,14 @@ import type { AnyMasl, MaslHeaders, MaslResponse } from "@dasl/tile-lexicon";
|
|
|
2
2
|
export interface MothershipConfig {
|
|
3
3
|
/** Host of the loading server (`load.webtil.es`), with a scheme and port when not https://. */
|
|
4
4
|
loadDomain?: string;
|
|
5
|
+
/**
|
|
6
|
+
* The tile origin to run tiles on, as a host (`notes.tiles.example`, with
|
|
7
|
+
* the port if there is one), instead of a fresh random one for every load.
|
|
8
|
+
* For a deployment that means tiles to share an origin or to find their
|
|
9
|
+
* storage again; the loading server has to know the name as one of its tile
|
|
10
|
+
* origins. Leave it out and every tile gets an origin of its own.
|
|
11
|
+
*/
|
|
12
|
+
tileHost?: string;
|
|
5
13
|
/**
|
|
6
14
|
* Whether the shuttle spends the renderer's WebRTC budget before the tile
|
|
7
15
|
* loads (the default). A host that blocks WebRTC itself (an Electron app with
|
|
@@ -15,20 +23,21 @@ export interface TileLoader {
|
|
|
15
23
|
export interface TilePathLoader {
|
|
16
24
|
resolvePath(path: string): Promise<MaslResponse>;
|
|
17
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* The dock stopped a tile, because its runtime tried to leave the frame it
|
|
28
|
+
* runs in: `blocked` when the navigation was refused, `navigated` when the
|
|
29
|
+
* frame loaded something else all the same. The tile is gone either way; a
|
|
30
|
+
* host that wants it back renders it again.
|
|
31
|
+
*/
|
|
32
|
+
export interface StoppedEvent extends Event {
|
|
33
|
+
reason: 'blocked' | 'navigated';
|
|
34
|
+
}
|
|
18
35
|
/** A tiles-protocol message from a tile: `protocol` ("data"), `kind` ("payload", "ready"), and its `payload`. The mothership attaches no meaning to any of them. */
|
|
19
36
|
export interface ProtocolEvent extends Event {
|
|
20
37
|
protocol: string;
|
|
21
38
|
kind: string;
|
|
22
39
|
payload: unknown;
|
|
23
40
|
}
|
|
24
|
-
/**
|
|
25
|
-
* A tp-data message from a tile; `payload` is what the tile sent.
|
|
26
|
-
* @deprecated The `data` and `data-ready` events go in the next major
|
|
27
|
-
* version. Use `tileData()` from `@dasl/tile-loader/data`, or the `protocol` event.
|
|
28
|
-
*/
|
|
29
|
-
export interface DataEvent extends Event {
|
|
30
|
-
payload: unknown;
|
|
31
|
-
}
|
|
32
41
|
export declare class TileMothership {
|
|
33
42
|
#private;
|
|
34
43
|
constructor(conf?: MothershipConfig);
|
|
@@ -45,6 +54,12 @@ export declare class TileMothership {
|
|
|
45
54
|
startShuttle(id: string): void;
|
|
46
55
|
addLoader(loader: TileLoader): void;
|
|
47
56
|
removeLoader(loader: TileLoader): void;
|
|
57
|
+
/** The origin of the loading server: where the dock is, and so who we talk to. */
|
|
58
|
+
getLoadOrigin(): string;
|
|
59
|
+
/**
|
|
60
|
+
* What a tile's frame loads: the dock, on the loading server. Asked like
|
|
61
|
+
* this it picks a fresh origin for the tile and frames the runtime there.
|
|
62
|
+
*/
|
|
48
63
|
getLoadSource(): string;
|
|
49
64
|
loadTile(url: string): Promise<Tile | false>;
|
|
50
65
|
}
|
|
@@ -64,12 +79,6 @@ export declare class Tile extends EventTarget {
|
|
|
64
79
|
* means is up to the caller (see `@dasl/tile-loader/data` for tp-data).
|
|
65
80
|
*/
|
|
66
81
|
sendProtocol(protocol: string, kind: string, payload?: unknown): void;
|
|
67
|
-
/**
|
|
68
|
-
* Sends a tp-data payload to the tile (https://dasl.ing/tp-data.html).
|
|
69
|
-
* @deprecated Goes in the next major version. Use `tileData(tile).send()`
|
|
70
|
-
* from `@dasl/tile-loader/data`, or `sendProtocol('data', 'payload', payload)`.
|
|
71
|
-
*/
|
|
72
|
-
sendData(payload: unknown): void;
|
|
73
82
|
attachIframe(ifr: HTMLIFrameElement): void;
|
|
74
83
|
renderContent(height?: number): HTMLIFrameElement;
|
|
75
84
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE7E,MAAM,WAAW,gBAAgB;IAC/B,+FAA+F;IAC/F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,CAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,GAAG,SAAS,CAAC,CAAC;CACnF;AACD,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACnD;AAwBD;;;;;GAKG;AACH,MAAM,WAAW,YAAa,SAAQ,KAAK;IACzC,MAAM,EAAE,SAAS,GAAG,WAAW,CAAC;CACjC;AAED,oKAAoK;AACpK,MAAM,WAAW,aAAc,SAAQ,KAAK;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,qBAAa,cAAc;;gBAKZ,IAAI,GAAE,gBAAqB;IAGxC,IAAI;IA8DJ;;;;OAIG;IACH,cAAc,CAAE,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW;IAGnD,aAAa,CAAE,MAAM,EAAE,kBAAkB,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS;IAUnE,aAAa,CAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAQ3D,oBAAoB,CAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI;IAMxD,YAAY,CAAE,EAAE,EAAE,MAAM;IASxB,SAAS,CAAE,MAAM,EAAE,UAAU;IAI7B,YAAY,CAAE,MAAM,EAAE,UAAU;IAGhC,kFAAkF;IAClF,aAAa,IAAK,MAAM;IAIxB;;;OAGG;IACH,aAAa,IAAK,MAAM;IAMlB,QAAQ,CAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;CAOpD;AAED,qBAAa,IAAK,SAAQ,WAAW;;gBAMtB,UAAU,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc;IAoBnG,IAAI,GAAG,IAAK,MAAM,CAEjB;IACD,IAAI,QAAQ,IAAK,OAAO,CAEvB;IACK,WAAW,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAIjD,UAAU,CAAE,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAgD7E,aAAa,IAAK,MAAM;IAGxB;;;;OAIG;IACH,YAAY,CAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAI/D,YAAY,CAAE,GAAG,EAAE,iBAAiB;IAIpC,aAAa,CAAE,MAAM,SAAM,GAAG,iBAAiB;CAahD"}
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝
|
|
8
8
|
•--~~~## MOTHERSHIP ##~~~--•
|
|
9
9
|
|
|
10
|
-
The tile-loading architecture has
|
|
10
|
+
The tile-loading architecture has four levels that all communicate together:
|
|
11
11
|
|
|
12
12
|
- At the top, the MOTHERSHIP. This has access to things in the real world like
|
|
13
13
|
fetching from the internet or reading from the file system. It's the interface
|
|
@@ -17,7 +17,14 @@ The tile-loading architecture has three levels that all communicate together:
|
|
|
17
17
|
the configurability so that the other components can be deployed in entirely
|
|
18
18
|
generic ways.
|
|
19
19
|
- The mothership instantiates tiles by creating insulated contexts (a sandboxed
|
|
20
|
-
iframe, an incognito window…) and loading
|
|
20
|
+
iframe, an incognito window…) and loading the DOCK in it: a page on the
|
|
21
|
+
loading server's own origin, which frames the shuttle on the tile's origin
|
|
22
|
+
and keeps it there. The tile can script its shuttle but not the dock, so
|
|
23
|
+
the dock is what holds the frame in place (it can be navigated nowhere),
|
|
24
|
+
keeps everything below it from opening windows, and passes messages only
|
|
25
|
+
between the mothership and that one shuttle. The mothership only ever
|
|
26
|
+
talks to the dock.
|
|
27
|
+
- In the dock, the SHUTTLE. The role of the
|
|
21
28
|
shuttle is to set up a service worker and an iframe to load the root of the
|
|
22
29
|
tile into. It only exists because you need something to carry a service worker
|
|
23
30
|
in. The only other thing that it does is (*drumroll*) shuttle messages back
|
|
@@ -27,7 +34,7 @@ The tile-loading architecture has three levels that all communicate together:
|
|
|
27
34
|
requests up, which the shuttle then hands over to the mothership.
|
|
28
35
|
*/
|
|
29
36
|
import { el } from "./lib/el.js";
|
|
30
|
-
import { tileResponseHeaders } from "@dasl/tile-lexicon";
|
|
37
|
+
import { tileResponseHeaders, dockPath } from "@dasl/tile-lexicon";
|
|
31
38
|
const TILES_PFX = 'tiles-';
|
|
32
39
|
const SHUTTLE_PFX = 'tiles-shuttle-';
|
|
33
40
|
const SND_SHUTTLE_LOAD = `${SHUTTLE_PFX}load`; // tell worker to roll
|
|
@@ -40,12 +47,15 @@ const RCV_WORKER_READY = `${WORKER_PFX}ready`; // worker ready
|
|
|
40
47
|
const RCV_WORKER_REQUEST = `${WORKER_PFX}request`; // worker requested something
|
|
41
48
|
const SND_WORKER_RESPONSE = `${WORKER_PFX}response`; // respond to a worker
|
|
42
49
|
const TILES_WARNING = `${TILES_PFX}warn`; // worker warnings
|
|
43
|
-
const TILES_ERROR = `${
|
|
50
|
+
const TILES_ERROR = `${SHUTTLE_PFX}error`; // shuttle errors
|
|
51
|
+
const RCV_DOCK_STOPPED = 'tiles-dock-stopped'; // the dock stopped the tile
|
|
44
52
|
// Tiles protocols (https://dasl.ing/tp-data.html and friends): the shuttle
|
|
45
53
|
// relays `tiles-protocol-up-<protocol>-<kind>` from the tile to us, and
|
|
46
54
|
// `tiles-protocol-down-<protocol>-<kind>` from us to the tile.
|
|
47
55
|
const PROTOCOL_UP = 'tiles-protocol-up-';
|
|
48
56
|
const PROTOCOL_DOWN = 'tiles-protocol-down-';
|
|
57
|
+
// Warnings and errors come as a list; anything else is logged as it is.
|
|
58
|
+
const asList = (msg) => (Array.isArray(msg) ? msg : [msg]);
|
|
49
59
|
export class TileMothership {
|
|
50
60
|
#loaders = [];
|
|
51
61
|
#conf;
|
|
@@ -57,33 +67,47 @@ export class TileMothership {
|
|
|
57
67
|
init() {
|
|
58
68
|
window.addEventListener('message', async (ev) => {
|
|
59
69
|
const { action } = ev.data || {};
|
|
70
|
+
if (typeof action !== 'string')
|
|
71
|
+
return;
|
|
72
|
+
// Any frame can post a message, and say anything in it: the window
|
|
73
|
+
// it comes from says which tile is talking. That window is the tile's
|
|
74
|
+
// dock, on the loading server's origin, and it stays there; a message
|
|
75
|
+
// from one of our frames that is somewhere else is not from a dock.
|
|
76
|
+
// Messages still carry an id; we don't read it.
|
|
77
|
+
const id = this.#idForWindow(ev.source);
|
|
78
|
+
if (!id || ev.origin !== this.getLoadOrigin())
|
|
79
|
+
return;
|
|
80
|
+
const tile = this.#id2tile.get(id);
|
|
60
81
|
if (action === TILES_WARNING) {
|
|
61
|
-
|
|
62
|
-
console.warn(`[W:${id}]`, ...msg);
|
|
82
|
+
console.warn(`[W:${id}]`, ...asList(ev.data.msg));
|
|
63
83
|
}
|
|
64
|
-
if (action === TILES_ERROR) {
|
|
65
|
-
|
|
66
|
-
|
|
84
|
+
else if (action === TILES_ERROR) {
|
|
85
|
+
console.error(`[S:${id}]`, ...asList(ev.data.msg));
|
|
86
|
+
}
|
|
87
|
+
else if (action === RCV_DOCK_STOPPED) {
|
|
88
|
+
const reason = ev.data.payload?.reason === 'blocked' ? 'blocked' : 'navigated';
|
|
89
|
+
console.error(`[D:${id}] The tile's runtime tried to navigate (${reason}); the tile was stopped.`);
|
|
90
|
+
tile.dispatchEvent(Object.assign(new Event('stopped'), { reason }));
|
|
67
91
|
}
|
|
68
92
|
else if (action === RCV_SHUTTLE_READY) {
|
|
69
|
-
const { id } = ev.data;
|
|
70
93
|
this.sendToShuttle(id, SND_WORKER_LOAD, { id });
|
|
71
94
|
}
|
|
72
95
|
else if (action === RCV_WORKER_READY) {
|
|
73
|
-
const { id } = ev.data;
|
|
74
|
-
const tile = this.#id2tile.get(id);
|
|
75
|
-
if (!tile)
|
|
76
|
-
throw new Error(`No tile shuttle with ID ${id}`);
|
|
77
96
|
tile.dispatchEvent(new Event('load'));
|
|
78
97
|
}
|
|
79
98
|
else if (action === RCV_WORKER_REQUEST) {
|
|
80
|
-
const { type,
|
|
99
|
+
const { type, payload } = ev.data;
|
|
81
100
|
if (type === 'resolve-path') {
|
|
82
101
|
const { path, requestId } = payload;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
102
|
+
let res;
|
|
103
|
+
try {
|
|
104
|
+
res = await tile.resolvePath(path);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
// Answer all the same, or the worker waits for ever.
|
|
108
|
+
console.error(`Could not resolve ${path}:`, err);
|
|
109
|
+
res = { ok: false, status: 502, statusText: 'Bad Gateway' };
|
|
110
|
+
}
|
|
87
111
|
// Every document the worker serves, 404s included, carries the
|
|
88
112
|
// policy: the tile can script anything on its origin, so nothing
|
|
89
113
|
// on it may be unconfined.
|
|
@@ -93,12 +117,7 @@ export class TileMothership {
|
|
|
93
117
|
this.sendToShuttle(id, SND_WORKER_RESPONSE, { requestId, response });
|
|
94
118
|
}
|
|
95
119
|
}
|
|
96
|
-
else if (
|
|
97
|
-
// Protocol messages carry no id: the shuttle window they come from
|
|
98
|
-
// says which tile is talking, and nothing else gets to pretend.
|
|
99
|
-
const tile = this.tileForWindow(ev.source);
|
|
100
|
-
if (!tile)
|
|
101
|
-
return;
|
|
120
|
+
else if (action.startsWith(PROTOCOL_UP)) {
|
|
102
121
|
const rest = action.slice(PROTOCOL_UP.length);
|
|
103
122
|
const dash = rest.indexOf('-');
|
|
104
123
|
if (dash < 1)
|
|
@@ -107,11 +126,6 @@ export class TileMothership {
|
|
|
107
126
|
const kind = rest.slice(dash + 1);
|
|
108
127
|
const { payload } = ev.data;
|
|
109
128
|
tile.dispatchEvent(Object.assign(new Event('protocol'), { protocol, kind, payload }));
|
|
110
|
-
// Deprecated: tp-data also raised as events of its own, until the
|
|
111
|
-
// next major version (see @dasl/tile-loader/data).
|
|
112
|
-
if (protocol === 'data') {
|
|
113
|
-
tile.dispatchEvent(Object.assign(new Event(kind === 'payload' ? 'data' : `data-${kind}`), { payload }));
|
|
114
|
-
}
|
|
115
129
|
}
|
|
116
130
|
});
|
|
117
131
|
}
|
|
@@ -124,18 +138,26 @@ export class TileMothership {
|
|
|
124
138
|
return tileResponseHeaders(headers);
|
|
125
139
|
}
|
|
126
140
|
tileForWindow(source) {
|
|
141
|
+
const id = this.#idForWindow(source);
|
|
142
|
+
if (id)
|
|
143
|
+
return this.#id2tile.get(id);
|
|
144
|
+
}
|
|
145
|
+
#idForWindow(source) {
|
|
127
146
|
if (!source)
|
|
128
147
|
return;
|
|
129
148
|
for (const [id, ifr] of this.#id2shuttle) {
|
|
130
149
|
if (ifr.contentWindow === source)
|
|
131
|
-
return
|
|
150
|
+
return id;
|
|
132
151
|
}
|
|
133
152
|
}
|
|
134
153
|
sendToShuttle(id, action, payload) {
|
|
135
154
|
const ifr = this.#id2shuttle.get(id);
|
|
136
155
|
if (!ifr)
|
|
137
156
|
return console.error(`No shuttle for ID ${id}`);
|
|
138
|
-
|
|
157
|
+
// To the dock and no one else: should the frame ever be anywhere but on
|
|
158
|
+
// the loading server, what we say (the tile's documents, the host's
|
|
159
|
+
// data) does not go with it.
|
|
160
|
+
ifr.contentWindow?.postMessage({ id, action, payload }, this.getLoadOrigin());
|
|
139
161
|
}
|
|
140
162
|
registerShuttleFrame(ifr, tile) {
|
|
141
163
|
const id = crypto.randomUUID(); // we might want to make that pluggable
|
|
@@ -159,10 +181,20 @@ export class TileMothership {
|
|
|
159
181
|
removeLoader(loader) {
|
|
160
182
|
this.#loaders = this.#loaders.filter(ldr => ldr !== loader);
|
|
161
183
|
}
|
|
162
|
-
|
|
184
|
+
/** The origin of the loading server: where the dock is, and so who we talk to. */
|
|
185
|
+
getLoadOrigin() {
|
|
163
186
|
const domain = this.#conf.loadDomain || 'load.webtil.es';
|
|
164
|
-
|
|
165
|
-
|
|
187
|
+
return new URL(/^https?:\/\//.test(domain) ? domain : `https://${domain}`).origin;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* What a tile's frame loads: the dock, on the loading server. Asked like
|
|
191
|
+
* this it picks a fresh origin for the tile and frames the runtime there.
|
|
192
|
+
*/
|
|
193
|
+
getLoadSource() {
|
|
194
|
+
const url = new URL(dockPath, this.getLoadOrigin());
|
|
195
|
+
if (this.#conf.tileHost)
|
|
196
|
+
url.searchParams.set('tile', this.#conf.tileHost);
|
|
197
|
+
return url.href;
|
|
166
198
|
}
|
|
167
199
|
// Load a tile.
|
|
168
200
|
async loadTile(url) {
|
|
@@ -269,14 +301,6 @@ export class Tile extends EventTarget {
|
|
|
269
301
|
throw new Error('The tile is not rendered yet.');
|
|
270
302
|
this.#mothership.sendToShuttle(this.#shuttleId, `${PROTOCOL_DOWN}${protocol}-${kind}`, payload);
|
|
271
303
|
}
|
|
272
|
-
/**
|
|
273
|
-
* Sends a tp-data payload to the tile (https://dasl.ing/tp-data.html).
|
|
274
|
-
* @deprecated Goes in the next major version. Use `tileData(tile).send()`
|
|
275
|
-
* from `@dasl/tile-loader/data`, or `sendProtocol('data', 'payload', payload)`.
|
|
276
|
-
*/
|
|
277
|
-
sendData(payload) {
|
|
278
|
-
this.sendProtocol('data', 'payload', payload);
|
|
279
|
-
}
|
|
280
304
|
attachIframe(ifr) {
|
|
281
305
|
this.#shuttleId = this.#mothership.registerShuttleFrame(ifr, this);
|
|
282
306
|
ifr.addEventListener('load', () => this.#mothership.startShuttle(this.#shuttleId));
|