@celljs/ta-relay 4.11.0 → 4.13.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 (86) hide show
  1. package/README.en.md +26 -1
  2. package/README.md +26 -1
  3. package/esm/common/index.d.ts +5 -0
  4. package/esm/common/index.js +5 -0
  5. package/esm/common/relay-faces.d.ts +32 -0
  6. package/esm/common/relay-faces.js +208 -0
  7. package/esm/common/relay-friends.d.ts +154 -0
  8. package/esm/common/relay-friends.js +482 -0
  9. package/esm/common/relay-hub-util.d.ts +9 -0
  10. package/esm/common/relay-hub-util.js +19 -2
  11. package/esm/common/relay-hubs-connection.d.ts +110 -0
  12. package/esm/common/relay-hubs-connection.js +508 -0
  13. package/esm/common/relay-hubs-protocol.d.ts +174 -0
  14. package/esm/common/relay-hubs-protocol.js +2 -0
  15. package/esm/common/relay-hubs.d.ts +68 -216
  16. package/esm/common/relay-hubs.js +303 -507
  17. package/esm/common/relay-identity.d.ts +2 -0
  18. package/esm/common/relay-info.d.ts +44 -0
  19. package/esm/common/relay-info.js +94 -0
  20. package/esm/common/relay-protocol.d.ts +7 -3
  21. package/esm/common/relay-protocol.js +7 -3
  22. package/esm/common/relay-room-chat.d.ts +36 -2
  23. package/esm/common/relay-room-chat.js +32 -7
  24. package/esm/common/relay-spot.d.ts +122 -0
  25. package/esm/common/relay-spot.js +179 -0
  26. package/esm/guest/guest-i18n.d.ts +5 -0
  27. package/esm/guest/guest-i18n.js +10 -0
  28. package/esm/guest/guest-style.d.ts +1 -1
  29. package/esm/guest/guest-style.js +11 -4
  30. package/esm/guest/guest.js +39 -18
  31. package/esm/node/index.d.ts +2 -0
  32. package/esm/node/index.js +2 -0
  33. package/esm/node/relay-file-storage.d.ts +32 -0
  34. package/esm/node/relay-file-storage.js +101 -0
  35. package/esm/node/relay-host.d.ts +63 -28
  36. package/esm/node/relay-host.js +145 -52
  37. package/esm/node/relay-hub-files.d.ts +1 -1
  38. package/esm/node/relay-server.d.ts +37 -3
  39. package/esm/node/relay-server.js +193 -37
  40. package/esm/node/relay-store.d.ts +34 -6
  41. package/esm/node/relay-store.js +54 -22
  42. package/esm/node/relays-file.d.ts +139 -0
  43. package/esm/node/relays-file.js +373 -0
  44. package/lib/common/index.d.ts +5 -0
  45. package/lib/common/index.js +5 -0
  46. package/lib/common/relay-faces.d.ts +33 -0
  47. package/lib/common/relay-faces.js +211 -0
  48. package/lib/common/relay-friends.d.ts +155 -0
  49. package/lib/common/relay-friends.js +486 -0
  50. package/lib/common/relay-hub-util.d.ts +9 -0
  51. package/lib/common/relay-hub-util.js +19 -2
  52. package/lib/common/relay-hubs-connection.d.ts +111 -0
  53. package/lib/common/relay-hubs-connection.js +513 -0
  54. package/lib/common/relay-hubs-protocol.d.ts +175 -0
  55. package/lib/common/relay-hubs-protocol.js +3 -0
  56. package/lib/common/relay-hubs.d.ts +68 -216
  57. package/lib/common/relay-hubs.js +311 -515
  58. package/lib/common/relay-identity.d.ts +2 -0
  59. package/lib/common/relay-info.d.ts +45 -0
  60. package/lib/common/relay-info.js +97 -0
  61. package/lib/common/relay-protocol.d.ts +7 -3
  62. package/lib/common/relay-protocol.js +8 -4
  63. package/lib/common/relay-room-chat.d.ts +36 -2
  64. package/lib/common/relay-room-chat.js +32 -7
  65. package/lib/common/relay-spot.d.ts +123 -0
  66. package/lib/common/relay-spot.js +183 -0
  67. package/lib/guest/guest-i18n.d.ts +5 -0
  68. package/lib/guest/guest-i18n.js +10 -0
  69. package/lib/guest/guest-style.d.ts +1 -1
  70. package/lib/guest/guest-style.js +11 -4
  71. package/lib/guest/guest.js +39 -18
  72. package/lib/node/index.d.ts +2 -0
  73. package/lib/node/index.js +2 -0
  74. package/lib/node/relay-file-storage.d.ts +33 -0
  75. package/lib/node/relay-file-storage.js +105 -0
  76. package/lib/node/relay-host.d.ts +63 -28
  77. package/lib/node/relay-host.js +146 -53
  78. package/lib/node/relay-hub-files.d.ts +1 -1
  79. package/lib/node/relay-server.d.ts +37 -3
  80. package/lib/node/relay-server.js +193 -37
  81. package/lib/node/relay-store.d.ts +34 -6
  82. package/lib/node/relay-store.js +54 -22
  83. package/lib/node/relays-file.d.ts +140 -0
  84. package/lib/node/relays-file.js +378 -0
  85. package/package.json +2 -2
  86. package/viewer/room.html +21 -14
