@celljs/ta-relay 4.13.0 → 4.14.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.
Files changed (58) hide show
  1. package/README.en.md +9 -1
  2. package/README.md +9 -1
  3. package/esm/common/index.d.ts +3 -0
  4. package/esm/common/index.js +3 -0
  5. package/esm/common/relay-friends.js +29 -4
  6. package/esm/common/relay-host-calls.d.ts +34 -0
  7. package/esm/common/relay-host-calls.js +126 -0
  8. package/esm/common/relay-hubs-connection.d.ts +9 -1
  9. package/esm/common/relay-hubs-connection.js +33 -1
  10. package/esm/common/relay-hubs-protocol.d.ts +9 -1
  11. package/esm/common/relay-hubs.d.ts +7 -0
  12. package/esm/common/relay-hubs.js +20 -3
  13. package/esm/common/relay-identity.d.ts +11 -0
  14. package/esm/common/relay-identity.js +12 -1
  15. package/esm/common/relay-protocol.d.ts +1 -1
  16. package/esm/common/relay-protocol.js +2 -1
  17. package/esm/common/relay-team.d.ts +144 -0
  18. package/esm/common/relay-team.js +200 -0
  19. package/esm/common/relay-web.d.ts +13 -0
  20. package/esm/common/relay-web.js +61 -0
  21. package/esm/join/join-i18n.d.ts +53 -0
  22. package/esm/join/join-i18n.js +103 -0
  23. package/esm/join/join.d.ts +1 -0
  24. package/esm/join/join.js +364 -0
  25. package/esm/node/relay-server.d.ts +7 -0
  26. package/esm/node/relay-server.js +28 -3
  27. package/esm/node/relay-viewer.d.ts +2 -0
  28. package/esm/node/relay-viewer.js +9 -4
  29. package/lib/common/index.d.ts +3 -0
  30. package/lib/common/index.js +3 -0
  31. package/lib/common/relay-friends.js +29 -4
  32. package/lib/common/relay-host-calls.d.ts +35 -0
  33. package/lib/common/relay-host-calls.js +130 -0
  34. package/lib/common/relay-hubs-connection.d.ts +9 -1
  35. package/lib/common/relay-hubs-connection.js +33 -1
  36. package/lib/common/relay-hubs-protocol.d.ts +9 -1
  37. package/lib/common/relay-hubs.d.ts +7 -0
  38. package/lib/common/relay-hubs.js +20 -3
  39. package/lib/common/relay-identity.d.ts +11 -0
  40. package/lib/common/relay-identity.js +12 -1
  41. package/lib/common/relay-protocol.d.ts +1 -1
  42. package/lib/common/relay-protocol.js +2 -1
  43. package/lib/common/relay-team.d.ts +145 -0
  44. package/lib/common/relay-team.js +204 -0
  45. package/lib/common/relay-web.d.ts +14 -0
  46. package/lib/common/relay-web.js +64 -0
  47. package/lib/join/join-i18n.d.ts +54 -0
  48. package/lib/join/join-i18n.js +106 -0
  49. package/lib/join/join.d.ts +2 -0
  50. package/lib/join/join.js +366 -0
  51. package/lib/node/relay-server.d.ts +7 -0
  52. package/lib/node/relay-server.js +27 -2
  53. package/lib/node/relay-viewer.d.ts +2 -0
  54. package/lib/node/relay-viewer.js +6 -1
  55. package/package.json +4 -4
  56. package/viewer/join.html +92 -0
  57. package/viewer/page.html +9 -9
  58. package/viewer/room.html +10 -10
