@celljs/ta-relay 4.11.0 → 4.12.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/esm/common/index.d.ts +2 -0
- package/esm/common/index.js +2 -0
- package/esm/common/relay-faces.d.ts +32 -0
- package/esm/common/relay-faces.js +208 -0
- package/esm/common/relay-hubs-connection.d.ts +98 -0
- package/esm/common/relay-hubs-connection.js +505 -0
- package/esm/common/relay-hubs-protocol.d.ts +130 -0
- package/esm/common/relay-hubs-protocol.js +2 -0
- package/esm/common/relay-hubs.d.ts +4 -214
- package/esm/common/relay-hubs.js +2 -495
- package/esm/common/relay-room-chat.d.ts +31 -2
- package/esm/common/relay-room-chat.js +31 -7
- package/esm/guest/guest-i18n.d.ts +3 -0
- package/esm/guest/guest-i18n.js +6 -0
- package/esm/guest/guest-style.d.ts +1 -1
- package/esm/guest/guest-style.js +11 -4
- package/esm/guest/guest.js +31 -18
- package/esm/node/relay-hub-files.d.ts +1 -1
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/common/relay-faces.d.ts +33 -0
- package/lib/common/relay-faces.js +211 -0
- package/lib/common/relay-hubs-connection.d.ts +99 -0
- package/lib/common/relay-hubs-connection.js +510 -0
- package/lib/common/relay-hubs-protocol.d.ts +131 -0
- package/lib/common/relay-hubs-protocol.js +3 -0
- package/lib/common/relay-hubs.d.ts +4 -214
- package/lib/common/relay-hubs.js +9 -502
- package/lib/common/relay-room-chat.d.ts +31 -2
- package/lib/common/relay-room-chat.js +31 -7
- package/lib/guest/guest-i18n.d.ts +3 -0
- package/lib/guest/guest-i18n.js +6 -0
- package/lib/guest/guest-style.d.ts +1 -1
- package/lib/guest/guest-style.js +11 -4
- package/lib/guest/guest.js +31 -18
- package/lib/node/relay-hub-files.d.ts +1 -1
- package/package.json +2 -2
- package/viewer/room.html +21 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const GUEST_STYLE = "\n:root{color-scheme:light dark;--bg:#fff;--fg:#1f1f1f;--muted:#737373;--faint:#a3a3a3;--line:#ececec;--soft:#f5f5f5;--bubble:#f2f2f2;--mine:#e7f6ec;--mine-fg:#14532d;--code:#f6f6f6;--accent:#16a34a;--red:#dc2626;--radius:16px}\n@media (prefers-color-scheme:dark){:root{--bg:#191919;--fg:#ececec;--muted:#a3a3a3;--faint:#6b6b6b;--line:#2c2c2c;--soft:#222;--bubble:#262626;--mine:#1f3a2a;--mine-fg:#d1fae5;--code:#232323;--accent:#4ade80;--red:#f87171}}\n*{box-sizing:border-box}\nhtml,body{margin:0;height:100%;background:var(--bg);color:var(--fg);font:15px/1.6 -apple-system,BlinkMacSystemFont,\"Segoe UI\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft YaHei\",sans-serif;-webkit-font-smoothing:antialiased;overscroll-behavior:none}\nbutton{font:inherit;color:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent}\n.app{display:flex;flex-direction:column;height:100dvh;max-width:760px;margin:0 auto}\n.top{flex:none;display:flex;align-items:center;gap:10px;min-height:54px;padding:8px 10px 8px 16px;padding-top:max(8px,env(safe-area-inset-top));border-bottom:1px solid var(--line);background:var(--bg)}\n.logo{width:26px;height:26px;border-radius:8px;background:var(--fg);color:var(--bg);display:grid;place-items:center;font-weight:700;font-size:13px;flex:none}\n.heading{flex:1;min-width:0;display:flex;flex-direction:column}\n.heading b{font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.heading b span{color:var(--muted);font-weight:500;margin-left:4px}\n.heading small{font-size:11.5px;line-height:15px;color:var(--accent)}\n.heading small.quiet{color:var(--muted)}\n.icon{flex:none;width:36px;height:36px;display:grid;place-items:center;border:0;border-radius:10px;background:none;font-size:20px;line-height:1;color:var(--muted)}\n.icon:hover{background:var(--soft);color:var(--fg)}\n.center{flex:1;display:flex;flex-direction:column;justify-content:center;padding:24px 22px calc(32px + env(safe-area-inset-bottom));max-width:440px;width:100%;margin:0 auto;gap:14px}\n.card-face{align-self:center}\n.lead{margin:0;text-align:center;color:var(--muted);font-size:14px}\n.room-name{margin:0;text-align:center;font-size:21px;font-weight:600;line-height:1.35;word-break:break-word}\n.hint{margin:0;text-align:center;color:var(--muted);font-size:13px}\n.small{margin:0;color:var(--faint);font-size:12px;line-height:1.55;text-align:center}\nlabel.field{display:flex;flex-direction:column;gap:6px;font-size:13px;color:var(--muted);margin-top:6px}\ninput.text{font:inherit;font-size:16px;color:var(--fg);background:var(--soft);border:1px solid var(--line);border-radius:12px;padding:11px 13px;outline:none}\ninput.text:focus{border-color:var(--accent)}\n.primary{border:0;border-radius:12px;padding:12px 16px;background:#16a34a;color:#fff;font-weight:600;font-size:15px}\n.primary:disabled{opacity:.55;cursor:default}\n.plain{border:0;background:none;color:var(--muted);font-size:13.5px;padding:8px}\n.plain:hover{color:var(--fg)}\n.danger{color:var(--red)}\n.error{margin:0;text-align:center;color:var(--red);font-size:13px}\n.spin{width:22px;height:22px;border-radius:50%;border:2px solid var(--line);border-top-color:var(--accent);animation:spin .9s linear infinite;align-self:center}\n@keyframes spin{to{transform:rotate(360deg)}}\n.face{flex:none;display:inline-
|
|
1
|
+
export declare const GUEST_STYLE = "\n:root{color-scheme:light dark;--bg:#fff;--fg:#1f1f1f;--muted:#737373;--faint:#a3a3a3;--line:#ececec;--soft:#f5f5f5;--bubble:#f2f2f2;--mine:#e7f6ec;--mine-fg:#14532d;--code:#f6f6f6;--accent:#16a34a;--red:#dc2626;--radius:16px}\n@media (prefers-color-scheme:dark){:root{--bg:#191919;--fg:#ececec;--muted:#a3a3a3;--faint:#6b6b6b;--line:#2c2c2c;--soft:#222;--bubble:#262626;--mine:#1f3a2a;--mine-fg:#d1fae5;--code:#232323;--accent:#4ade80;--red:#f87171}}\n*{box-sizing:border-box}\nhtml,body{margin:0;height:100%;background:var(--bg);color:var(--fg);font:15px/1.6 -apple-system,BlinkMacSystemFont,\"Segoe UI\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft YaHei\",sans-serif;-webkit-font-smoothing:antialiased;overscroll-behavior:none}\nbutton{font:inherit;color:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent}\n.app{display:flex;flex-direction:column;height:100dvh;max-width:760px;margin:0 auto}\n.top{flex:none;display:flex;align-items:center;gap:10px;min-height:54px;padding:8px 10px 8px 16px;padding-top:max(8px,env(safe-area-inset-top));border-bottom:1px solid var(--line);background:var(--bg)}\n.logo{width:26px;height:26px;border-radius:8px;background:var(--fg);color:var(--bg);display:grid;place-items:center;font-weight:700;font-size:13px;flex:none}\n.heading{flex:1;min-width:0;display:flex;flex-direction:column}\n.heading b{font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.heading b span{color:var(--muted);font-weight:500;margin-left:4px}\n.heading small{font-size:11.5px;line-height:15px;color:var(--accent)}\n.heading small.quiet{color:var(--muted)}\n.icon{flex:none;width:36px;height:36px;display:grid;place-items:center;border:0;border-radius:10px;background:none;font-size:20px;line-height:1;color:var(--muted)}\n.icon:hover{background:var(--soft);color:var(--fg)}\n.center{flex:1;display:flex;flex-direction:column;justify-content:center;padding:24px 22px calc(32px + env(safe-area-inset-bottom));max-width:440px;width:100%;margin:0 auto;gap:14px}\n.card-face{align-self:center}\n.lead{margin:0;text-align:center;color:var(--muted);font-size:14px}\n.room-name{margin:0;text-align:center;font-size:21px;font-weight:600;line-height:1.35;word-break:break-word}\n.hint{margin:0;text-align:center;color:var(--muted);font-size:13px}\n.small{margin:0;color:var(--faint);font-size:12px;line-height:1.55;text-align:center}\nlabel.field{display:flex;flex-direction:column;gap:6px;font-size:13px;color:var(--muted);margin-top:6px}\ninput.text{font:inherit;font-size:16px;color:var(--fg);background:var(--soft);border:1px solid var(--line);border-radius:12px;padding:11px 13px;outline:none}\ninput.text:focus{border-color:var(--accent)}\n.primary{border:0;border-radius:12px;padding:12px 16px;background:#16a34a;color:#fff;font-weight:600;font-size:15px}\n.primary:disabled{opacity:.55;cursor:default}\n.plain{border:0;background:none;color:var(--muted);font-size:13.5px;padding:8px}\n.plain:hover{color:var(--fg)}\n.danger{color:var(--red)}\n.error{margin:0;text-align:center;color:var(--red);font-size:13px}\n.spin{width:22px;height:22px;border-radius:50%;border:2px solid var(--line);border-top-color:var(--accent);animation:spin .9s linear infinite;align-self:center}\n@keyframes spin{to{transform:rotate(360deg)}}\n.face{flex:none;display:inline-flex;position:relative;user-select:none}\n.face svg{display:block;overflow:visible}\n.ta-face-eyes{transform-box:fill-box;transform-origin:center;animation:blink 5.2s infinite}\n.face[data-face=\"1\"] .ta-face-eyes,.face[data-face=\"5\"] .ta-face-eyes,.face[data-face=\"9\"] .ta-face-eyes,.face[data-face=\"13\"] .ta-face-eyes{animation-delay:-1.7s}\n.face[data-face=\"2\"] .ta-face-eyes,.face[data-face=\"6\"] .ta-face-eyes,.face[data-face=\"10\"] .ta-face-eyes,.face[data-face=\"14\"] .ta-face-eyes{animation-delay:-3.1s}\n.face[data-face=\"3\"] .ta-face-eyes,.face[data-face=\"7\"] .ta-face-eyes,.face[data-face=\"11\"] .ta-face-eyes,.face[data-face=\"15\"] .ta-face-eyes{animation-delay:-4.4s}\n@keyframes blink{0%,94%,100%{transform:scaleY(1)}97%{transform:scaleY(.1)}}\n@media (prefers-reduced-motion:reduce){.face *{animation:none!important}}\n@media (prefers-color-scheme:dark){.face[data-face=\"11\"] .ta-face-body>g>circle{fill:#4a4a52}}\n.face i{position:absolute;right:-1px;bottom:-1px;width:28%;height:28%;min-width:7px;min-height:7px;border-radius:50%;border:2px solid var(--bg);background:var(--faint)}\n.face i.on{background:var(--accent)}\n.banner{flex:none;margin:10px 14px 0;padding:8px 12px;border-radius:12px;background:var(--soft);color:var(--muted);font-size:12.5px;line-height:1.5}\n.list{flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;overscroll-behavior:none;padding:10px 14px 12px;display:flex;flex-direction:column;gap:4px}\n.empty{margin:14vh auto 0;max-width:300px;text-align:center;color:var(--muted);font-size:13px}\n.when{align-self:center;margin:14px 0 6px;color:var(--faint);font-size:11.5px;font-variant-numeric:tabular-nums}\n.msg{display:flex;align-items:flex-start;gap:10px}\n.msg.first{margin-top:10px}\n.msg .slot{width:32px;flex:none;display:flex;justify-content:center}\n.msg .col{display:flex;flex-direction:column;align-items:flex-start;min-width:0;max-width:calc(100% - 84px)}\n.msg .who{display:flex;align-items:center;gap:6px;margin:0 2px 4px;color:var(--muted);font-size:12px;line-height:16px}\n.msg.double .bubble{border:1px dashed var(--soft);background:none}\n.bubble{min-width:0;max-width:100%;padding:8px 13px;border-radius:5px var(--radius) var(--radius) var(--radius);background:var(--bubble);word-break:break-word}\n.mine{display:flex;justify-content:flex-end;margin:6px 0 2px}\n.mine .bubble{max-width:78%;border-radius:var(--radius) 5px var(--radius) var(--radius);background:var(--mine);color:var(--mine-fg)}\n.bubble>:first-child{margin-top:0}.bubble>:last-child{margin-bottom:0}\n.bubble p{margin:0 0 .6em}\n.bubble ul,.bubble ol{margin:0 0 .6em;padding-left:1.3em}\n.bubble a{color:inherit;text-decoration:underline;text-underline-offset:2px}\n.bubble code{font:13px ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--code);padding:1px 4px;border-radius:5px}\n.bubble pre{margin:0 0 .6em;padding:8px 10px;background:var(--code);border-radius:10px;overflow-x:auto}\n.bubble pre code{background:none;padding:0}\n.bubble blockquote{margin:0 0 .6em;padding-left:10px;border-left:3px solid var(--line);color:var(--muted)}\n.failed{align-self:flex-end;color:var(--red);font-size:12px;margin:2px 4px 0}\n.box{flex:none;display:flex;align-items:flex-end;gap:8px;padding:8px 12px calc(10px + env(safe-area-inset-bottom));border-top:1px solid var(--line);background:var(--bg)}\n.box textarea{flex:1;min-width:0;resize:none;max-height:160px;font:inherit;font-size:16px;line-height:1.45;color:var(--fg);background:var(--soft);border:1px solid var(--line);border-radius:18px;padding:8px 14px;outline:none}\n.box textarea:focus{border-color:var(--accent)}\n.box .primary{flex:none;border-radius:18px;padding:8px 16px;min-height:40px}\n.foot{flex:none;text-align:center;color:var(--faint);font-size:11px;padding:0 0 6px}\n.sheet{position:fixed;inset:0;z-index:5;display:flex;align-items:flex-end;justify-content:center;background:rgba(0,0,0,.32)}\n.sheet .panel{width:100%;max-width:520px;max-height:80dvh;overflow-y:auto;background:var(--bg);border-radius:18px 18px 0 0;padding:14px 8px calc(14px + env(safe-area-inset-bottom))}\n@media (min-width:700px){.sheet{align-items:center}.sheet .panel{border-radius:18px}}\n.panel h3{margin:4px 14px 8px;font-size:13px;font-weight:500;color:var(--muted)}\n.member{display:flex;align-items:center;gap:10px;padding:8px 12px}\n.member .nm{flex:1;min-width:0;display:flex;align-items:center;gap:6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.tag{flex:none;padding:0 6px;border-radius:6px;background:var(--soft);color:var(--muted);font-size:11px;line-height:18px}\n.member .st{font-size:12px;color:var(--muted)}\n.member .st.on{color:var(--accent)}\n.row{display:block;width:100%;text-align:left;border:0;background:none;padding:12px 14px;border-radius:12px;font-size:14.5px}\n.row:hover{background:var(--soft)}\n.sep{height:1px;margin:6px 12px;background:var(--line)}\n";
|
package/esm/guest/guest-style.js
CHANGED
|
@@ -31,9 +31,15 @@ input.text:focus{border-color:var(--accent)}
|
|
|
31
31
|
.error{margin:0;text-align:center;color:var(--red);font-size:13px}
|
|
32
32
|
.spin{width:22px;height:22px;border-radius:50%;border:2px solid var(--line);border-top-color:var(--accent);animation:spin .9s linear infinite;align-self:center}
|
|
33
33
|
@keyframes spin{to{transform:rotate(360deg)}}
|
|
34
|
-
.face{flex:none;display:inline-
|
|
35
|
-
.
|
|
36
|
-
|
|
34
|
+
.face{flex:none;display:inline-flex;position:relative;user-select:none}
|
|
35
|
+
.face svg{display:block;overflow:visible}
|
|
36
|
+
.ta-face-eyes{transform-box:fill-box;transform-origin:center;animation:blink 5.2s infinite}
|
|
37
|
+
.face[data-face="1"] .ta-face-eyes,.face[data-face="5"] .ta-face-eyes,.face[data-face="9"] .ta-face-eyes,.face[data-face="13"] .ta-face-eyes{animation-delay:-1.7s}
|
|
38
|
+
.face[data-face="2"] .ta-face-eyes,.face[data-face="6"] .ta-face-eyes,.face[data-face="10"] .ta-face-eyes,.face[data-face="14"] .ta-face-eyes{animation-delay:-3.1s}
|
|
39
|
+
.face[data-face="3"] .ta-face-eyes,.face[data-face="7"] .ta-face-eyes,.face[data-face="11"] .ta-face-eyes,.face[data-face="15"] .ta-face-eyes{animation-delay:-4.4s}
|
|
40
|
+
@keyframes blink{0%,94%,100%{transform:scaleY(1)}97%{transform:scaleY(.1)}}
|
|
41
|
+
@media (prefers-reduced-motion:reduce){.face *{animation:none!important}}
|
|
42
|
+
@media (prefers-color-scheme:dark){.face[data-face="11"] .ta-face-body>g>circle{fill:#4a4a52}}
|
|
37
43
|
.face i{position:absolute;right:-1px;bottom:-1px;width:28%;height:28%;min-width:7px;min-height:7px;border-radius:50%;border:2px solid var(--bg);background:var(--faint)}
|
|
38
44
|
.face i.on{background:var(--accent)}
|
|
39
45
|
.banner{flex:none;margin:10px 14px 0;padding:8px 12px;border-radius:12px;background:var(--soft);color:var(--muted);font-size:12.5px;line-height:1.5}
|
|
@@ -44,7 +50,8 @@ input.text:focus{border-color:var(--accent)}
|
|
|
44
50
|
.msg.first{margin-top:10px}
|
|
45
51
|
.msg .slot{width:32px;flex:none;display:flex;justify-content:center}
|
|
46
52
|
.msg .col{display:flex;flex-direction:column;align-items:flex-start;min-width:0;max-width:calc(100% - 84px)}
|
|
47
|
-
.msg .who{margin:0 2px 4px;color:var(--muted);font-size:12px;line-height:16px}
|
|
53
|
+
.msg .who{display:flex;align-items:center;gap:6px;margin:0 2px 4px;color:var(--muted);font-size:12px;line-height:16px}
|
|
54
|
+
.msg.double .bubble{border:1px dashed var(--soft);background:none}
|
|
48
55
|
.bubble{min-width:0;max-width:100%;padding:8px 13px;border-radius:5px var(--radius) var(--radius) var(--radius);background:var(--bubble);word-break:break-word}
|
|
49
56
|
.mine{display:flex;justify-content:flex-end;margin:6px 0 2px}
|
|
50
57
|
.mine .bubble{max-width:78%;border-radius:var(--radius) 5px var(--radius) var(--radius);background:var(--mine);color:var(--mine-fg)}
|
package/esm/guest/guest.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FaceUtil } from '../common/relay-faces.js';
|
|
1
2
|
import { RelayHubUtil } from '../common/relay-hub-util.js';
|
|
2
3
|
import { RelayHubs } from '../common/relay-hubs.js';
|
|
3
4
|
import { RelayRoomChat } from '../common/relay-room-chat.js';
|
|
@@ -41,19 +42,25 @@ function div(className, ...children) {
|
|
|
41
42
|
node.append(...children);
|
|
42
43
|
return node;
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const SVG = 'http://www.w3.org/2000/svg';
|
|
46
|
+
function svg(node) {
|
|
47
|
+
var _a;
|
|
48
|
+
const element = document.createElementNS(SVG, node.tag);
|
|
49
|
+
for (const [name, value] of Object.entries(node.attrs)) {
|
|
50
|
+
element.setAttribute(name, String(value));
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
element.append(...((_a = node.children) !== null && _a !== void 0 ? _a : []).map(svg));
|
|
53
|
+
return element;
|
|
50
54
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const node = el('span'
|
|
55
|
-
node.className =
|
|
56
|
-
node.
|
|
55
|
+
/** The face of one in the room, as Ta draws it (FaceUtil.art); a dot at its corner when told whether online. */
|
|
56
|
+
function face(id, size, online) {
|
|
57
|
+
const shown = FaceUtil.of(id);
|
|
58
|
+
const node = el('span');
|
|
59
|
+
node.className = 'face';
|
|
60
|
+
node.dataset.face = String(shown);
|
|
61
|
+
node.style.cssText = `width:${size}px;height:${size}px`;
|
|
62
|
+
const picture = svg({ tag: 'svg', attrs: { viewBox: '0 0 40 40', width: size, height: size, 'aria-hidden': 'true' }, children: [FaceUtil.art(shown)] });
|
|
63
|
+
node.append(picture);
|
|
57
64
|
if (online !== undefined) {
|
|
58
65
|
const dot = el('i');
|
|
59
66
|
dot.className = online ? 'on' : '';
|
|
@@ -178,7 +185,7 @@ class GuestPage {
|
|
|
178
185
|
void submit();
|
|
179
186
|
}
|
|
180
187
|
});
|
|
181
|
-
this.frame(this.top(), div('center', Object.assign(face(this.link.owner,
|
|
188
|
+
this.frame(this.top(), div('center', Object.assign(face(this.link.owner, 64), { className: 'face card-face' }), Object.assign(el('p', t('invited', { by: this.link.by || '…' })), { className: 'lead' }), Object.assign(el('h1', this.link.title || t('title')), { className: 'room-name' }), Object.assign(el('p', t('joinHint')), { className: 'hint' }), label, ...shown, ask, Object.assign(el('p', t('keep')), { className: 'small' }), Object.assign(el('p', t('haveTa')), { className: 'small' })));
|
|
182
189
|
}
|
|
183
190
|
waiting() {
|
|
184
191
|
this.frame(this.top(), div('center', Object.assign(el('div'), { className: 'spin' }), Object.assign(el('h1', t('waiting', { by: this.link.by || '…' })), { className: 'room-name' }), Object.assign(el('p', t('waitingHint')), { className: 'hint' }), button('plain', t('cancel'), () => void this.hubs.leave(this.link.room).then(() => this.update()))));
|
|
@@ -280,28 +287,34 @@ class GuestPage {
|
|
|
280
287
|
}
|
|
281
288
|
const lines = this.chat.lines;
|
|
282
289
|
const self = (_a = room.members.find(member => member.self)) === null || _a === void 0 ? void 0 : _a.member;
|
|
283
|
-
const
|
|
290
|
+
const personOf = (line) => { var _a; var _b; return (_b = (_a = room.members.find(member => member.member === line.from)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : line.name; };
|
|
291
|
+
// What a double says (docs/design/ta-link.md 4) is its own: `X's double`, a guest having none; an agent's, its name.
|
|
292
|
+
const nameOf = (line) => (line.agent ? line.agent.name : line.double ? t('doubleOf').replace('{name}', personOf(line)) : personOf(line));
|
|
293
|
+
const tagOf = (line) => (line.agent ? t('agentOf').replace('{name}', personOf(line)) : line.double ? t('double') : '');
|
|
294
|
+
const speaker = (line) => { var _a; var _b; return `${line.from}:${line.double ? 'd' : ''}:${(_b = (_a = line.agent) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : ''}`; };
|
|
284
295
|
const nodes = [];
|
|
285
296
|
if (!lines.length) {
|
|
286
297
|
nodes.push(div('empty', t('empty')));
|
|
287
298
|
}
|
|
288
299
|
lines.forEach((line, index) => {
|
|
289
300
|
var _a;
|
|
301
|
+
var _b, _c;
|
|
290
302
|
const before = lines[index - 1];
|
|
291
303
|
const separator = !before || line.at - before.at > PAUSE_MS;
|
|
292
|
-
const first = separator || before
|
|
304
|
+
const first = separator || speaker(before) !== speaker(line) || line.at - before.at > RUN_MS;
|
|
293
305
|
if (separator) {
|
|
294
306
|
nodes.push(div('when', GuestI18n.time(line.at)));
|
|
295
307
|
}
|
|
296
308
|
const bubble = div('bubble', ViewerMarkdown.render(line.text));
|
|
297
309
|
bubble.title = GuestI18n.time(line.at);
|
|
298
|
-
if (line.from === self) {
|
|
310
|
+
if (line.from === self && !line.agent) {
|
|
299
311
|
nodes.push(div('mine', bubble));
|
|
300
312
|
return;
|
|
301
313
|
}
|
|
302
314
|
const other = room.members.find(member => member.member === line.from);
|
|
303
|
-
const
|
|
304
|
-
|
|
315
|
+
const tag = tagOf(line);
|
|
316
|
+
const col = div('col', ...(first ? [div('who', nameOf(line), ...(tag ? [div('tag', tag)] : []))] : []), bubble);
|
|
317
|
+
nodes.push(div(`msg${first ? ' first' : ''}${line.double || line.agent ? ' double' : ''}`, div('slot', ...(first ? [face((_c = (_b = (_a = line.agent) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : other === null || other === void 0 ? void 0 : other.id) !== null && _c !== void 0 ? _c : line.from, 32)] : [])), col));
|
|
305
318
|
});
|
|
306
319
|
list.replaceChildren(...nodes);
|
|
307
320
|
if (this.stuck) {
|
|
@@ -320,7 +333,7 @@ class GuestPage {
|
|
|
320
333
|
const tags = [member.self ? t('you') : '', member.owner ? t('owner') : '', member.guest ? t('guest') : ''].filter(Boolean);
|
|
321
334
|
const name = div('nm', member.name, ...tags.map(tag => Object.assign(el('span', tag), { className: 'tag' })));
|
|
322
335
|
const status = Object.assign(el('span', member.online ? t('onlineNow') : ''), { className: 'st on' });
|
|
323
|
-
panel.append(div('member', face(member.id,
|
|
336
|
+
panel.append(div('member', face(member.id, 34, member.online), name, status));
|
|
324
337
|
}
|
|
325
338
|
panel.append(div('sep'), button('row', t('rename'), () => {
|
|
326
339
|
var _a, _b;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RelayHubsStore, RelayHubsStoreName } from '../common/relay-hubs.js';
|
|
1
|
+
import type { RelayHubsStore, RelayHubsStoreName } from '../common/relay-hubs-protocol.js';
|
|
2
2
|
/** What the rooms of a Ta keep, as files of its agent directory readable by the user alone: `identity.json`, `rooms.json`, `friends.json`. */
|
|
3
3
|
export declare class RelayHubFiles implements RelayHubsStore {
|
|
4
4
|
readonly agentDir: string;
|
package/lib/common/index.d.ts
CHANGED
|
@@ -5,10 +5,12 @@ export * from './relay-card';
|
|
|
5
5
|
export * from './relay-cipher';
|
|
6
6
|
export * from './relay-content';
|
|
7
7
|
export * from './relay-conversation';
|
|
8
|
+
export * from './relay-faces';
|
|
8
9
|
export * from './relay-files';
|
|
9
10
|
export * from './relay-hub';
|
|
10
11
|
export * from './relay-hub-util';
|
|
11
12
|
export * from './relay-hubs';
|
|
13
|
+
export * from './relay-hubs-protocol';
|
|
12
14
|
export * from './relay-identity';
|
|
13
15
|
export * from './relay-pairing';
|
|
14
16
|
export * from './relay-protocol';
|
package/lib/common/index.js
CHANGED
|
@@ -21,10 +21,12 @@ __exportStar(require("./relay-card"), exports);
|
|
|
21
21
|
__exportStar(require("./relay-cipher"), exports);
|
|
22
22
|
__exportStar(require("./relay-content"), exports);
|
|
23
23
|
__exportStar(require("./relay-conversation"), exports);
|
|
24
|
+
__exportStar(require("./relay-faces"), exports);
|
|
24
25
|
__exportStar(require("./relay-files"), exports);
|
|
25
26
|
__exportStar(require("./relay-hub"), exports);
|
|
26
27
|
__exportStar(require("./relay-hub-util"), exports);
|
|
27
28
|
__exportStar(require("./relay-hubs"), exports);
|
|
29
|
+
__exportStar(require("./relay-hubs-protocol"), exports);
|
|
28
30
|
__exportStar(require("./relay-identity"), exports);
|
|
29
31
|
__exportStar(require("./relay-pairing"), exports);
|
|
30
32
|
__exportStar(require("./relay-protocol"), exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** How many faces there are. */
|
|
2
|
+
export declare const FACE_COUNT = 16;
|
|
3
|
+
/** An element of SVG: its tag, its attributes as written in SVG (`stroke-width`, `class`), what is in it. */
|
|
4
|
+
export interface FaceNode {
|
|
5
|
+
tag: string;
|
|
6
|
+
attrs: Record<string, string | number>;
|
|
7
|
+
children?: FaceNode[];
|
|
8
|
+
}
|
|
9
|
+
export interface Look {
|
|
10
|
+
color: string;
|
|
11
|
+
/** Eyes and mouth. */
|
|
12
|
+
eye: string;
|
|
13
|
+
cheek: string;
|
|
14
|
+
/** A second colour of the shape: ears, a stem, an antenna. */
|
|
15
|
+
accent?: string;
|
|
16
|
+
/** The height of the eyes and how far apart they are. */
|
|
17
|
+
eyeY: number;
|
|
18
|
+
gap: number;
|
|
19
|
+
mouth?: string;
|
|
20
|
+
/** Brows pressed in, a grin. */
|
|
21
|
+
brows?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare namespace FaceUtil {
|
|
24
|
+
/** The face of an id: the same for the same id, on every device. */
|
|
25
|
+
function of(seed: string): number;
|
|
26
|
+
/** The face given, if it is one, else that of `seed`. */
|
|
27
|
+
function pick(face: number | undefined, seed?: string): number;
|
|
28
|
+
/** Its colour, for what draws no faces. */
|
|
29
|
+
function color(face: number): string;
|
|
30
|
+
/** What is in the `<svg viewBox="0 0 40 40">` of a face: its shape, then its cheeks, brows, eyes and mouth. */
|
|
31
|
+
function art(face: number): FaceNode;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=relay-faces.d.ts.map
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* The faces of those who are not Ta (agents, the people of rooms), framework-free so that Ta Web (ui.Face, React) and
|
|
4
|
+
* the page of web guests of the relay (src/guest, the DOM) draw the same: a small coloured shape with two eyes, cheeks
|
|
5
|
+
* and a mouth, one of FACE_COUNT, on a 40 × 40 grid. Their styles (`ta-face-eyes` blinks, `ta-face-look` looks
|
|
6
|
+
* about while at work) are those of the page that draws them.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.FaceUtil = exports.FACE_COUNT = void 0;
|
|
10
|
+
/** How many faces there are. */
|
|
11
|
+
exports.FACE_COUNT = 16;
|
|
12
|
+
const BLUE = '#4285F4';
|
|
13
|
+
const RED = '#EA4335';
|
|
14
|
+
const YELLOW = '#FBBC05';
|
|
15
|
+
const GREEN = '#34A853';
|
|
16
|
+
const MINT = '#5CC27F';
|
|
17
|
+
const ORANGE = '#EE7B3B';
|
|
18
|
+
const VIOLET = '#8C5CF0';
|
|
19
|
+
const CREAM = '#F1DFC0';
|
|
20
|
+
const TEAL = '#26B0A9';
|
|
21
|
+
const PINK = '#F27BA6';
|
|
22
|
+
const LILAC = '#B49CF5';
|
|
23
|
+
const SKY = '#45B5E8';
|
|
24
|
+
const INDIGO = '#5C6BC0';
|
|
25
|
+
const MIST = '#DCE3F0';
|
|
26
|
+
const INK = '#202124';
|
|
27
|
+
const WHITE = '#FFFFFF';
|
|
28
|
+
const CHEEK = 'rgba(255, 160, 185, 0.55)';
|
|
29
|
+
/** The edge of a light face. */
|
|
30
|
+
const EDGE = 'rgba(0, 0, 0, 0.14)';
|
|
31
|
+
const CHEEK_DEEP = 'rgba(120, 10, 30, 0.35)';
|
|
32
|
+
const CHEEK_WARM = 'rgba(234, 67, 53, 0.4)';
|
|
33
|
+
/** By face: the order is that of the shapes drawn in {@link shape}. */
|
|
34
|
+
const LOOKS = [
|
|
35
|
+
{ color: MINT, eye: '#1D3B27', cheek: CHEEK, eyeY: 21, gap: 8 }, // round
|
|
36
|
+
{ color: BLUE, eye: WHITE, cheek: CHEEK, eyeY: 23, gap: 8 }, // cat
|
|
37
|
+
{ color: RED, eye: WHITE, cheek: CHEEK_DEEP, eyeY: 22, gap: 8 }, // pentagon
|
|
38
|
+
{ color: CREAM, eye: '#4A3420', cheek: 'rgba(240, 120, 120, 0.5)', accent: '#DDBF8E', eyeY: 22, gap: 7.6 }, // bear
|
|
39
|
+
{ color: GREEN, eye: WHITE, cheek: CHEEK, eyeY: 19, gap: 7.2 }, // capsule
|
|
40
|
+
{ color: INDIGO, eye: WHITE, cheek: CHEEK, eyeY: 20, gap: 7.4 }, // diamond
|
|
41
|
+
{ color: YELLOW, eye: INK, cheek: CHEEK_WARM, accent: '#F29900', eyeY: 24, gap: 8.4 }, // bun
|
|
42
|
+
{ color: VIOLET, eye: '#22134A', cheek: CHEEK, eyeY: 20, gap: 8 }, // hexagon
|
|
43
|
+
{ color: MIST, eye: '#2B3245', cheek: CHEEK, eyeY: 19, gap: 7.6 }, // ghost
|
|
44
|
+
{ color: SKY, eye: WHITE, cheek: CHEEK, eyeY: 21, gap: 6.4 }, // star
|
|
45
|
+
{ color: ORANGE, eye: '#3D1C08', cheek: CHEEK, accent: GREEN, eyeY: 22, gap: 8.6, brows: true }, // pumpkin
|
|
46
|
+
{ color: WHITE, eye: WHITE, cheek: CHEEK, accent: INK, mouth: INK, eyeY: 22, gap: 10 }, // panda
|
|
47
|
+
{ color: TEAL, eye: WHITE, cheek: CHEEK, accent: '#1B8A84', eyeY: 22.5, gap: 8.4 }, // screen
|
|
48
|
+
{ color: PINK, eye: '#4A1428', cheek: 'rgba(160, 20, 70, 0.3)', eyeY: 24, gap: 7.4 }, // drop
|
|
49
|
+
{ color: LILAC, eye: '#2A1A5E', cheek: CHEEK, eyeY: 25, gap: 8 }, // rabbit
|
|
50
|
+
{ color: YELLOW, eye: INK, cheek: CHEEK_WARM, eyeY: 25, gap: 7.4 }, // triangle
|
|
51
|
+
];
|
|
52
|
+
/** The corners of a polygon of `count` sides around (cx, cy), the first straight up; `inner` makes it a star. */
|
|
53
|
+
function corners(count, radius, cx, cy, inner) {
|
|
54
|
+
const points = [];
|
|
55
|
+
const steps = inner ? count * 2 : count;
|
|
56
|
+
for (let index = 0; index < steps; index++) {
|
|
57
|
+
const r = inner && index % 2 === 1 ? inner : radius;
|
|
58
|
+
const angle = -Math.PI / 2 + (index * 2 * Math.PI) / steps;
|
|
59
|
+
points.push(`${(cx + r * Math.cos(angle)).toFixed(2)},${(cy + r * Math.sin(angle)).toFixed(2)}`);
|
|
60
|
+
}
|
|
61
|
+
return points.join(' ');
|
|
62
|
+
}
|
|
63
|
+
const PENTAGON = corners(5, 13.5, 20, 21.5);
|
|
64
|
+
const HEXAGON = corners(6, 14, 20, 20);
|
|
65
|
+
const STAR = corners(5, 15.5, 20, 21.5, 8.6);
|
|
66
|
+
function node(tag, attrs, children) {
|
|
67
|
+
return children ? { tag, attrs, children } : { tag, attrs };
|
|
68
|
+
}
|
|
69
|
+
/** A polygon with round corners: filled and stroked in the same colour. */
|
|
70
|
+
function rounded(points, color, width = 5) {
|
|
71
|
+
return node('polygon', { points, fill: color, stroke: color, 'stroke-width': width, 'stroke-linejoin': 'round' });
|
|
72
|
+
}
|
|
73
|
+
function shape(face, look) {
|
|
74
|
+
const { color, accent = color } = look;
|
|
75
|
+
switch (face) {
|
|
76
|
+
case 1:
|
|
77
|
+
return node('g', {}, [
|
|
78
|
+
rounded('7.5,6.5 17,12 8.5,18', color, 4),
|
|
79
|
+
rounded('32.5,6.5 23,12 31.5,18', color, 4),
|
|
80
|
+
node('ellipse', { cx: 20, cy: 23, rx: 14.5, ry: 12.5, fill: color }),
|
|
81
|
+
]);
|
|
82
|
+
case 2:
|
|
83
|
+
return rounded(PENTAGON, color);
|
|
84
|
+
case 3:
|
|
85
|
+
return node('g', {}, [
|
|
86
|
+
node('circle', { cx: 9.5, cy: 10.5, r: 5.5, fill: color }),
|
|
87
|
+
node('circle', { cx: 30.5, cy: 10.5, r: 5.5, fill: color }),
|
|
88
|
+
node('circle', { cx: 9.5, cy: 10.5, r: 2.6, fill: accent }),
|
|
89
|
+
node('circle', { cx: 30.5, cy: 10.5, r: 2.6, fill: accent }),
|
|
90
|
+
node('ellipse', { cx: 20, cy: 22.5, rx: 14.5, ry: 13, fill: color }),
|
|
91
|
+
]);
|
|
92
|
+
case 4:
|
|
93
|
+
return node('rect', { x: 8.5, y: 4, width: 23, height: 32, rx: 11.5, fill: color });
|
|
94
|
+
case 5:
|
|
95
|
+
return rounded('20,5.5 34.5,20 20,34.5 5.5,20', color, 5.5);
|
|
96
|
+
case 6:
|
|
97
|
+
return node('g', {}, [
|
|
98
|
+
node('ellipse', { cx: 20, cy: 11, rx: 3.2, ry: 3.6, fill: accent }),
|
|
99
|
+
node('path', { d: 'M20 12.5c9.2 0 15.5 5.6 15.5 12.4 0 6.4-6.9 10.1-15.5 10.1S4.5 31.3 4.5 24.9C4.5 18.1 10.8 12.5 20 12.5Z', fill: color }),
|
|
100
|
+
]);
|
|
101
|
+
case 7:
|
|
102
|
+
return rounded(HEXAGON, color);
|
|
103
|
+
case 8:
|
|
104
|
+
return node('path', {
|
|
105
|
+
d: 'M8 19a12 12 0 0 1 24 0v14l-4-3-4 3-4-3-4 3-4-3-4 3Z',
|
|
106
|
+
fill: color,
|
|
107
|
+
stroke: EDGE,
|
|
108
|
+
'stroke-width': 0.8,
|
|
109
|
+
'stroke-linejoin': 'round',
|
|
110
|
+
});
|
|
111
|
+
case 9:
|
|
112
|
+
return rounded(STAR, color, 4.5);
|
|
113
|
+
case 10:
|
|
114
|
+
return node('g', {}, [
|
|
115
|
+
node('rect', { x: 18.6, y: 4.5, width: 2.8, height: 7, rx: 1.4, fill: accent }),
|
|
116
|
+
node('ellipse', { cx: 12.5, cy: 23, rx: 8.5, ry: 11, fill: color }),
|
|
117
|
+
node('ellipse', { cx: 27.5, cy: 23, rx: 8.5, ry: 11, fill: color }),
|
|
118
|
+
node('ellipse', { cx: 20, cy: 22.5, rx: 9.5, ry: 12, fill: color }),
|
|
119
|
+
]);
|
|
120
|
+
case 11:
|
|
121
|
+
return node('g', {}, [
|
|
122
|
+
node('circle', { cx: 9.5, cy: 10, r: 5, fill: accent }),
|
|
123
|
+
node('circle', { cx: 30.5, cy: 10, r: 5, fill: accent }),
|
|
124
|
+
node('ellipse', { cx: 20, cy: 22.5, rx: 14.5, ry: 13, fill: color, stroke: EDGE, 'stroke-width': 0.8 }),
|
|
125
|
+
node('ellipse', { cx: 14.6, cy: 22, rx: 3.6, ry: 4.4, transform: 'rotate(20 14.6 22)', fill: accent }),
|
|
126
|
+
node('ellipse', { cx: 25.4, cy: 22, rx: 3.6, ry: 4.4, transform: 'rotate(-20 25.4 22)', fill: accent }),
|
|
127
|
+
]);
|
|
128
|
+
case 12:
|
|
129
|
+
return node('g', {}, [
|
|
130
|
+
node('rect', { x: 19.1, y: 6, width: 1.8, height: 7, fill: accent }),
|
|
131
|
+
node('circle', { cx: 20, cy: 5, r: 2.2, fill: accent }),
|
|
132
|
+
node('rect', { x: 5.5, y: 12, width: 29, height: 22.5, rx: 6.5, fill: color }),
|
|
133
|
+
]);
|
|
134
|
+
case 13:
|
|
135
|
+
return node('path', { d: 'M20 4.5c2 0 13 11.6 13 20.2 0 6.4-5.8 10.8-13 10.8S7 31.1 7 24.7C7 16.1 18 4.5 20 4.5Z', fill: color });
|
|
136
|
+
case 14:
|
|
137
|
+
return node('g', {}, [
|
|
138
|
+
node('ellipse', { cx: 14, cy: 10.5, rx: 3.6, ry: 8, transform: 'rotate(-8 14 10.5)', fill: color }),
|
|
139
|
+
node('ellipse', { cx: 26, cy: 10.5, rx: 3.6, ry: 8, transform: 'rotate(8 26 10.5)', fill: color }),
|
|
140
|
+
node('ellipse', { cx: 20, cy: 25, rx: 14, ry: 11, fill: color }),
|
|
141
|
+
]);
|
|
142
|
+
case 15:
|
|
143
|
+
return rounded('20,7 35,33 5,33', color, 6);
|
|
144
|
+
default:
|
|
145
|
+
return node('circle', { cx: 20, cy: 21, r: 14.5, fill: color });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
var FaceUtil;
|
|
149
|
+
(function (FaceUtil) {
|
|
150
|
+
/** The face of an id: the same for the same id, on every device. */
|
|
151
|
+
function of(seed) {
|
|
152
|
+
let hash = 0;
|
|
153
|
+
for (const char of seed) {
|
|
154
|
+
hash = (hash * 31 + char.charCodeAt(0)) | 0;
|
|
155
|
+
}
|
|
156
|
+
return Math.abs(hash) % exports.FACE_COUNT;
|
|
157
|
+
}
|
|
158
|
+
FaceUtil.of = of;
|
|
159
|
+
/** The face given, if it is one, else that of `seed`. */
|
|
160
|
+
function pick(face, seed = '') {
|
|
161
|
+
return face !== undefined && face >= 0 && face < exports.FACE_COUNT ? Math.floor(face) : of(seed);
|
|
162
|
+
}
|
|
163
|
+
FaceUtil.pick = pick;
|
|
164
|
+
/** Its colour, for what draws no faces. */
|
|
165
|
+
function color(face) {
|
|
166
|
+
var _a;
|
|
167
|
+
return ((_a = LOOKS[face]) !== null && _a !== void 0 ? _a : LOOKS[0]).color;
|
|
168
|
+
}
|
|
169
|
+
FaceUtil.color = color;
|
|
170
|
+
/** What is in the `<svg viewBox="0 0 40 40">` of a face: its shape, then its cheeks, brows, eyes and mouth. */
|
|
171
|
+
function art(face) {
|
|
172
|
+
var _a, _b;
|
|
173
|
+
const look = (_a = LOOKS[face]) !== null && _a !== void 0 ? _a : LOOKS[0];
|
|
174
|
+
const half = look.gap / 2;
|
|
175
|
+
const eyeW = 4.1;
|
|
176
|
+
const eyeH = 4.9;
|
|
177
|
+
const top = look.eyeY - eyeH / 2;
|
|
178
|
+
const cheekY = look.eyeY + 3.6;
|
|
179
|
+
const cheekX = half + 2.2;
|
|
180
|
+
const mouthY = look.eyeY + 3.4;
|
|
181
|
+
const features = [
|
|
182
|
+
node('g', { fill: look.cheek }, [
|
|
183
|
+
node('ellipse', { cx: 20 - cheekX, cy: cheekY, rx: 2.2, ry: 1.25 }),
|
|
184
|
+
node('ellipse', { cx: 20 + cheekX, cy: cheekY, rx: 2.2, ry: 1.25 }),
|
|
185
|
+
]),
|
|
186
|
+
];
|
|
187
|
+
if (look.brows) {
|
|
188
|
+
features.push(node('path', {
|
|
189
|
+
d: `M${20 - half - 3.4} ${top - 2.6}l3.6 1.6M${20 + half + 3.4} ${top - 2.6}l-3.6 1.6`,
|
|
190
|
+
stroke: look.eye,
|
|
191
|
+
'stroke-width': 1.4,
|
|
192
|
+
'stroke-linecap': 'round',
|
|
193
|
+
fill: 'none',
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
features.push(node('g', { class: 'ta-face-eyes', fill: look.eye }, [
|
|
197
|
+
node('rect', { x: 20 - half - eyeW / 2, y: top, width: eyeW, height: eyeH, rx: eyeW / 2 }),
|
|
198
|
+
node('rect', { x: 20 + half - eyeW / 2, y: top, width: eyeW, height: eyeH, rx: eyeW / 2 }),
|
|
199
|
+
]), node('path', {
|
|
200
|
+
d: `M18.1 ${mouthY}q.95 1.25 1.9 0q.95 1.25 1.9 0`,
|
|
201
|
+
fill: 'none',
|
|
202
|
+
stroke: (_b = look.mouth) !== null && _b !== void 0 ? _b : look.eye,
|
|
203
|
+
'stroke-width': 1.1,
|
|
204
|
+
'stroke-linecap': 'round',
|
|
205
|
+
'stroke-linejoin': 'round',
|
|
206
|
+
}));
|
|
207
|
+
return node('g', { class: 'ta-face-body' }, [shape(face, look), node('g', { class: 'ta-face-look' }, features)]);
|
|
208
|
+
}
|
|
209
|
+
FaceUtil.art = art;
|
|
210
|
+
})(FaceUtil || (exports.FaceUtil = FaceUtil = {}));
|
|
211
|
+
//# sourceMappingURL=relay-faces.js.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type RelayHubAskBody, type RelayHubKeys, type RelayHubMember, type RelayHubRosterBody } from './relay-hub-util';
|
|
2
|
+
import type { RelayFriend, RelayHubsOptions, RelayRoomEvent, RelayRoomRecord, RelayRoomRequest, RelayRoomStatus, RelayRoomValue } from './relay-hubs-protocol';
|
|
3
|
+
import { type RelayIdentity, type RelayPublicIdentity } from './relay-identity';
|
|
4
|
+
import { type RelayHubEntry, type RelayHubFailure, type RelayHubRequest } from './relay-protocol';
|
|
5
|
+
/** What a member sends in a message, signed and sealed: data of an extension, or a word of Ta itself. */
|
|
6
|
+
export interface MessageBody {
|
|
7
|
+
d?: unknown;
|
|
8
|
+
/** A member's new name, for the owner to put in the roster. */
|
|
9
|
+
name?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface StateBody {
|
|
12
|
+
key: string;
|
|
13
|
+
value: unknown;
|
|
14
|
+
}
|
|
15
|
+
/** How long a call waits for the room to be connected, or for the relay to answer. */
|
|
16
|
+
export declare const READY_MS = 15000;
|
|
17
|
+
export declare const OPEN = 1;
|
|
18
|
+
/** A room as this Ta holds it while it runs: its connection and what it knows of the room. */
|
|
19
|
+
export declare class Live {
|
|
20
|
+
record: RelayRoomRecord;
|
|
21
|
+
socket?: WebSocket;
|
|
22
|
+
keys?: RelayHubKeys;
|
|
23
|
+
synced: boolean;
|
|
24
|
+
online: Set<string>;
|
|
25
|
+
roster?: RelayHubRosterBody;
|
|
26
|
+
readonly state: Map<string, RelayRoomValue>;
|
|
27
|
+
/** Asks to join, with the invitation each came with. */
|
|
28
|
+
readonly asks: Map<string, {
|
|
29
|
+
body: RelayHubAskBody;
|
|
30
|
+
invite: string;
|
|
31
|
+
}>;
|
|
32
|
+
readonly done: Map<number, (result: {
|
|
33
|
+
ok: boolean;
|
|
34
|
+
v: number;
|
|
35
|
+
error?: RelayHubFailure;
|
|
36
|
+
}) => void>;
|
|
37
|
+
readonly ready: Array<() => void>;
|
|
38
|
+
attempts: number;
|
|
39
|
+
/** Connect again at once, whatever the close said. */
|
|
40
|
+
retry: boolean;
|
|
41
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
42
|
+
pingTimer?: ReturnType<typeof setInterval>;
|
|
43
|
+
awaitingPong: boolean;
|
|
44
|
+
/** Events are handled one after another: opening them is async. */
|
|
45
|
+
chain: Promise<void>;
|
|
46
|
+
constructor(record: RelayRoomRecord);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The half of {@link RelayHubs} that keeps a connection to the hub of each room and reads what comes over it:
|
|
50
|
+
* connecting again, the welcome, the roster, the state and the messages, each opened and checked against the
|
|
51
|
+
* signatures of the roster; what is kept of the rooms and the friends.
|
|
52
|
+
*/
|
|
53
|
+
export declare abstract class RelayHubsConnection {
|
|
54
|
+
protected readonly options: RelayHubsOptions;
|
|
55
|
+
protected readonly live: Map<string, Live>;
|
|
56
|
+
protected readonly listeners: Set<(event: RelayRoomEvent) => void>;
|
|
57
|
+
protected own?: RelayIdentity;
|
|
58
|
+
/** Asks the user was told of while this runs: those the owner finds waiting when it connects are told once. */
|
|
59
|
+
protected readonly told: Set<string>;
|
|
60
|
+
protected stopped: boolean;
|
|
61
|
+
protected nextId: number;
|
|
62
|
+
constructor(options: RelayHubsOptions);
|
|
63
|
+
/** This Ta's identity, made the first time. */
|
|
64
|
+
identity(): Promise<RelayIdentity>;
|
|
65
|
+
protected requestOf(live: Live, ask: RelayHubAskBody, friends: Set<string>): RelayRoomRequest;
|
|
66
|
+
/** Resolves once the room is connected and has its state; rejects after a while. */
|
|
67
|
+
protected ready(live: Live): Promise<void>;
|
|
68
|
+
protected request(live: Live, request: RelayHubRequest): void;
|
|
69
|
+
protected sendBody(live: Live, body: MessageBody, to?: string): Promise<void>;
|
|
70
|
+
/** The roster with `change` made, its version one more, signed by the owner. */
|
|
71
|
+
protected nextRoster(live: Live, change: (members: RelayHubMember[]) => RelayHubMember[]): Promise<{
|
|
72
|
+
v: number;
|
|
73
|
+
d: string;
|
|
74
|
+
}>;
|
|
75
|
+
protected writeRoster(live: Live, change: (members: RelayHubMember[]) => RelayHubMember[]): Promise<void>;
|
|
76
|
+
protected connect(live: Live): void;
|
|
77
|
+
protected hello(live: Live, socket: WebSocket): Promise<void>;
|
|
78
|
+
protected closed(live: Live, code: number): void;
|
|
79
|
+
protected disconnect(live: Live): void;
|
|
80
|
+
protected receive(live: Live, text: string): Promise<void>;
|
|
81
|
+
protected failed(live: Live, code: RelayHubFailure): void;
|
|
82
|
+
protected setStatus(live: Live, status: RelayRoomStatus, reason?: RelayRoomRecord['reason']): void;
|
|
83
|
+
protected admitted(live: Live, answer: string): Promise<void>;
|
|
84
|
+
/** An ask to join: told as a request the first time this Ta hears it; `fresh` when it came now, not with the welcome. */
|
|
85
|
+
protected asked(live: Live, sealed: string, fresh: boolean): Promise<void>;
|
|
86
|
+
protected readRoster(live: Live, sealed: string): Promise<void>;
|
|
87
|
+
protected guestOf(live: Live, member: string): boolean;
|
|
88
|
+
protected signOf(live: Live): (member: string) => string | undefined;
|
|
89
|
+
protected readEntry(live: Live, entry: RelayHubEntry, tell: boolean): Promise<void>;
|
|
90
|
+
protected readMessage(live: Live, from: string, sealed: string): Promise<void>;
|
|
91
|
+
/** Those of a room are friends: kept with their keys and the rooms shared. */
|
|
92
|
+
protected meet(title: string, members: RelayPublicIdentity[]): void;
|
|
93
|
+
protected friendIds(): Set<string>;
|
|
94
|
+
protected readFriends(): RelayFriend[];
|
|
95
|
+
protected readRooms(): RelayRoomRecord[];
|
|
96
|
+
protected save(): void;
|
|
97
|
+
protected emit(event: RelayRoomEvent): void;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=relay-hubs-connection.d.ts.map
|