@celljs/ta-relay 4.13.1 → 4.15.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.en.md +9 -1
- package/README.md +9 -1
- package/esm/common/index.d.ts +3 -0
- package/esm/common/index.js +3 -0
- package/esm/common/page-language.d.ts +14 -0
- package/esm/common/page-language.js +27 -0
- package/esm/common/relay-friends.js +29 -4
- package/esm/common/relay-host-calls.d.ts +34 -0
- package/esm/common/relay-host-calls.js +126 -0
- package/esm/common/relay-hubs-connection.d.ts +9 -1
- package/esm/common/relay-hubs-connection.js +33 -1
- package/esm/common/relay-hubs-protocol.d.ts +9 -1
- package/esm/common/relay-hubs.d.ts +7 -0
- package/esm/common/relay-hubs.js +20 -3
- package/esm/common/relay-identity.d.ts +11 -0
- package/esm/common/relay-identity.js +12 -1
- package/esm/common/relay-protocol.d.ts +1 -1
- package/esm/common/relay-protocol.js +2 -1
- package/esm/common/relay-team.d.ts +169 -0
- package/esm/common/relay-team.js +248 -0
- package/esm/common/relay-web.d.ts +13 -0
- package/esm/common/relay-web.js +61 -0
- package/esm/guest/guest-i18n.d.ts +6 -1
- package/esm/guest/guest-i18n.js +98 -5
- package/esm/guest/guest.js +1 -1
- package/esm/join/join-i18n.d.ts +65 -0
- package/esm/join/join-i18n.js +233 -0
- package/esm/join/join.d.ts +1 -0
- package/esm/join/join.js +433 -0
- package/esm/node/relay-server.d.ts +7 -0
- package/esm/node/relay-server.js +28 -3
- package/esm/node/relay-viewer.d.ts +2 -0
- package/esm/node/relay-viewer.js +9 -4
- package/esm/viewer/viewer-i18n.d.ts +6 -1
- package/esm/viewer/viewer-i18n.js +107 -3
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.js +3 -0
- package/lib/common/page-language.d.ts +15 -0
- package/lib/common/page-language.js +31 -0
- package/lib/common/relay-friends.js +29 -4
- package/lib/common/relay-host-calls.d.ts +35 -0
- package/lib/common/relay-host-calls.js +130 -0
- package/lib/common/relay-hubs-connection.d.ts +9 -1
- package/lib/common/relay-hubs-connection.js +33 -1
- package/lib/common/relay-hubs-protocol.d.ts +9 -1
- package/lib/common/relay-hubs.d.ts +7 -0
- package/lib/common/relay-hubs.js +20 -3
- package/lib/common/relay-identity.d.ts +11 -0
- package/lib/common/relay-identity.js +12 -1
- package/lib/common/relay-protocol.d.ts +1 -1
- package/lib/common/relay-protocol.js +2 -1
- package/lib/common/relay-team.d.ts +170 -0
- package/lib/common/relay-team.js +252 -0
- package/lib/common/relay-web.d.ts +14 -0
- package/lib/common/relay-web.js +64 -0
- package/lib/guest/guest-i18n.d.ts +6 -1
- package/lib/guest/guest-i18n.js +99 -6
- package/lib/guest/guest.js +1 -1
- package/lib/join/join-i18n.d.ts +66 -0
- package/lib/join/join-i18n.js +236 -0
- package/lib/join/join.d.ts +2 -0
- package/lib/join/join.js +435 -0
- package/lib/node/relay-server.d.ts +7 -0
- package/lib/node/relay-server.js +27 -2
- package/lib/node/relay-viewer.d.ts +2 -0
- package/lib/node/relay-viewer.js +6 -1
- package/lib/viewer/viewer-i18n.d.ts +6 -1
- package/lib/viewer/viewer-i18n.js +108 -4
- package/package.json +4 -4
- package/viewer/join.html +93 -0
- package/viewer/page.html +9 -9
- package/viewer/room.html +10 -10
package/lib/join/join.js
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const relay_team_1 = require("../common/relay-team");
|
|
5
|
+
const guest_style_1 = require("../guest/guest-style");
|
|
6
|
+
const join_i18n_1 = require("./join-i18n");
|
|
7
|
+
/*
|
|
8
|
+
* 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
|
|
9
|
+
* in with a name, or signed in with an account of a provider the Ta signs in with (the provider sends the browser back
|
|
10
|
+
* 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),
|
|
11
|
+
* which keeps it for this origin. The relay serves the page and forwards what it says, sealed end to end.
|
|
12
|
+
*/
|
|
13
|
+
const { t } = join_i18n_1.JoinI18n;
|
|
14
|
+
const NAME_KEY = 'ta-join:name';
|
|
15
|
+
/** The page of Ta keeps the computers it signs in to here (HostUtil of @celljs/ta-web). */
|
|
16
|
+
const HOSTS_KEY = 'ta.hosts';
|
|
17
|
+
/** A sign-in on its way to the provider: the link and the name, which do not come back with the browser. */
|
|
18
|
+
const SIGN_IN_KEY = 'ta-join:sign-in';
|
|
19
|
+
function el(tag, className, text) {
|
|
20
|
+
const node = document.createElement(tag);
|
|
21
|
+
if (className) {
|
|
22
|
+
node.className = className;
|
|
23
|
+
}
|
|
24
|
+
if (text !== undefined) {
|
|
25
|
+
node.textContent = text;
|
|
26
|
+
}
|
|
27
|
+
return node;
|
|
28
|
+
}
|
|
29
|
+
function button(className, text, onClick) {
|
|
30
|
+
const node = el('button', className, text);
|
|
31
|
+
node.type = 'button';
|
|
32
|
+
node.addEventListener('click', onClick);
|
|
33
|
+
return node;
|
|
34
|
+
}
|
|
35
|
+
function read(key) {
|
|
36
|
+
try {
|
|
37
|
+
const text = localStorage.getItem(key);
|
|
38
|
+
return text ? JSON.parse(text) : undefined;
|
|
39
|
+
}
|
|
40
|
+
catch (_a) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function write(key, value) {
|
|
45
|
+
try {
|
|
46
|
+
if (value === undefined) {
|
|
47
|
+
localStorage.removeItem(key);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
localStorage.setItem(key, typeof value === 'string' ? value : JSON.stringify(value));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (_a) {
|
|
54
|
+
// A browser that keeps nothing: this visit alone.
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class JoinPage {
|
|
58
|
+
constructor(link) {
|
|
59
|
+
this.link = link;
|
|
60
|
+
this.ways = { providers: [], required: false };
|
|
61
|
+
this.pendingKey = `ta-join:${link.host}:${link.device}`;
|
|
62
|
+
this.owner = link.owner || 'Ta';
|
|
63
|
+
}
|
|
64
|
+
/** `back`: the browser came back from the provider, signed in (or with the error it said). */
|
|
65
|
+
start(back, handoff) {
|
|
66
|
+
const pending = read(this.pendingKey);
|
|
67
|
+
if (back === null || back === void 0 ? void 0 : back.handoff) {
|
|
68
|
+
void this.handBack(back);
|
|
69
|
+
}
|
|
70
|
+
else if (back) {
|
|
71
|
+
void this.back(back);
|
|
72
|
+
}
|
|
73
|
+
else if (handoff) {
|
|
74
|
+
void this.handOff(handoff);
|
|
75
|
+
}
|
|
76
|
+
else if ((pending === null || pending === void 0 ? void 0 : pending.request) && pending.keys) {
|
|
77
|
+
void this.wait(pending);
|
|
78
|
+
}
|
|
79
|
+
else if (this.joined()) {
|
|
80
|
+
this.joinedScreen();
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
void this.open();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Asks the Ta how one says who they are, then the form; a Ta that cannot be reached says so, to try again. */
|
|
87
|
+
async open(error) {
|
|
88
|
+
var _a;
|
|
89
|
+
this.frame(el('div', 'spin'));
|
|
90
|
+
try {
|
|
91
|
+
this.ways = await this.connection().ways('web');
|
|
92
|
+
}
|
|
93
|
+
catch (failure) {
|
|
94
|
+
(_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
|
|
95
|
+
this.joining = undefined;
|
|
96
|
+
this.frame(...this.heading(), el('p', 'error', this.reason(failure)), button('primary', t('retry'), () => void this.open(error)));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.form(error);
|
|
100
|
+
}
|
|
101
|
+
connection() {
|
|
102
|
+
var _a;
|
|
103
|
+
(_a = this.joining) !== null && _a !== void 0 ? _a : (this.joining = new relay_team_1.RelayTeamJoining(this.link));
|
|
104
|
+
return this.joining;
|
|
105
|
+
}
|
|
106
|
+
async back({ signIn, name, error }) {
|
|
107
|
+
if (!signIn) {
|
|
108
|
+
await this.open(t('signInFailed', { reason: error !== null && error !== void 0 ? error : '' }));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this.frame(el('div', 'spin'), el('h1', 'room-name', t('checking')));
|
|
112
|
+
try {
|
|
113
|
+
this.ways = await this.connection().ways('web');
|
|
114
|
+
await this.ask(name !== null && name !== void 0 ? name : '', signIn);
|
|
115
|
+
}
|
|
116
|
+
catch (failure) {
|
|
117
|
+
this.form(this.reason(failure));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Signing in for the Ta app that opened this page: straight to the provider, the Ta giving where. */
|
|
121
|
+
async handOff({ provider, handoff }) {
|
|
122
|
+
var _a;
|
|
123
|
+
var _b;
|
|
124
|
+
this.frame(el('div', 'spin'), el('h1', 'room-name', t('signingIn')));
|
|
125
|
+
try {
|
|
126
|
+
const started = await this.connection().signIn(provider, handoff);
|
|
127
|
+
if (started.device) {
|
|
128
|
+
await this.typeCode(started, { id: provider, name: provider === 'github' ? 'GitHub' : provider }, '', handoff);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
write(SIGN_IN_KEY, { state: started.state, href: relay_team_1.RelayTeamLinkUtil.format(this.link), name: '', handoff });
|
|
132
|
+
(_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
|
|
133
|
+
location.replace((_b = started.url) !== null && _b !== void 0 ? _b : '');
|
|
134
|
+
}
|
|
135
|
+
catch (failure) {
|
|
136
|
+
this.frame(...this.heading(), el('p', 'error', this.reason(failure)));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** Back from the provider, signed in for the Ta app: the Ta verifies it, and the app goes on. */
|
|
140
|
+
async handBack({ signIn, error }) {
|
|
141
|
+
var _a;
|
|
142
|
+
if (!signIn || !('code' in signIn)) {
|
|
143
|
+
this.frame(...this.heading(), el('p', 'error', t('signInFailed', { reason: error !== null && error !== void 0 ? error : '' })));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
this.frame(el('div', 'spin'), el('h1', 'room-name', t('checking')));
|
|
147
|
+
try {
|
|
148
|
+
const { account } = await this.connection().signedIn(signIn.state, signIn.code);
|
|
149
|
+
(_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
|
|
150
|
+
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 })));
|
|
151
|
+
}
|
|
152
|
+
catch (failure) {
|
|
153
|
+
this.frame(...this.heading(), el('p', 'error', this.reason(failure)));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** To the provider, which sends the browser back to this page with a code; or a code to type at it (GitHub's). */
|
|
157
|
+
async signIn(provider, name) {
|
|
158
|
+
var _a;
|
|
159
|
+
var _b;
|
|
160
|
+
const started = await this.connection().signIn(provider.id);
|
|
161
|
+
if (started.device) {
|
|
162
|
+
await this.typeCode(started, provider, name);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
write(SIGN_IN_KEY, { state: started.state, href: location.href, name });
|
|
166
|
+
(_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
|
|
167
|
+
location.assign((_b = started.url) !== null && _b !== void 0 ? _b : '');
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Signing in by a code (docs/design/ta-team.md 17.4): the code, copied as the provider's page opens, typed there; the Ta
|
|
171
|
+
* asks the provider whether it was, and keeps the account under the state of the sign-in (or the app's handoff).
|
|
172
|
+
*/
|
|
173
|
+
async typeCode(started, provider, name, handoff) {
|
|
174
|
+
const device = started.device;
|
|
175
|
+
const joining = this.connection();
|
|
176
|
+
const named = join_i18n_1.JoinI18n.provider(provider);
|
|
177
|
+
const copied = el('p', 'small', '');
|
|
178
|
+
const open = button('primary', t('copyOpen', { provider: named }), () => {
|
|
179
|
+
var _a;
|
|
180
|
+
void ((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(device.code).then(() => (copied.textContent = t('copied'))).catch(() => undefined));
|
|
181
|
+
window.open(device.uri, '_blank', 'noopener');
|
|
182
|
+
});
|
|
183
|
+
const back = button('plain', t('back'), () => {
|
|
184
|
+
joining.close();
|
|
185
|
+
this.joining = undefined;
|
|
186
|
+
void this.open();
|
|
187
|
+
});
|
|
188
|
+
this.frame(...this.heading(), el('p', 'hint', t('typeCode', { provider: named })), el('div', 'device-code', device.code), open, copied, el('p', 'small', t('typeCodeHint', { provider: named })), ...(handoff ? [] : [back]));
|
|
189
|
+
try {
|
|
190
|
+
const account = await joining.typed(started.state, device.expiresAt);
|
|
191
|
+
if (this.joining !== joining) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (!account) {
|
|
195
|
+
await this.open(t('codeGone'));
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (handoff) {
|
|
199
|
+
joining.close();
|
|
200
|
+
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 })));
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
this.frame(el('div', 'spin'), el('h1', 'room-name', t('checking')));
|
|
204
|
+
await this.ask(name, { handoff: started.state });
|
|
205
|
+
}
|
|
206
|
+
catch (failure) {
|
|
207
|
+
if (this.joining !== joining) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (handoff) {
|
|
211
|
+
this.frame(...this.heading(), el('p', 'error', this.reason(failure)));
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
this.form(this.reason(failure));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** This browser is let into that Ta already: Ta's page keeps it among its computers. */
|
|
219
|
+
joined() {
|
|
220
|
+
var _a;
|
|
221
|
+
const hosts = read(HOSTS_KEY);
|
|
222
|
+
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}`));
|
|
223
|
+
}
|
|
224
|
+
frame(...children) {
|
|
225
|
+
const logo = el('span', 'logo', 'Ta');
|
|
226
|
+
const heading = el('div', 'heading');
|
|
227
|
+
heading.append(el('b', undefined, t('title')));
|
|
228
|
+
const top = el('div', 'top');
|
|
229
|
+
top.append(logo, heading);
|
|
230
|
+
const center = el('div', 'center');
|
|
231
|
+
center.append(...children);
|
|
232
|
+
const app = el('div', 'app');
|
|
233
|
+
app.append(top, center);
|
|
234
|
+
document.body.replaceChildren(app);
|
|
235
|
+
}
|
|
236
|
+
heading() {
|
|
237
|
+
const nodes = [el('p', 'lead', t('invited', { owner: this.owner })), el('h1', 'room-name', this.owner)];
|
|
238
|
+
const chips = el('div', 'chips');
|
|
239
|
+
if (this.link.role) {
|
|
240
|
+
chips.append(el('span', 'chip', t('role', { role: join_i18n_1.JoinI18n.role(this.link.role) })));
|
|
241
|
+
}
|
|
242
|
+
if (this.link.what) {
|
|
243
|
+
chips.append(el('span', 'chip', t('what', { what: this.link.what })));
|
|
244
|
+
}
|
|
245
|
+
if (chips.childElementCount) {
|
|
246
|
+
nodes.push(chips);
|
|
247
|
+
}
|
|
248
|
+
return nodes;
|
|
249
|
+
}
|
|
250
|
+
form(error) {
|
|
251
|
+
var _a;
|
|
252
|
+
document.title = t('title');
|
|
253
|
+
const { providers, required } = this.ways;
|
|
254
|
+
const field = el('input', 'text');
|
|
255
|
+
field.placeholder = t('namePlaceholder');
|
|
256
|
+
field.maxLength = 40;
|
|
257
|
+
field.enterKeyHint = 'go';
|
|
258
|
+
field.value = (_a = localStorage.getItem(NAME_KEY)) !== null && _a !== void 0 ? _a : '';
|
|
259
|
+
const label = el('label', 'field');
|
|
260
|
+
label.append(t('name'), field);
|
|
261
|
+
const buttons = [];
|
|
262
|
+
const busy = (on) => {
|
|
263
|
+
for (const one of buttons) {
|
|
264
|
+
one.disabled = on;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
const ask = button('primary', t('join'), () => void submit());
|
|
268
|
+
const submit = async () => {
|
|
269
|
+
const name = field.value.trim();
|
|
270
|
+
if (!name) {
|
|
271
|
+
field.focus();
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
busy(true);
|
|
275
|
+
ask.textContent = t('joining');
|
|
276
|
+
write(NAME_KEY, name);
|
|
277
|
+
try {
|
|
278
|
+
await this.ask(name);
|
|
279
|
+
}
|
|
280
|
+
catch (failure) {
|
|
281
|
+
this.form(this.reason(failure));
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
field.addEventListener('keydown', event => {
|
|
285
|
+
if (event.key === 'Enter' && !event.isComposing) {
|
|
286
|
+
void submit();
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
const accounts = providers.map(provider => {
|
|
290
|
+
const one = button(required ? 'primary' : 'plain', t('signInWith', { provider: join_i18n_1.JoinI18n.provider(provider) }), () => {
|
|
291
|
+
busy(true);
|
|
292
|
+
one.textContent = t('signingIn');
|
|
293
|
+
this.signIn(provider, field.value.trim()).catch(failure => this.form(this.reason(failure)));
|
|
294
|
+
});
|
|
295
|
+
return one;
|
|
296
|
+
});
|
|
297
|
+
buttons.push(ask, ...accounts);
|
|
298
|
+
const signIns = el('div', 'accounts');
|
|
299
|
+
signIns.append(...accounts);
|
|
300
|
+
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')));
|
|
301
|
+
if (!required && !matchMedia('(pointer: coarse)').matches) {
|
|
302
|
+
field.focus();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
reason(failure) {
|
|
306
|
+
const message = failure instanceof Error ? failure.message : String(failure);
|
|
307
|
+
return /did not answer|is it running|lost/i.test(message) ? t('unreachable', { owner: this.owner }) : t('failed', { reason: message });
|
|
308
|
+
}
|
|
309
|
+
async ask(name, signIn) {
|
|
310
|
+
var _a;
|
|
311
|
+
const joining = this.connection();
|
|
312
|
+
const answer = await joining.ask(name, 'web', signIn);
|
|
313
|
+
if (answer.status === 'refused' && answer.reason === 'account') {
|
|
314
|
+
this.ways = { ...this.ways, required: true };
|
|
315
|
+
this.form();
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (answer.status === 'refused' && answer.reason === 'app') {
|
|
319
|
+
joining.close();
|
|
320
|
+
this.joining = undefined;
|
|
321
|
+
this.message(answer.reason);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const request = (_a = answer.request) !== null && _a !== void 0 ? _a : '';
|
|
325
|
+
const keys = joining.keys;
|
|
326
|
+
if (answer.status === 'waiting') {
|
|
327
|
+
write(this.pendingKey, { request, keys });
|
|
328
|
+
}
|
|
329
|
+
await this.settle(joining, request, answer);
|
|
330
|
+
}
|
|
331
|
+
/** Waits for the answer to a request asked before, in this tab or one closed since. */
|
|
332
|
+
async wait(pending) {
|
|
333
|
+
const joining = new relay_team_1.RelayTeamJoining(this.link);
|
|
334
|
+
this.joining = joining;
|
|
335
|
+
joining.resume(pending.keys);
|
|
336
|
+
try {
|
|
337
|
+
await this.settle(joining, pending.request, { status: 'waiting' });
|
|
338
|
+
}
|
|
339
|
+
catch (failure) {
|
|
340
|
+
this.waitingScreen(this.reason(failure), pending);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
async settle(joining, request, first) {
|
|
344
|
+
let answer = first;
|
|
345
|
+
if (answer.status === 'waiting') {
|
|
346
|
+
this.waitingScreen();
|
|
347
|
+
answer = await joining.wait(request);
|
|
348
|
+
}
|
|
349
|
+
if (answer.status === 'accepted' && answer.answer) {
|
|
350
|
+
this.frame(el('div', 'spin'), el('h1', 'room-name', t('connecting')));
|
|
351
|
+
const pairing = await joining.pairing(request, answer.answer);
|
|
352
|
+
joining.close();
|
|
353
|
+
write(this.pendingKey, undefined);
|
|
354
|
+
// To Ta's page, which takes the device out of the address and keeps it for this origin.
|
|
355
|
+
location.replace(relay_team_1.RelayTeamLinkUtil.web(location.origin, pairing));
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
joining.close();
|
|
359
|
+
this.joining = undefined;
|
|
360
|
+
write(this.pendingKey, undefined);
|
|
361
|
+
this.message(answer.status === 'refused' ? 'refused' : 'gone');
|
|
362
|
+
}
|
|
363
|
+
waitingScreen(error, pending) {
|
|
364
|
+
const cancel = button('plain', t('cancel'), () => {
|
|
365
|
+
var _a;
|
|
366
|
+
(_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
|
|
367
|
+
this.joining = undefined;
|
|
368
|
+
write(this.pendingKey, undefined);
|
|
369
|
+
void this.open();
|
|
370
|
+
});
|
|
371
|
+
const again = pending ? [button('primary', t('again'), () => void this.wait(pending))] : [];
|
|
372
|
+
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);
|
|
373
|
+
}
|
|
374
|
+
message(text) {
|
|
375
|
+
const again = text === 'refused' ? [button('primary', t('again'), () => void this.open())] : [];
|
|
376
|
+
this.frame(...this.heading(), el('p', text === 'app' ? 'hint' : 'error', t(text, { owner: this.owner })), ...again);
|
|
377
|
+
}
|
|
378
|
+
joinedScreen() {
|
|
379
|
+
this.frame(...this.heading(), el('p', 'hint', t('joined', { owner: this.owner })), button('primary', t('open'), () => location.assign(relay_team_1.RELAY_WEB_PATH)));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const style = document.createElement('style');
|
|
383
|
+
style.textContent = `${guest_style_1.GUEST_STYLE}
|
|
384
|
+
.chips{display:flex;flex-wrap:wrap;justify-content:center;gap:6px}
|
|
385
|
+
.chip{padding:3px 10px;border-radius:999px;background:var(--soft);color:var(--muted);font-size:12.5px}
|
|
386
|
+
.accounts{display:flex;flex-direction:column;gap:8px;width:100%}
|
|
387
|
+
.accounts .plain{width:100%;padding:11px 14px;border:1px solid var(--line);border-radius:12px;color:var(--fg);font-weight:500}
|
|
388
|
+
.or{margin:2px 0;color:var(--muted);font-size:12.5px;text-align:center}
|
|
389
|
+
.device-code{align-self:center;margin:4px auto;padding:10px 18px;border:1px dashed var(--line);border-radius:12px;font:600 26px/1.2 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.12em;user-select:all}
|
|
390
|
+
.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}
|
|
391
|
+
`;
|
|
392
|
+
document.head.append(style);
|
|
393
|
+
/**
|
|
394
|
+
* Back from the provider: `/j?code=…&state=…` (or `?error=…`), the link being in the sign-in kept before it went; the
|
|
395
|
+
* address is the link's again, without the code.
|
|
396
|
+
*/
|
|
397
|
+
function cameBack() {
|
|
398
|
+
var _a, _b;
|
|
399
|
+
const query = new URLSearchParams(location.search);
|
|
400
|
+
const state = query.get('state');
|
|
401
|
+
if (!state) {
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
const kept = read(SIGN_IN_KEY);
|
|
405
|
+
write(SIGN_IN_KEY, undefined);
|
|
406
|
+
const link = (kept === null || kept === void 0 ? void 0 : kept.state) === state ? relay_team_1.RelayTeamLinkUtil.parse(kept.href) : undefined;
|
|
407
|
+
if (!kept || !link) {
|
|
408
|
+
return undefined;
|
|
409
|
+
}
|
|
410
|
+
history.replaceState(null, '', new URL(kept.href).pathname + new URL(kept.href).hash);
|
|
411
|
+
const code = query.get('code');
|
|
412
|
+
return {
|
|
413
|
+
link,
|
|
414
|
+
back: {
|
|
415
|
+
...(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 : '' }),
|
|
416
|
+
...(kept.handoff ? { handoff: true } : {}),
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
const back = cameBack();
|
|
421
|
+
const link = (_a = back === null || back === void 0 ? void 0 : back.link) !== null && _a !== void 0 ? _a : relay_team_1.RelayTeamLinkUtil.parse(location.href);
|
|
422
|
+
if (link) {
|
|
423
|
+
// The fragment's sign-in for the Ta app goes once: opened again, the page is the link's.
|
|
424
|
+
const handoff = back ? undefined : relay_team_1.RelayTeamLinkUtil.handoffOf(location.href);
|
|
425
|
+
if (handoff) {
|
|
426
|
+
history.replaceState(null, '', location.pathname + relay_team_1.RelayTeamLinkUtil.format(link).slice(relay_team_1.RelayTeamLinkUtil.format(link).indexOf('#')));
|
|
427
|
+
}
|
|
428
|
+
new JoinPage(link).start(back === null || back === void 0 ? void 0 : back.back, handoff);
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
const center = el('div', 'center');
|
|
432
|
+
center.append(el('p', 'error', t('invalid')));
|
|
433
|
+
document.body.replaceChildren(center);
|
|
434
|
+
}
|
|
435
|
+
//# 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>;
|
package/lib/node/relay-server.js
CHANGED
|
@@ -12,6 +12,8 @@ const relay_info_1 = require("../common/relay-info");
|
|
|
12
12
|
const relay_protocol_1 = require("../common/relay-protocol");
|
|
13
13
|
const relay_room_1 = require("../common/relay-room");
|
|
14
14
|
const relay_spot_1 = require("../common/relay-spot");
|
|
15
|
+
const relay_team_1 = require("../common/relay-team");
|
|
16
|
+
const relay_web_1 = require("../common/relay-web");
|
|
15
17
|
const relay_file_storage_1 = require("./relay-file-storage");
|
|
16
18
|
const relay_viewer_1 = require("./relay-viewer");
|
|
17
19
|
const WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
|
|
@@ -133,9 +135,13 @@ class RelayServer {
|
|
|
133
135
|
});
|
|
134
136
|
return;
|
|
135
137
|
}
|
|
136
|
-
if (path === relay_protocol_1.RELAY_ROOM_PATH) {
|
|
138
|
+
if (path === relay_protocol_1.RELAY_ROOM_PATH || path === relay_team_1.RELAY_JOIN_PATH) {
|
|
137
139
|
response.writeHead(200, { ...relay_protocol_1.RELAY_VIEWER_HEADERS, 'x-frame-options': 'DENY' });
|
|
138
|
-
response.end(relay_viewer_1.RelayViewer.room());
|
|
140
|
+
response.end(path === relay_protocol_1.RELAY_ROOM_PATH ? relay_viewer_1.RelayViewer.room() : relay_viewer_1.RelayViewer.join());
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (path.startsWith(relay_team_1.RELAY_WEB_PATH) || path === relay_team_1.RELAY_WEB_PATH.slice(0, -1)) {
|
|
144
|
+
this.web(path, response);
|
|
139
145
|
return;
|
|
140
146
|
}
|
|
141
147
|
if (path === relay_protocol_1.RELAY_CONTENT_PATH || path === relay_protocol_1.RELAY_FRAME_PATH) {
|
|
@@ -162,6 +168,25 @@ class RelayServer {
|
|
|
162
168
|
});
|
|
163
169
|
});
|
|
164
170
|
}
|
|
171
|
+
/** A file of Ta's web page (RelayWebUtil), from the directory of the options. */
|
|
172
|
+
web(path, response) {
|
|
173
|
+
var _a;
|
|
174
|
+
if (path === relay_team_1.RELAY_WEB_PATH.slice(0, -1)) {
|
|
175
|
+
response.writeHead(308, { location: relay_team_1.RELAY_WEB_PATH });
|
|
176
|
+
response.end();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const file = relay_web_1.RelayWebUtil.file(path);
|
|
180
|
+
const full = file && this.options.web ? (0, node_path_1.join)(this.options.web, file) : undefined;
|
|
181
|
+
if (!file || !full || !((_a = (0, node_fs_1.statSync)(full, { throwIfNoEntry: false })) === null || _a === void 0 ? void 0 : _a.isFile())) {
|
|
182
|
+
response.writeHead(404, { 'content-type': 'text/plain' });
|
|
183
|
+
response.end('Not found.\n');
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const body = (0, node_fs_1.readFileSync)(full);
|
|
187
|
+
response.writeHead(200, relay_web_1.RelayWebUtil.headers(file));
|
|
188
|
+
response.end(file === 'index.html' ? relay_web_1.RelayWebUtil.index(body.toString('utf8')) : body);
|
|
189
|
+
}
|
|
165
190
|
close() {
|
|
166
191
|
var _a, _b, _c, _d, _e;
|
|
167
192
|
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
|
}
|
package/lib/node/relay-viewer.js
CHANGED
|
@@ -11,7 +11,7 @@ var RelayViewer;
|
|
|
11
11
|
if (!pages) {
|
|
12
12
|
const dir = (0, node_path_1.join)(__dirname, '../../viewer');
|
|
13
13
|
const file = (name) => (0, node_fs_1.readFileSync)((0, node_path_1.join)(dir, name), 'utf8');
|
|
14
|
-
pages = { page: file('page.html'), frame: file('frame.html'), room: file('room.html') };
|
|
14
|
+
pages = { page: file('page.html'), frame: file('frame.html'), room: file('room.html'), join: file('join.html') };
|
|
15
15
|
}
|
|
16
16
|
return pages;
|
|
17
17
|
}
|
|
@@ -20,6 +20,11 @@ var RelayViewer;
|
|
|
20
20
|
return read().room;
|
|
21
21
|
}
|
|
22
22
|
RelayViewer.room = room;
|
|
23
|
+
/** The page of a link that invites into a Ta, opened in a browser. */
|
|
24
|
+
function join() {
|
|
25
|
+
return read().join;
|
|
26
|
+
}
|
|
27
|
+
RelayViewer.join = join;
|
|
23
28
|
function page() {
|
|
24
29
|
return read().page;
|
|
25
30
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PageLanguage } from '../common/page-language';
|
|
1
2
|
declare const zh: {
|
|
2
3
|
title: string;
|
|
3
4
|
loading: string;
|
|
@@ -48,8 +49,12 @@ declare const zh: {
|
|
|
48
49
|
use: string;
|
|
49
50
|
};
|
|
50
51
|
export type ViewerText = keyof typeof zh;
|
|
52
|
+
/** The words of each language of Ta, checked by scripts/check-i18n.ts. */
|
|
53
|
+
export declare const VIEWER_WORDS: Readonly<Record<PageLanguage, typeof zh>>;
|
|
51
54
|
export declare namespace ViewerI18n {
|
|
52
|
-
const
|
|
55
|
+
const language: PageLanguage;
|
|
56
|
+
/** Chinese or Japanese: Latin among the words has a space on each side. */
|
|
57
|
+
const cjk: boolean;
|
|
53
58
|
function t(id: ViewerText, values?: Record<string, string | number>): string;
|
|
54
59
|
function date(at: number): string;
|
|
55
60
|
}
|