@@ -1,6 +1,7 @@
1
1
  const zh = {
2
2
  title: 'Ta 房间',
3
3
  invalid: '这不是一个完整的 Ta 房间邀请链接,请检查是否复制完整。',
4
+ inTa: '这是{by}在 Ta 里的加好友链接,要在 Ta 里打开:用 Ta 扫码,或把链接粘贴到 Ta 的快捷打开。',
4
5
  invited: '{by}邀请你加入',
5
6
  joinHint: '房主同意后,就能在这里和大家聊天。',
6
7
  name: '你的名字',
@@ -26,6 +27,10 @@ const zh = {
26
27
  owner: '房主',
27
28
  you: '我',
28
29
  guest: '网页访客',
30
+ doubleOf: '{name}的分身',
31
+ double: '分身',
32
+ task: '任务',
33
+ agentOf: '{name}的智能体',
29
34
  rename: '修改我的名字',
30
35
  leave: '退出房间',
31
36
  leaveAsk: '退出「{title}」?退出后要有新的邀请才能再进来。',
@@ -40,6 +45,7 @@ const zh = {
40
45
  const en = {
41
46
  title: 'A room of Ta',
42
47
  invalid: 'This is not a whole link that invites into a room of Ta: check it was copied in full.',
48
+ inTa: 'This link of {by} adds them as a friend in Ta, and opens in Ta: scan it with Ta, or paste it in Quick open of Ta.',
43
49
  invited: '{by} invites you to join',
44
50
  joinHint: 'Once the owner lets you in, you chat with everyone here.',
45
51
  name: 'Your name',
@@ -65,6 +71,10 @@ const en = {
65
71
  owner: 'Owner',
66
72
  you: 'You',
67
73
  guest: 'Web guest',
74
+ doubleOf: "{name}'s double",
75
+ double: 'Double',
76
+ task: 'Task',
77
+ agentOf: "{name}'s agent",
68
78
  rename: 'Change my name',
69
79
  leave: 'Leave the room',
70
80
  leaveAsk: 'Leave “{title}”? You come back only by a new invitation.',
@@ -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-grid;place-items:center;border-radius:50%;font-weight:600;line-height:1;user-select:none;position:relative}\n.t0{background:#e6f4ea;color:#166534}.t1{background:#e8f0fe;color:#1d4ed8}.t2{background:#fdf0e6;color:#b45309}.t3{background:#f3e8fd;color:#7e22ce}.t4{background:#fde8ef;color:#be185d}.t5{background:#e6f6f8;color:#0e7490}\n@media (prefers-color-scheme:dark){.t0{background:#1d3326;color:#86efac}.t1{background:#1e2a44;color:#93c5fd}.t2{background:#3a2a1a;color:#fdba74}.t3{background:#2e2140;color:#d8b4fe}.t4{background:#3a1f2a;color:#f9a8d4}.t5{background:#173238;color:#67e8f9}}\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{margin:0 2px 4px;color:var(--muted);font-size:12px;line-height:16px}\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";
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";
@@ -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-grid;place-items:center;border-radius:50%;font-weight:600;line-height:1;user-select:none;position:relative}
35
- .t0{background:#e6f4ea;color:#166534}.t1{background:#e8f0fe;color:#1d4ed8}.t2{background:#fdf0e6;color:#b45309}.t3{background:#f3e8fd;color:#7e22ce}.t4{background:#fde8ef;color:#be185d}.t5{background:#e6f6f8;color:#0e7490}
36
- @media (prefers-color-scheme:dark){.t0{background:#1d3326;color:#86efac}.t1{background:#1e2a44;color:#93c5fd}.t2{background:#3a2a1a;color:#fdba74}.t3{background:#2e2140;color:#d8b4fe}.t4{background:#3a1f2a;color:#f9a8d4}.t5{background:#173238;color:#67e8f9}}
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)}
@@ -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
- function tint(id) {
45
- let hash = 0;
46
- for (const char of id) {
47
- hash = (hash * 31 + char.charCodeAt(0)) | 0;
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
- return Math.abs(hash) % 6;
52
+ element.append(...((_a = node.children) !== null && _a !== void 0 ? _a : []).map(svg));
53
+ return element;
50
54
  }
51
- function face(id, name, size, online) {
52
- var _a;
53
- var _b;
54
- const node = el('span', (_b = (_a = Array.from(name.trim())[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : '?');
55
- node.className = `face t${tint(id)}`;
56
- node.style.cssText = `width:${size}px;height:${size}px;font-size:${Math.round(size * 0.42)}px`;
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, this.link.by || '?', 56), { className: `face card-face t${tint(this.link.owner)}` }), 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' })));
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,36 @@ 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 nameOf = (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; };
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') : '', line.task ? t('task') : '']
294
+ .filter(Boolean)
295
+ .join(' · ');
296
+ 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
297
  const nodes = [];
285
298
  if (!lines.length) {
286
299
  nodes.push(div('empty', t('empty')));
287
300
  }
288
301
  lines.forEach((line, index) => {
289
302
  var _a;
303
+ var _b, _c;
290
304
  const before = lines[index - 1];
291
305
  const separator = !before || line.at - before.at > PAUSE_MS;
292
- const first = separator || before.from !== line.from || line.at - before.at > RUN_MS;
306
+ const first = separator || speaker(before) !== speaker(line) || line.at - before.at > RUN_MS;
293
307
  if (separator) {
294
308
  nodes.push(div('when', GuestI18n.time(line.at)));
295
309
  }
296
310
  const bubble = div('bubble', ViewerMarkdown.render(line.text));
297
311
  bubble.title = GuestI18n.time(line.at);
298
- if (line.from === self) {
312
+ if (line.from === self && !line.agent) {
299
313
  nodes.push(div('mine', bubble));
300
314
  return;
301
315
  }
302
316
  const other = room.members.find(member => member.member === line.from);
303
- const col = div('col', ...(first ? [div('who', nameOf(line))] : []), bubble);
304
- nodes.push(div(`msg${first ? ' first' : ''}`, div('slot', ...(first ? [face((_a = other === null || other === void 0 ? void 0 : other.id) !== null && _a !== void 0 ? _a : line.from, nameOf(line), 32)] : [])), col));
317
+ const tag = tagOf(line);
318
+ const col = div('col', ...(first ? [div('who', nameOf(line), ...(tag ? [div('tag', tag)] : []))] : []), bubble);
319
+ 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
320
  });
306
321
  list.replaceChildren(...nodes);
307
322
  if (this.stuck) {
@@ -320,7 +335,7 @@ class GuestPage {
320
335
  const tags = [member.self ? t('you') : '', member.owner ? t('owner') : '', member.guest ? t('guest') : ''].filter(Boolean);
321
336
  const name = div('nm', member.name, ...tags.map(tag => Object.assign(el('span', tag), { className: 'tag' })));
322
337
  const status = Object.assign(el('span', member.online ? t('onlineNow') : ''), { className: 'st on' });
323
- panel.append(div('member', face(member.id, member.name, 32, member.online), name, status));
338
+ panel.append(div('member', face(member.id, 34, member.online), name, status));
324
339
  }
325
340
  panel.append(div('sep'), button('row', t('rename'), () => {
326
341
  var _a, _b;
@@ -364,6 +379,12 @@ function main() {
364
379
  document.body.replaceChildren(div('app', div('top', logo), div('center', Object.assign(el('p', t('invalid')), { className: 'hint' }))));
365
380
  return;
366
381
  }
382
+ if (link.kind) {
383
+ // A room a package keeps for itself (friends of Moments): only a Ta joins it.
384
+ const logo = Object.assign(el('span', 'Ta'), { className: 'logo' });
385
+ document.body.replaceChildren(div('app', div('top', logo), div('center', Object.assign(el('p', t('inTa', { by: link.by })), { className: 'hint' }))));
386
+ return;
387
+ }
367
388
  new GuestPage(link).start();
368
389
  }
369
390
  addEventListener('hashchange', () => location.reload());
@@ -1,7 +1,9 @@
1
1
  export * from '../common/index.js';
2
+ export * from './relay-file-storage.js';
2
3
  export * from './relay-files-host.js';
3
4
  export * from './relay-host.js';
4
5
  export * from './relay-hub-files.js';
5
6
  export * from './relay-server.js';
6
7
  export * from './relay-store.js';
7
8
  export * from './relay-viewer.js';
9
+ export * from './relays-file.js';
package/esm/node/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export * from '../common/index.js';
2
+ export * from './relay-file-storage.js';
2
3
  export * from './relay-files-host.js';
3
4
  export * from './relay-host.js';
4
5
  export * from './relay-hub-files.js';
5
6
  export * from './relay-server.js';
6
7
  export * from './relay-store.js';
7
8
  export * from './relay-viewer.js';
9
+ export * from './relays-file.js';
8
10
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,32 @@
1
+ import type { RelayBlobStorage } from '../common/relay-blobs.js';
2
+ import type { RelayHubStorage } from '../common/relay-hub.js';
3
+ /**
4
+ * What `ta relay --data <dir>` keeps of a room or a copy, as a Durable Object keeps it: one directory each, the values in
5
+ * memory and in one file, written whole after each change (rooms hold at most a few megabytes, copies eight).
6
+ */
7
+ export declare class FileRelayStorage implements RelayHubStorage, RelayBlobStorage {
8
+ protected readonly dir: string;
9
+ /** Its alarm ran: what it held went with it (a copy that ran out, a room unused for long). */
10
+ protected readonly onAlarm?: (() => void) | undefined;
11
+ protected readonly values: Map<string, unknown>;
12
+ protected readonly file: string;
13
+ protected timer?: ReturnType<typeof setTimeout>;
14
+ constructor(dir: string,
15
+ /** Its alarm ran: what it held went with it (a copy that ran out, a room unused for long). */
16
+ onAlarm?: (() => void) | undefined);
17
+ /** The ids of what a directory of the relay holds. */
18
+ static ids(root: string): string[];
19
+ get empty(): boolean;
20
+ get<T>(key: string): Promise<T | undefined>;
21
+ put(key: string, value: unknown): Promise<void>;
22
+ delete(key: string): Promise<boolean>;
23
+ list<T>(options: {
24
+ prefix: string;
25
+ }): Promise<Map<string, T>>;
26
+ deleteAll(): Promise<void>;
27
+ setAlarm(at: number): Promise<void>;
28
+ close(): void;
29
+ protected schedule(at: number): void;
30
+ protected save(): void;
31
+ protected static load(file: string): Map<string, unknown>;
32
+ }
@@ -0,0 +1,101 @@
1
+ import { mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { RelayBytes } from '../common/relay-bytes.js';
4
+ const encode = (value) => (value instanceof Uint8Array ? { b: RelayBytes.toBase64(value) } : { j: value });
5
+ const decode = (stored) => ('b' in stored ? RelayBytes.fromBase64(stored.b) : stored.j);
6
+ /**
7
+ * What `ta relay --data <dir>` keeps of a room or a copy, as a Durable Object keeps it: one directory each, the values in
8
+ * memory and in one file, written whole after each change (rooms hold at most a few megabytes, copies eight).
9
+ */
10
+ export class FileRelayStorage {
11
+ constructor(dir,
12
+ /** Its alarm ran: what it held went with it (a copy that ran out, a room unused for long). */
13
+ onAlarm) {
14
+ this.dir = dir;
15
+ this.onAlarm = onAlarm;
16
+ this.file = join(dir, 'values.json');
17
+ this.values = FileRelayStorage.load(this.file);
18
+ const alarm = this.values.get(ALARM);
19
+ if (typeof alarm === 'number') {
20
+ this.schedule(alarm);
21
+ }
22
+ }
23
+ /** The ids of what a directory of the relay holds. */
24
+ static ids(root) {
25
+ try {
26
+ return readdirSync(root, { withFileTypes: true })
27
+ .filter(entry => entry.isDirectory())
28
+ .map(entry => entry.name);
29
+ }
30
+ catch (_a) {
31
+ return [];
32
+ }
33
+ }
34
+ get empty() {
35
+ return [...this.values.keys()].every(key => key === ALARM);
36
+ }
37
+ async get(key) {
38
+ const value = this.values.get(key);
39
+ return value === undefined ? undefined : structuredClone(value);
40
+ }
41
+ async put(key, value) {
42
+ this.values.set(key, structuredClone(value));
43
+ this.save();
44
+ }
45
+ async delete(key) {
46
+ const had = this.values.delete(key);
47
+ this.save();
48
+ return had;
49
+ }
50
+ async list(options) {
51
+ const found = new Map();
52
+ for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
53
+ if (key !== ALARM && key.startsWith(options.prefix)) {
54
+ found.set(key, structuredClone(value));
55
+ }
56
+ }
57
+ return found;
58
+ }
59
+ async deleteAll() {
60
+ this.values.clear();
61
+ clearTimeout(this.timer);
62
+ rmSync(this.dir, { recursive: true, force: true });
63
+ }
64
+ async setAlarm(at) {
65
+ this.values.set(ALARM, at);
66
+ this.save();
67
+ this.schedule(at);
68
+ }
69
+ close() {
70
+ clearTimeout(this.timer);
71
+ }
72
+ schedule(at) {
73
+ var _a, _b;
74
+ clearTimeout(this.timer);
75
+ // Past the 24 days of a timer, it is set again then.
76
+ const wait = Math.max(at - Date.now(), 0);
77
+ this.timer = setTimeout(() => { var _a; return (wait > 2 ** 31 - 1 ? this.schedule(at) : (_a = this.onAlarm) === null || _a === void 0 ? void 0 : _a.call(this)); }, Math.min(wait, 2 ** 31 - 1));
78
+ (_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
79
+ }
80
+ save() {
81
+ if (this.empty) {
82
+ rmSync(this.dir, { recursive: true, force: true });
83
+ return;
84
+ }
85
+ mkdirSync(this.dir, { recursive: true, mode: 0o700 });
86
+ const temporary = `${this.file}.${process.pid}.tmp`;
87
+ writeFileSync(temporary, JSON.stringify(Object.fromEntries([...this.values].map(([key, value]) => [key, encode(value)]))), { mode: 0o600 });
88
+ renameSync(temporary, this.file);
89
+ }
90
+ static load(file) {
91
+ try {
92
+ const data = JSON.parse(readFileSync(file, 'utf8'));
93
+ return new Map(Object.entries(data).map(([key, stored]) => [key, decode(stored)]));
94
+ }
95
+ catch (_a) {
96
+ return new Map();
97
+ }
98
+ }
99
+ }
100
+ const ALARM = '\u0000alarm';
101
+ //# sourceMappingURL=relay-file-storage.js.map
@@ -2,7 +2,7 @@ import { RelayCipher } from '../common/relay-cipher.js';
2
2
  import { type RelayFilesFrame } from '../common/relay-files.js';
3
3
  import { RELAY_PING, type RelayHostMessage, type RelayWelcome } from '../common/relay-protocol.js';
4
4
  import { RelayFilesHost } from './relay-files-host.js';
5
- import type { RelayContentShare, RelayShare, RelayStore } from './relay-store.js';
5
+ import { type RelayContentShare, type RelayShare, RelayStore } from './relay-store.js';
6
6
  export interface RelayHostOptions {
7
7
  store: RelayStore;
8
8
  /** The WebSocket of this ta serve, with its token: every device gets a connection to it of its own. */
@@ -16,6 +16,10 @@ export interface RelayHostOptions {
16
16
  /** Hands on the content shared in the store (RelayStore.contents) to whoever has its link; without it, such links are refused. */
17
17
  shareContent?: boolean;
18
18
  }
19
+ export declare namespace RelayHostUtil {
20
+ /** The WebSocket of ta serve for a device: with its id, so that ta serve makes its calls as the one it belongs to. */
21
+ function localUrl(base: string, deviceId: string | undefined): string;
22
+ }
19
23
  /**
20
24
  * A device on a channel: the handshake, then its connection to ta serve — or, for a channel that asked
21
25
  * for files (RelayFiles, RelayFilesHost), the file it asks for. What a channel is, it says in its first
@@ -23,7 +27,7 @@ export interface RelayHostOptions {
23
27
  */
24
28
  declare class RelayChannel {
25
29
  readonly id: string;
26
- protected readonly host: RelayHost;
30
+ protected readonly host: RelayUplink;
27
31
  protected readonly options: RelayHostOptions;
28
32
  protected cipher?: RelayCipher;
29
33
  protected local?: WebSocket;
@@ -34,13 +38,17 @@ declare class RelayChannel {
34
38
  /** Content shared with Ta friends: a cipher with the key of each, till the proof of one opens. */
35
39
  protected candidates?: RelayCipher[];
36
40
  protected files?: RelayFilesHost;
41
+ /** The paired device on this channel: ta serve is told which, to know whose calls they are. */
42
+ protected deviceId?: string;
37
43
  protected readonly early: string[];
38
44
  /** Agreed in the hello of a viewer of content, set once it proved. */
39
45
  protected compress: boolean;
40
46
  protected proofTimer?: ReturnType<typeof setTimeout>;
41
47
  protected readonly timer: NodeJS.Timeout;
42
- constructor(id: string, host: RelayHost, options: RelayHostOptions);
48
+ constructor(id: string, host: RelayUplink, options: RelayHostOptions);
43
49
  receive(text: string): Promise<void>;
50
+ /** A paired device on ta serve or its files, not one holding a link. */
51
+ get device(): boolean;
44
52
  /** From the relay: the device is gone. */
45
53
  closed(): void;
46
54
  /** A frame of the files of the workspace, sealed as the rest. */
@@ -56,43 +64,39 @@ declare class RelayChannel {
56
64
  protected answer(welcome: RelayWelcome): void;
57
65
  protected close(): void;
58
66
  }
67
+ /** What a channel needs of the connection it came over. */
68
+ interface RelayUplinkOwner {
69
+ readonly options: RelayHostOptions;
70
+ blocked(contentId: string): boolean;
71
+ wrongKey(contentId: string): void;
72
+ }
59
73
  /**
60
- * ta serve at the relay: one WebSocket out to it, over which the paired devices come in, each on a
61
- * channel of its own. A device that knows its key gets a connection to ta serve; nothing else does, and
62
- * the relay sees only what the two seal.
74
+ * ta serve at one relay: one WebSocket out to it, over which the devices and links of that relay come in, each on a
75
+ * channel of its own.
63
76
  */
64
- export declare class RelayHost {
65
- protected readonly options: RelayHostOptions;
77
+ declare class RelayUplink {
78
+ /** The relay, without a trailing slash. */
79
+ readonly relay: string;
80
+ protected readonly target: string;
81
+ protected readonly owner: RelayUplinkOwner;
66
82
  protected socket?: WebSocket;
67
- /** Where {@link socket} goes: WebSocket.url is normalised. */
68
- protected target?: string;
69
83
  protected stopped: boolean;
70
84
  protected attempts: number;
71
85
  protected timer?: ReturnType<typeof setTimeout>;
72
86
  protected pingTimer?: ReturnType<typeof setInterval>;
73
- protected readonly channels: Map<string, RelayChannel>;
74
- /** Wrong keys of each share of content, of late. */
75
- protected readonly wrong: Map<string, {
76
- count: number;
77
- since: number;
78
- }>;
79
- constructor(options: RelayHostOptions);
80
- /** @internal Whether a share of content had too many wrong keys of late. */
81
- blocked(contentId: string, now?: number): boolean;
82
- /** @internal */
83
- wrongKey(contentId: string, now?: number): void;
84
- /** Whether the connection to the relay is open. */
87
+ readonly channels: Map<string, RelayChannel>;
88
+ constructor(
89
+ /** The relay, without a trailing slash. */
90
+ relay: string, target: string, owner: RelayUplinkOwner);
85
91
  get online(): boolean;
86
- /** Connects when relay.json has a relay and a device, and keeps connected; checks again on {@link refresh}. */
92
+ get devicesOpen(): number;
87
93
  start(): void;
88
- /** relay.json may have changed: connect if it now has devices, or leave if it has none. */
89
- refresh(): void;
90
94
  stop(): void;
91
- /** @internal */
95
+ blocked(contentId: string): boolean;
96
+ wrongKey(contentId: string): void;
92
97
  send(message: RelayHostMessage | typeof RELAY_PING): void;
93
- /** @internal */
94
98
  closeChannel(id: string): void;
95
- protected connect(target: string): void;
99
+ protected connect(): void;
96
100
  /**
97
101
  * The heartbeat of the connection to the relay. Without it a connection gone without a word (through
98
102
  * a proxy, a network that changed, a computer that slept) would look open for good, its devices told
@@ -106,4 +110,35 @@ export declare class RelayHost {
106
110
  protected disconnect(): void;
107
111
  protected closeChannels(): void;
108
112
  }
113
+ /**
114
+ * ta serve at its relays: one WebSocket out to each relay its devices and links are on (relay.json), over which they
115
+ * come in, each on a channel of its own. A device that knows its key gets a connection to ta serve; nothing else
116
+ * does, and a relay sees only what the two seal.
117
+ */
118
+ export declare class RelayHost implements RelayUplinkOwner {
119
+ readonly options: RelayHostOptions;
120
+ protected stopped: boolean;
121
+ protected readonly uplinks: Map<string, RelayUplink>;
122
+ /** Wrong keys of each share of content, of late. */
123
+ protected readonly wrong: Map<string, {
124
+ count: number;
125
+ since: number;
126
+ }>;
127
+ constructor(options: RelayHostOptions);
128
+ /** @internal Whether a share of content had too many wrong keys of late. */
129
+ blocked(contentId: string, now?: number): boolean;
130
+ /** @internal */
131
+ wrongKey(contentId: string, now?: number): void;
132
+ /** Whether the connection to every relay it should be at is open; false when it is at none. */
133
+ get online(): boolean;
134
+ /** Whether the connection to this relay is open. */
135
+ onlineAt(relay: string): boolean;
136
+ /** The paired devices connected now, each connection once: those holding a link are not counted. */
137
+ get devicesOpen(): number;
138
+ /** Connects to the relays relay.json needs, and keeps connected; checks again on {@link refresh}. */
139
+ start(): void;
140
+ /** relay.json may have changed: connect to a relay that now has devices or links, leave one that has none. */
141
+ refresh(): void;
142
+ stop(): void;
143
+ }
109
144
  export {};