@@ -0,0 +1,364 @@
1
+ var _a;
2
+ import { RELAY_WEB_PATH, RelayTeamJoining, RelayTeamLinkUtil, } from '../common/relay-team.js';
3
+ import { GUEST_STYLE } from '../guest/guest-style.js';
4
+ import { JoinI18n } from './join-i18n.js';
5
+ /*
6
+ * The page a link that invites into a Ta opens in a browser (docs/design/ta-team.md 8.3, 17): one without Ta asks to come
7
+ * in with a name, or signed in with an account of a provider the Ta signs in with (the provider sends the browser back
8
+ * here with a code, which only that Ta can use); once let in, the device sealed for this request alone opens Ta's web page of the relay (RELAY_WEB_PATH),
9
+ * which keeps it for this origin. The relay serves the page and forwards what it says, sealed end to end.
10
+ */
11
+ const { t } = JoinI18n;
12
+ const NAME_KEY = 'ta-join:name';
13
+ /** The page of Ta keeps the computers it signs in to here (HostUtil of @celljs/ta-web). */
14
+ const HOSTS_KEY = 'ta.hosts';
15
+ /** A sign-in on its way to the provider: the link and the name, which do not come back with the browser. */
16
+ const SIGN_IN_KEY = 'ta-join:sign-in';
17
+ function el(tag, className, text) {
18
+ const node = document.createElement(tag);
19
+ if (className) {
20
+ node.className = className;
21
+ }
22
+ if (text !== undefined) {
23
+ node.textContent = text;
24
+ }
25
+ return node;
26
+ }
27
+ function button(className, text, onClick) {
28
+ const node = el('button', className, text);
29
+ node.type = 'button';
30
+ node.addEventListener('click', onClick);
31
+ return node;
32
+ }
33
+ function read(key) {
34
+ try {
35
+ const text = localStorage.getItem(key);
36
+ return text ? JSON.parse(text) : undefined;
37
+ }
38
+ catch (_a) {
39
+ return undefined;
40
+ }
41
+ }
42
+ function write(key, value) {
43
+ try {
44
+ if (value === undefined) {
45
+ localStorage.removeItem(key);
46
+ }
47
+ else {
48
+ localStorage.setItem(key, typeof value === 'string' ? value : JSON.stringify(value));
49
+ }
50
+ }
51
+ catch (_a) {
52
+ // A browser that keeps nothing: this visit alone.
53
+ }
54
+ }
55
+ class JoinPage {
56
+ constructor(link) {
57
+ this.link = link;
58
+ this.ways = { providers: [], required: false };
59
+ this.pendingKey = `ta-join:${link.host}:${link.device}`;
60
+ this.owner = link.owner || 'Ta';
61
+ }
62
+ /** `back`: the browser came back from the provider, signed in (or with the error it said). */
63
+ start(back, handoff) {
64
+ const pending = read(this.pendingKey);
65
+ if (back === null || back === void 0 ? void 0 : back.handoff) {
66
+ void this.handBack(back);
67
+ }
68
+ else if (back) {
69
+ void this.back(back);
70
+ }
71
+ else if (handoff) {
72
+ void this.handOff(handoff);
73
+ }
74
+ else if ((pending === null || pending === void 0 ? void 0 : pending.request) && pending.keys) {
75
+ void this.wait(pending);
76
+ }
77
+ else if (this.joined()) {
78
+ this.joinedScreen();
79
+ }
80
+ else {
81
+ void this.open();
82
+ }
83
+ }
84
+ /** Asks the Ta how one says who they are, then the form. */
85
+ async open(error) {
86
+ this.frame(el('div', 'spin'));
87
+ this.ways = await this.connection().ways('web');
88
+ this.form(error);
89
+ }
90
+ connection() {
91
+ var _a;
92
+ (_a = this.joining) !== null && _a !== void 0 ? _a : (this.joining = new RelayTeamJoining(this.link));
93
+ return this.joining;
94
+ }
95
+ async back({ signIn, name, error }) {
96
+ if (!signIn) {
97
+ await this.open(t('signInFailed', { reason: error !== null && error !== void 0 ? error : '' }));
98
+ return;
99
+ }
100
+ this.frame(el('div', 'spin'), el('h1', 'room-name', t('checking')));
101
+ try {
102
+ this.ways = await this.connection().ways('web');
103
+ await this.ask(name !== null && name !== void 0 ? name : '', signIn);
104
+ }
105
+ catch (failure) {
106
+ this.form(this.reason(failure));
107
+ }
108
+ }
109
+ /** Signing in for the Ta app that opened this page: straight to the provider, the Ta giving where. */
110
+ async handOff({ provider, handoff }) {
111
+ var _a;
112
+ this.frame(el('div', 'spin'), el('h1', 'room-name', t('signingIn')));
113
+ try {
114
+ const { url, state } = await this.connection().signIn(provider, handoff);
115
+ write(SIGN_IN_KEY, { state, href: RelayTeamLinkUtil.format(this.link), name: '', handoff });
116
+ (_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
117
+ location.replace(url);
118
+ }
119
+ catch (failure) {
120
+ this.frame(...this.heading(), el('p', 'error', this.reason(failure)));
121
+ }
122
+ }
123
+ /** Back from the provider, signed in for the Ta app: the Ta verifies it, and the app goes on. */
124
+ async handBack({ signIn, error }) {
125
+ var _a;
126
+ if (!signIn || !('code' in signIn)) {
127
+ this.frame(...this.heading(), el('p', 'error', t('signInFailed', { reason: error !== null && error !== void 0 ? error : '' })));
128
+ return;
129
+ }
130
+ this.frame(el('div', 'spin'), el('h1', 'room-name', t('checking')));
131
+ try {
132
+ const { account } = await this.connection().signedIn(signIn.state, signIn.code);
133
+ (_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
134
+ this.frame(el('div', 'done-mark', '✓'), el('h1', 'room-name', t('handedOff', { who: account.name || account.id })), el('p', 'hint', t('backToApp', { owner: this.owner })));
135
+ }
136
+ catch (failure) {
137
+ this.frame(...this.heading(), el('p', 'error', this.reason(failure)));
138
+ }
139
+ }
140
+ /** To the provider, which sends the browser back to this page with a code. */
141
+ async signIn(provider, name) {
142
+ var _a;
143
+ const { url, state } = await this.connection().signIn(provider);
144
+ write(SIGN_IN_KEY, { state, href: location.href, name });
145
+ (_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
146
+ location.assign(url);
147
+ }
148
+ /** This browser is let into that Ta already: Ta's page keeps it among its computers. */
149
+ joined() {
150
+ var _a;
151
+ const hosts = read(HOSTS_KEY);
152
+ return !!((_a = hosts === null || hosts === void 0 ? void 0 : hosts.hosts) === null || _a === void 0 ? void 0 : _a.some(host => host.id === `relay ${this.link.relay} ${this.link.host}`));
153
+ }
154
+ frame(...children) {
155
+ const logo = el('span', 'logo', 'Ta');
156
+ const heading = el('div', 'heading');
157
+ heading.append(el('b', undefined, t('title')));
158
+ const top = el('div', 'top');
159
+ top.append(logo, heading);
160
+ const center = el('div', 'center');
161
+ center.append(...children);
162
+ const app = el('div', 'app');
163
+ app.append(top, center);
164
+ document.body.replaceChildren(app);
165
+ }
166
+ heading() {
167
+ const nodes = [el('p', 'lead', t('invited', { owner: this.owner })), el('h1', 'room-name', this.owner)];
168
+ const chips = el('div', 'chips');
169
+ if (this.link.role) {
170
+ chips.append(el('span', 'chip', t('role', { role: JoinI18n.role(this.link.role) })));
171
+ }
172
+ if (this.link.what) {
173
+ chips.append(el('span', 'chip', t('what', { what: this.link.what })));
174
+ }
175
+ if (chips.childElementCount) {
176
+ nodes.push(chips);
177
+ }
178
+ return nodes;
179
+ }
180
+ form(error) {
181
+ var _a;
182
+ document.title = t('title');
183
+ const { providers, required } = this.ways;
184
+ const field = el('input', 'text');
185
+ field.placeholder = t('namePlaceholder');
186
+ field.maxLength = 40;
187
+ field.enterKeyHint = 'go';
188
+ field.value = (_a = localStorage.getItem(NAME_KEY)) !== null && _a !== void 0 ? _a : '';
189
+ const label = el('label', 'field');
190
+ label.append(t('name'), field);
191
+ const buttons = [];
192
+ const busy = (on) => {
193
+ for (const one of buttons) {
194
+ one.disabled = on;
195
+ }
196
+ };
197
+ const ask = button('primary', t('join'), () => void submit());
198
+ const submit = async () => {
199
+ const name = field.value.trim();
200
+ if (!name) {
201
+ field.focus();
202
+ return;
203
+ }
204
+ busy(true);
205
+ ask.textContent = t('joining');
206
+ write(NAME_KEY, name);
207
+ try {
208
+ await this.ask(name);
209
+ }
210
+ catch (failure) {
211
+ this.form(this.reason(failure));
212
+ }
213
+ };
214
+ field.addEventListener('keydown', event => {
215
+ if (event.key === 'Enter' && !event.isComposing) {
216
+ void submit();
217
+ }
218
+ });
219
+ const accounts = providers.map(provider => {
220
+ const one = button(required ? 'primary' : 'plain', t('signInWith', { provider: JoinI18n.provider(provider) }), () => {
221
+ busy(true);
222
+ one.textContent = t('signingIn');
223
+ this.signIn(provider.id, field.value.trim()).catch(failure => this.form(this.reason(failure)));
224
+ });
225
+ return one;
226
+ });
227
+ buttons.push(ask, ...accounts);
228
+ const signIns = el('div', 'accounts');
229
+ signIns.append(...accounts);
230
+ this.frame(...this.heading(), el('p', 'hint', required ? t('needAccount', { owner: this.owner }) : t('hint', { owner: this.owner })), ...(required ? [] : [label]), ...(error ? [el('p', 'error', error)] : []), ...(required ? [] : [ask]), ...(accounts.length && !required ? [el('p', 'or', t('or'))] : []), ...(accounts.length ? [signIns] : []), el('p', 'small', accounts.length ? t('keepAccount') : t('keep')), el('p', 'small', t('haveTa')));
231
+ if (!required && !matchMedia('(pointer: coarse)').matches) {
232
+ field.focus();
233
+ }
234
+ }
235
+ reason(failure) {
236
+ const message = failure instanceof Error ? failure.message : String(failure);
237
+ return /did not answer|is it running|lost/i.test(message) ? t('unreachable', { owner: this.owner }) : t('failed', { reason: message });
238
+ }
239
+ async ask(name, signIn) {
240
+ var _a;
241
+ const joining = this.connection();
242
+ const answer = await joining.ask(name, 'web', signIn);
243
+ if (answer.status === 'refused' && answer.reason === 'account') {
244
+ this.ways = { ...this.ways, required: true };
245
+ this.form();
246
+ return;
247
+ }
248
+ if (answer.status === 'refused' && answer.reason === 'app') {
249
+ joining.close();
250
+ this.joining = undefined;
251
+ this.message(answer.reason);
252
+ return;
253
+ }
254
+ const request = (_a = answer.request) !== null && _a !== void 0 ? _a : '';
255
+ const keys = joining.keys;
256
+ if (answer.status === 'waiting') {
257
+ write(this.pendingKey, { request, keys });
258
+ }
259
+ await this.settle(joining, request, answer);
260
+ }
261
+ /** Waits for the answer to a request asked before, in this tab or one closed since. */
262
+ async wait(pending) {
263
+ const joining = new RelayTeamJoining(this.link);
264
+ this.joining = joining;
265
+ joining.resume(pending.keys);
266
+ try {
267
+ await this.settle(joining, pending.request, { status: 'waiting' });
268
+ }
269
+ catch (failure) {
270
+ this.waitingScreen(this.reason(failure), pending);
271
+ }
272
+ }
273
+ async settle(joining, request, first) {
274
+ let answer = first;
275
+ if (answer.status === 'waiting') {
276
+ this.waitingScreen();
277
+ answer = await joining.wait(request);
278
+ }
279
+ if (answer.status === 'accepted' && answer.answer) {
280
+ this.frame(el('div', 'spin'), el('h1', 'room-name', t('connecting')));
281
+ const pairing = await joining.pairing(request, answer.answer);
282
+ joining.close();
283
+ write(this.pendingKey, undefined);
284
+ // To Ta's page, which takes the device out of the address and keeps it for this origin.
285
+ location.replace(RelayTeamLinkUtil.web(location.origin, pairing));
286
+ return;
287
+ }
288
+ joining.close();
289
+ this.joining = undefined;
290
+ write(this.pendingKey, undefined);
291
+ this.message(answer.status === 'refused' ? 'refused' : 'gone');
292
+ }
293
+ waitingScreen(error, pending) {
294
+ const cancel = button('plain', t('cancel'), () => {
295
+ var _a;
296
+ (_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
297
+ this.joining = undefined;
298
+ write(this.pendingKey, undefined);
299
+ void this.open();
300
+ });
301
+ const again = pending ? [button('primary', t('again'), () => void this.wait(pending))] : [];
302
+ this.frame(el('div', 'spin'), el('h1', 'room-name', t('waiting', { owner: this.owner })), el('p', 'hint', t('waitingHint')), ...(error ? [el('p', 'error', error)] : []), ...again, cancel);
303
+ }
304
+ message(text) {
305
+ const again = text === 'refused' ? [button('primary', t('again'), () => void this.open())] : [];
306
+ this.frame(...this.heading(), el('p', text === 'app' ? 'hint' : 'error', t(text, { owner: this.owner })), ...again);
307
+ }
308
+ joinedScreen() {
309
+ this.frame(...this.heading(), el('p', 'hint', t('joined', { owner: this.owner })), button('primary', t('open'), () => location.assign(RELAY_WEB_PATH)));
310
+ }
311
+ }
312
+ const style = document.createElement('style');
313
+ style.textContent = `${GUEST_STYLE}
314
+ .chips{display:flex;flex-wrap:wrap;justify-content:center;gap:6px}
315
+ .chip{padding:3px 10px;border-radius:999px;background:var(--soft);color:var(--muted);font-size:12.5px}
316
+ .accounts{display:flex;flex-direction:column;gap:8px;width:100%}
317
+ .accounts .plain{width:100%;padding:11px 14px;border:1px solid var(--line);border-radius:12px;color:var(--fg);font-weight:500}
318
+ .or{margin:2px 0;color:var(--muted);font-size:12.5px;text-align:center}
319
+ .done-mark{align-self:center;margin:0 auto;width:44px;height:44px;border-radius:50%;display:grid;place-items:center;background:var(--soft);color:var(--accent,#16a34a);font-size:22px;font-weight:600}
320
+ `;
321
+ document.head.append(style);
322
+ /**
323
+ * Back from the provider: `/j?code=…&state=…` (or `?error=…`), the link being in the sign-in kept before it went; the
324
+ * address is the link's again, without the code.
325
+ */
326
+ function cameBack() {
327
+ var _a, _b;
328
+ const query = new URLSearchParams(location.search);
329
+ const state = query.get('state');
330
+ if (!state) {
331
+ return undefined;
332
+ }
333
+ const kept = read(SIGN_IN_KEY);
334
+ write(SIGN_IN_KEY, undefined);
335
+ const link = (kept === null || kept === void 0 ? void 0 : kept.state) === state ? RelayTeamLinkUtil.parse(kept.href) : undefined;
336
+ if (!kept || !link) {
337
+ return undefined;
338
+ }
339
+ history.replaceState(null, '', new URL(kept.href).pathname + new URL(kept.href).hash);
340
+ const code = query.get('code');
341
+ return {
342
+ link,
343
+ back: {
344
+ ...(code ? { signIn: { state, code }, name: kept.name } : { error: (_b = (_a = query.get('error_description')) !== null && _a !== void 0 ? _a : query.get('error')) !== null && _b !== void 0 ? _b : '' }),
345
+ ...(kept.handoff ? { handoff: true } : {}),
346
+ },
347
+ };
348
+ }
349
+ const back = cameBack();
350
+ const link = (_a = back === null || back === void 0 ? void 0 : back.link) !== null && _a !== void 0 ? _a : RelayTeamLinkUtil.parse(location.href);
351
+ if (link) {
352
+ // The fragment's sign-in for the Ta app goes once: opened again, the page is the link's.
353
+ const handoff = back ? undefined : RelayTeamLinkUtil.handoffOf(location.href);
354
+ if (handoff) {
355
+ history.replaceState(null, '', location.pathname + RelayTeamLinkUtil.format(link).slice(RelayTeamLinkUtil.format(link).indexOf('#')));
356
+ }
357
+ new JoinPage(link).start(back === null || back === void 0 ? void 0 : back.back, handoff);
358
+ }
359
+ else {
360
+ const center = el('div', 'center');
361
+ center.append(el('p', 'error', t('invalid')));
362
+ document.body.replaceChildren(center);
363
+ }
364
+ //# sourceMappingURL=join.js.map
@@ -14,6 +14,11 @@ export interface RelayServerOptions {
14
14
  * (`ta relay --data <dir>`); without it, in memory for as long as it runs.
15
15
  */
16
16
  data?: string;
17
+ /**
18
+ * The files of Ta's web page (`apps/ta/dist/public`), served under RELAY_WEB_PATH for those let in from a browser
19
+ * (`ta relay` gives its own); without it, a link that invites still asks from a browser, but leads nowhere.
20
+ */
21
+ web?: string;
17
22
  }
18
23
  interface Room {
19
24
  secretHash: string;
@@ -82,6 +87,8 @@ export declare class RelayServer {
82
87
  protected server?: Server;
83
88
  constructor(options?: RelayServerOptions);
84
89
  listen(): Promise<string>;
90
+ /** A file of Ta's web page (RelayWebUtil), from the directory of the options. */
91
+ protected web(path: string, response: ServerResponse): void;
85
92
  close(): Promise<void>;
86
93
  /** A copy of content (RelayBlobs), kept in memory for as long as the relay runs. */
87
94
  protected blob(id: string, request: IncomingMessage, response: ServerResponse): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
2
- import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
2
+ import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
3
3
  import { createServer } from 'node:http';
4
4
  import { join } from 'node:path';
5
5
  import { WebSocketConnection } from '@celljs/rpc/lib/node/websocket/websocket-connection';
@@ -9,6 +9,8 @@ import { RELAY_INFO_PATH, RelayInfoUtil } from '../common/relay-info.js';
9
9
  import { RELAY_BLOB_PATH, RELAY_CONNECT_PATH, RELAY_CONTENT_PATH, RELAY_FRAME_HEADER_CSP, RELAY_FRAME_PATH, RELAY_HOST_PATH, RELAY_HUB_PATH, RELAY_ID, RELAY_PAIR_PAGE, RELAY_PAIR_PATH, RELAY_ROOM_PATH, RELAY_SHARE_PAGE, RELAY_SHARE_PATH, RELAY_VIEWER_HEADERS, RelayCloseCode, } from '../common/relay-protocol.js';
10
10
  import { RelayRoom } from '../common/relay-room.js';
11
11
  import { RELAY_SPOT_PATH, RelaySpot, RelaySpotCloseCode, RelaySpotTries } from '../common/relay-spot.js';
12
+ import { RELAY_JOIN_PATH, RELAY_WEB_PATH } from '../common/relay-team.js';
13
+ import { RelayWebUtil } from '../common/relay-web.js';
12
14
  import { FileRelayStorage } from './relay-file-storage.js';
13
15
  import { RelayViewer } from './relay-viewer.js';
14
16
  const WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
@@ -130,9 +132,13 @@ export class RelayServer {
130
132
  });
131
133
  return;
132
134
  }
133
- if (path === RELAY_ROOM_PATH) {
135
+ if (path === RELAY_ROOM_PATH || path === RELAY_JOIN_PATH) {
134
136
  response.writeHead(200, { ...RELAY_VIEWER_HEADERS, 'x-frame-options': 'DENY' });
135
- response.end(RelayViewer.room());
137
+ response.end(path === RELAY_ROOM_PATH ? RelayViewer.room() : RelayViewer.join());
138
+ return;
139
+ }
140
+ if (path.startsWith(RELAY_WEB_PATH) || path === RELAY_WEB_PATH.slice(0, -1)) {
141
+ this.web(path, response);
136
142
  return;
137
143
  }
138
144
  if (path === RELAY_CONTENT_PATH || path === RELAY_FRAME_PATH) {
@@ -159,6 +165,25 @@ export class RelayServer {
159
165
  });
160
166
  });
161
167
  }
168
+ /** A file of Ta's web page (RelayWebUtil), from the directory of the options. */
169
+ web(path, response) {
170
+ var _a;
171
+ if (path === RELAY_WEB_PATH.slice(0, -1)) {
172
+ response.writeHead(308, { location: RELAY_WEB_PATH });
173
+ response.end();
174
+ return;
175
+ }
176
+ const file = RelayWebUtil.file(path);
177
+ const full = file && this.options.web ? join(this.options.web, file) : undefined;
178
+ if (!file || !full || !((_a = statSync(full, { throwIfNoEntry: false })) === null || _a === void 0 ? void 0 : _a.isFile())) {
179
+ response.writeHead(404, { 'content-type': 'text/plain' });
180
+ response.end('Not found.\n');
181
+ return;
182
+ }
183
+ const body = readFileSync(full);
184
+ response.writeHead(200, RelayWebUtil.headers(file));
185
+ response.end(file === 'index.html' ? RelayWebUtil.index(body.toString('utf8')) : body);
186
+ }
162
187
  close() {
163
188
  var _a, _b, _c, _d, _e;
164
189
  for (const { sockets } of this.hubs.values()) {
@@ -2,6 +2,8 @@
2
2
  export declare namespace RelayViewer {
3
3
  /** The page of guests of rooms: a link that invites, opened in a browser. */
4
4
  function room(): string;
5
+ /** The page of a link that invites into a Ta, opened in a browser. */
6
+ function join(): string;
5
7
  function page(): string;
6
8
  function frame(): string;
7
9
  }
@@ -3,16 +3,16 @@ import { dirname as __cellDirname } from "node:path";
3
3
  const __filename = __cellFileURLToPath(import.meta.url);
4
4
  const __dirname = __cellDirname(__filename);
5
5
  import { readFileSync } from 'node:fs';
6
- import { join } from 'node:path';
6
+ import { join as joinPath } from 'node:path';
7
7
  /** The viewer of the relay as `ta relay` serves it: the pages scripts/build-viewer.ts built, next to lib/. */
8
8
  export var RelayViewer;
9
9
  (function (RelayViewer) {
10
10
  let pages;
11
11
  function read() {
12
12
  if (!pages) {
13
- const dir = join(__dirname, '../../viewer');
14
- const file = (name) => readFileSync(join(dir, name), 'utf8');
15
- pages = { page: file('page.html'), frame: file('frame.html'), room: file('room.html') };
13
+ const dir = joinPath(__dirname, '../../viewer');
14
+ const file = (name) => readFileSync(joinPath(dir, name), 'utf8');
15
+ pages = { page: file('page.html'), frame: file('frame.html'), room: file('room.html'), join: file('join.html') };
16
16
  }
17
17
  return pages;
18
18
  }
@@ -21,6 +21,11 @@ export var RelayViewer;
21
21
  return read().room;
22
22
  }
23
23
  RelayViewer.room = room;
24
+ /** The page of a link that invites into a Ta, opened in a browser. */
25
+ function join() {
26
+ return read().join;
27
+ }
28
+ RelayViewer.join = join;
24
29
  function page() {
25
30
  return read().page;
26
31
  }
@@ -8,6 +8,7 @@ export * from './relay-conversation';
8
8
  export * from './relay-faces';
9
9
  export * from './relay-files';
10
10
  export * from './relay-friends';
11
+ export * from './relay-host-calls';
11
12
  export * from './relay-hub';
12
13
  export * from './relay-hub-util';
13
14
  export * from './relay-hubs';
@@ -21,4 +22,6 @@ export * from './relay-room-chat';
21
22
  export * from './relay-share';
22
23
  export * from './relay-socket';
23
24
  export * from './relay-spot';
25
+ export * from './relay-team';
26
+ export * from './relay-web';
24
27
  //# sourceMappingURL=index.d.ts.map
@@ -24,6 +24,7 @@ __exportStar(require("./relay-conversation"), exports);
24
24
  __exportStar(require("./relay-faces"), exports);
25
25
  __exportStar(require("./relay-files"), exports);
26
26
  __exportStar(require("./relay-friends"), exports);
27
+ __exportStar(require("./relay-host-calls"), exports);
27
28
  __exportStar(require("./relay-hub"), exports);
28
29
  __exportStar(require("./relay-hub-util"), exports);
29
30
  __exportStar(require("./relay-hubs"), exports);
@@ -37,4 +38,6 @@ __exportStar(require("./relay-room-chat"), exports);
37
38
  __exportStar(require("./relay-share"), exports);
38
39
  __exportStar(require("./relay-socket"), exports);
39
40
  __exportStar(require("./relay-spot"), exports);
41
+ __exportStar(require("./relay-team"), exports);
42
+ __exportStar(require("./relay-web"), exports);
40
43
  //# sourceMappingURL=index.js.map
@@ -120,7 +120,13 @@ class RelayFriends {
120
120
  ? this.rooms
121
121
  .asksOf(mine.id)
122
122
  .filter(ask => !ask.guest && !chosen.has(ask.id))
123
- .map(ask => ({ id: ask.id, name: ask.name, at: ask.at, via: 'link' }))
123
+ .map(ask => ({
124
+ id: ask.id,
125
+ name: ask.name,
126
+ ...(relay_identity_1.RelayIdentityUtil.isLook(ask.look) ? { look: ask.look } : {}),
127
+ at: ask.at,
128
+ via: 'link',
129
+ }))
124
130
  : [];
125
131
  const offers = book.offers.filter(offer => !chosen.has(offer.id) && !asks.some(ask => ask.id === offer.id)).map(RelayFriendsUtil.requestOf);
126
132
  return [...asks, ...offers].sort((a, b) => a.at - b.at);
@@ -129,7 +135,10 @@ class RelayFriends {
129
135
  asked(ask) {
130
136
  if (!ask.guest && !this.read().friends.some(friend => friend.id === ask.id) && !this.told.has(ask.member)) {
131
137
  this.told.add(ask.member);
132
- this.emit({ type: 'friend', request: { id: ask.id, name: ask.name, at: ask.at, via: 'link' } });
138
+ this.emit({
139
+ type: 'friend',
140
+ request: { id: ask.id, name: ask.name, ...(relay_identity_1.RelayIdentityUtil.isLook(ask.look) ? { look: ask.look } : {}), at: ask.at, via: 'link' },
141
+ });
133
142
  this.emit({ type: 'rooms' });
134
143
  }
135
144
  this.changed();
@@ -177,12 +186,14 @@ class RelayFriends {
177
186
  const mine = rooms.find(room => room.owner && room.kind === exports.RELAY_FRIENDS_KIND);
178
187
  return this.read()
179
188
  .friends.map(friend => {
189
+ var _a, _b;
180
190
  const member = mine === null || mine === void 0 ? void 0 : mine.members.find(item => item.id === friend.id && !item.owner);
181
191
  const theirs = this.theirs(rooms, friend.id);
182
192
  const owner = theirs === null || theirs === void 0 ? void 0 : theirs.members.find(item => item.owner);
183
193
  return {
184
194
  id: friend.id,
185
195
  name: (member === null || member === void 0 ? void 0 : member.name) || (owner === null || owner === void 0 ? void 0 : owner.name) || friend.name,
196
+ ...(relay_identity_1.RelayIdentityUtil.isLook(((_a = member !== null && member !== void 0 ? member : owner) !== null && _a !== void 0 ? _a : friend).look) ? { look: ((_b = member !== null && member !== void 0 ? member : owner) !== null && _b !== void 0 ? _b : friend).look } : {}),
186
197
  status: member && (theirs === null || theirs === void 0 ? void 0 : theirs.status) === 'member' ? 'friend' : 'adding',
187
198
  online: !!(member === null || member === void 0 ? void 0 : member.online) || !!(owner === null || owner === void 0 ? void 0 : owner.online),
188
199
  metAt: friend.metAt,
@@ -209,7 +220,13 @@ class RelayFriends {
209
220
  const now = Date.now();
210
221
  for (const member of members) {
211
222
  const known = book.friends.find(friend => friend.id === member.id);
212
- if (known && (known.name !== member.name || known.sign !== member.sign || known.box !== member.box || now - known.seenAt > DAY_MS)) {
223
+ if (known &&
224
+ (known.name !== member.name ||
225
+ known.look !== member.look ||
226
+ known.sign !== member.sign ||
227
+ known.box !== member.box ||
228
+ now - known.seenAt > DAY_MS)) {
229
+ delete known.look;
213
230
  Object.assign(known, relay_identity_1.RelayIdentityUtil.publicOf(member), { seenAt: now });
214
231
  changed = true;
215
232
  }
@@ -407,6 +424,7 @@ var RelayFriendsUtil;
407
424
  return {
408
425
  id: friend.id,
409
426
  name: String((_a = friend.name) !== null && _a !== void 0 ? _a : '').slice(0, 40),
427
+ ...(relay_identity_1.RelayIdentityUtil.isLook(friend.look) ? { look: friend.look } : {}),
410
428
  ...(typeof friend.sign === 'string' ? { sign: friend.sign } : {}),
411
429
  ...(typeof friend.box === 'string' ? { box: friend.box } : {}),
412
430
  metAt: friend.metAt,
@@ -429,7 +447,14 @@ var RelayFriendsUtil;
429
447
  }
430
448
  RelayFriendsUtil.mergeFriend = mergeFriend;
431
449
  function requestOf(offer) {
432
- return { id: offer.id, name: offer.name, at: offer.at, via: 'room', room: offer.room };
450
+ return {
451
+ id: offer.id,
452
+ name: offer.name,
453
+ ...(relay_identity_1.RelayIdentityUtil.isLook(offer.look) ? { look: offer.look } : {}),
454
+ at: offer.at,
455
+ via: 'room',
456
+ room: offer.room,
457
+ };
433
458
  }
434
459
  RelayFriendsUtil.requestOf = requestOf;
435
460
  /** `friends.json` as it is now: those of before kept only if they were Moments friends (see migrate). */
@@ -0,0 +1,35 @@
1
+ import { type RelayPairing } from './relay-pairing';
2
+ import { RelaySocket } from './relay-socket';
3
+ /**
4
+ * Calls of the host of a package on another Ta, through the relay with a device of it (end to end): asking to come in
5
+ * with the device of a link (RelayTeamJoining), or reading what is shared with the user there from their own Ta. The
6
+ * other Ta checks every call as it does those of its pages.
7
+ */
8
+ export declare class RelayHostCalls {
9
+ protected readonly pairing: RelayPairing;
10
+ /** The package whose host is called. */
11
+ protected readonly name: string;
12
+ protected socket?: RelaySocket;
13
+ protected opening?: Promise<void>;
14
+ protected next: number;
15
+ protected readonly calls: Map<number, {
16
+ resolve(value: unknown): void;
17
+ reject(error: Error): void;
18
+ timer: ReturnType<typeof setTimeout>;
19
+ }>;
20
+ protected closed: boolean;
21
+ constructor(pairing: RelayPairing,
22
+ /** The package whose host is called. */
23
+ name: string);
24
+ /** From the pairing link of a device. */
25
+ static of(link: string, name: string): RelayHostCalls;
26
+ open(): Promise<void>;
27
+ /** Opens, again after a pause when the connection drops before it opened (not when the other Ta refused the device). */
28
+ protected tryOpen(tries: number): Promise<void>;
29
+ protected openOnce(): Promise<void>;
30
+ callHost(method: string, ...params: unknown[]): Promise<unknown>;
31
+ close(): void;
32
+ protected failAll(error: Error): void;
33
+ protected receive(data: string): void;
34
+ }
35
+ //# sourceMappingURL=relay-host-calls.d.ts.map