@celljs/ta-relay 4.16.0 → 4.18.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 (106) hide show
  1. package/esm/common/index.d.ts +2 -0
  2. package/esm/common/index.js +2 -0
  3. package/esm/common/relay-content.d.ts +13 -0
  4. package/esm/common/relay-content.js +42 -0
  5. package/esm/common/relay-conversation.d.ts +14 -0
  6. package/esm/common/relay-faces.d.ts +1 -1
  7. package/esm/common/relay-faces.js +56 -1
  8. package/esm/common/relay-files.d.ts +14 -3
  9. package/esm/common/relay-files.js +41 -16
  10. package/esm/common/relay-friend-sends.d.ts +64 -0
  11. package/esm/common/relay-friend-sends.js +126 -0
  12. package/esm/common/relay-group-invites.d.ts +76 -0
  13. package/esm/common/relay-group-invites.js +163 -0
  14. package/esm/common/relay-hub.js +2 -2
  15. package/esm/common/relay-hubs-identity.d.ts +36 -0
  16. package/esm/common/relay-hubs-identity.js +156 -0
  17. package/esm/common/relay-hubs-protocol.d.ts +7 -1
  18. package/esm/common/relay-hubs-util.d.ts +11 -0
  19. package/esm/common/relay-hubs-util.js +74 -0
  20. package/esm/common/relay-hubs.d.ts +36 -44
  21. package/esm/common/relay-hubs.js +95 -235
  22. package/esm/common/relay-open-in-ta.d.ts +11 -0
  23. package/esm/common/relay-open-in-ta.js +34 -0
  24. package/esm/common/relay-protocol.d.ts +11 -2
  25. package/esm/common/relay-protocol.js +18 -2
  26. package/esm/common/relay-spot.d.ts +15 -3
  27. package/esm/common/relay-spot.js +17 -5
  28. package/esm/guest/guest-i18n.d.ts +1 -0
  29. package/esm/guest/guest-i18n.js +45 -41
  30. package/esm/guest/guest-style.d.ts +1 -1
  31. package/esm/guest/guest-style.js +2 -0
  32. package/esm/guest/guest.js +7 -2
  33. package/esm/join/join-i18n.d.ts +1 -0
  34. package/esm/join/join-i18n.js +4 -0
  35. package/esm/join/join.js +4 -1
  36. package/esm/node/index.d.ts +1 -0
  37. package/esm/node/index.js +1 -0
  38. package/esm/node/relay-files-host.d.ts +2 -0
  39. package/esm/node/relay-files-host.js +24 -5
  40. package/esm/node/relay-memory-storage.d.ts +26 -0
  41. package/esm/node/relay-memory-storage.js +60 -0
  42. package/esm/node/relay-server.d.ts +14 -26
  43. package/esm/node/relay-server.js +33 -60
  44. package/esm/node/relay-store.js +4 -4
  45. package/esm/node/relays-file.d.ts +27 -0
  46. package/esm/node/relays-file.js +59 -4
  47. package/esm/viewer/viewer-i18n.d.ts +1 -0
  48. package/esm/viewer/viewer-i18n.js +4 -0
  49. package/esm/viewer/viewer-style.d.ts +1 -1
  50. package/esm/viewer/viewer-style.js +2 -0
  51. package/esm/viewer/viewer.js +36 -2
  52. package/lib/common/index.d.ts +2 -0
  53. package/lib/common/index.js +2 -0
  54. package/lib/common/relay-content.d.ts +13 -0
  55. package/lib/common/relay-content.js +43 -1
  56. package/lib/common/relay-conversation.d.ts +14 -0
  57. package/lib/common/relay-faces.d.ts +1 -1
  58. package/lib/common/relay-faces.js +56 -1
  59. package/lib/common/relay-files.d.ts +14 -3
  60. package/lib/common/relay-files.js +42 -17
  61. package/lib/common/relay-friend-sends.d.ts +65 -0
  62. package/lib/common/relay-friend-sends.js +130 -0
  63. package/lib/common/relay-group-invites.d.ts +77 -0
  64. package/lib/common/relay-group-invites.js +167 -0
  65. package/lib/common/relay-hub.js +1 -1
  66. package/lib/common/relay-hubs-identity.d.ts +37 -0
  67. package/lib/common/relay-hubs-identity.js +160 -0
  68. package/lib/common/relay-hubs-protocol.d.ts +7 -1
  69. package/lib/common/relay-hubs-util.d.ts +12 -0
  70. package/lib/common/relay-hubs-util.js +77 -0
  71. package/lib/common/relay-hubs.d.ts +36 -44
  72. package/lib/common/relay-hubs.js +94 -234
  73. package/lib/common/relay-open-in-ta.d.ts +12 -0
  74. package/lib/common/relay-open-in-ta.js +37 -0
  75. package/lib/common/relay-protocol.d.ts +11 -2
  76. package/lib/common/relay-protocol.js +20 -3
  77. package/lib/common/relay-spot.d.ts +15 -3
  78. package/lib/common/relay-spot.js +17 -5
  79. package/lib/guest/guest-i18n.d.ts +1 -0
  80. package/lib/guest/guest-i18n.js +45 -41
  81. package/lib/guest/guest-style.d.ts +1 -1
  82. package/lib/guest/guest-style.js +2 -0
  83. package/lib/guest/guest.js +7 -2
  84. package/lib/join/join-i18n.d.ts +1 -0
  85. package/lib/join/join-i18n.js +4 -0
  86. package/lib/join/join.js +4 -1
  87. package/lib/node/index.d.ts +1 -0
  88. package/lib/node/index.js +1 -0
  89. package/lib/node/relay-files-host.d.ts +2 -0
  90. package/lib/node/relay-files-host.js +23 -4
  91. package/lib/node/relay-memory-storage.d.ts +27 -0
  92. package/lib/node/relay-memory-storage.js +65 -0
  93. package/lib/node/relay-server.d.ts +14 -26
  94. package/lib/node/relay-server.js +34 -61
  95. package/lib/node/relay-store.js +3 -3
  96. package/lib/node/relays-file.d.ts +27 -0
  97. package/lib/node/relays-file.js +58 -3
  98. package/lib/viewer/viewer-i18n.d.ts +1 -0
  99. package/lib/viewer/viewer-i18n.js +4 -0
  100. package/lib/viewer/viewer-style.d.ts +1 -1
  101. package/lib/viewer/viewer-style.js +2 -0
  102. package/lib/viewer/viewer.js +35 -1
  103. package/package.json +3 -2
  104. package/viewer/join.html +12 -3
  105. package/viewer/page.html +18 -9
  106. package/viewer/room.html +21 -10
@@ -1,3 +1,4 @@
1
+ import { RelayBytes } from './relay-bytes.js';
1
2
  import { RELAY_PING, RELAY_PONG } from './relay-protocol.js';
2
3
  /**
3
4
  * A spot (docs/design/ta-nearby.md 2.2): the Ta that typed the same code of six digits, on networks that keep them
@@ -25,6 +26,8 @@ export var RelaySpotCloseCode;
25
26
  RelaySpotCloseCode[RelaySpotCloseCode["FULL"] = 4429] = "FULL";
26
27
  /** This address tried too many codes nobody opened: it waits (RelaySpotTries). */
27
28
  RelaySpotCloseCode[RelaySpotCloseCode["TRIES"] = 4428] = "TRIES";
29
+ /** Opened already, by one whose key this one does not hold: a new code is needed. Counted as a failure. */
30
+ RelaySpotCloseCode[RelaySpotCloseCode["TAKEN"] = 4409] = "TAKEN";
28
31
  })(RelaySpotCloseCode || (RelaySpotCloseCode = {}));
29
32
  /**
30
33
  * The codes nobody opened that one address tried lately (docs/design/ta-nearby.md 2.2): six digits are a million
@@ -123,7 +126,7 @@ export class RelaySpot {
123
126
  }
124
127
  }
125
128
  enter(socket, message) {
126
- var _a;
129
+ var _a, _b, _c, _d;
127
130
  if (message.t !== 'open' && message.t !== 'join') {
128
131
  socket.close(RelaySpotCloseCode.BAD, 'Open or join first.');
129
132
  return;
@@ -131,19 +134,27 @@ export class RelaySpot {
131
134
  const others = this.others(socket);
132
135
  const now = this.now();
133
136
  const opened = others.length ? Math.min(...others.map(other => { var _a; var _b; return (_b = (_a = other.who) === null || _a === void 0 ? void 0 : _a.opened) !== null && _b !== void 0 ? _b : now; })) : now;
137
+ const key = (_b = (_a = others.find(other => { var _a; return (_a = other.who) === null || _a === void 0 ? void 0 : _a.k; })) === null || _a === void 0 ? void 0 : _a.who) === null || _b === void 0 ? void 0 : _b.k;
138
+ const back = message.t === 'open' && !!key && !!message.k && message.k === key;
134
139
  if (!others.length && message.t === 'join') {
135
- (_a = this.missed) === null || _a === void 0 ? void 0 : _a.call(this, socket);
140
+ (_c = this.missed) === null || _c === void 0 ? void 0 : _c.call(this, socket);
136
141
  socket.close(RelaySpotCloseCode.NONE, 'No such spot.');
137
142
  }
138
- else if (now - opened > RELAY_SPOT_JOIN_MS) {
143
+ else if (others.length && message.t === 'open' && !back) {
144
+ (_d = this.missed) === null || _d === void 0 ? void 0 : _d.call(this, socket);
145
+ socket.close(RelaySpotCloseCode.TAKEN, 'Opened already.');
146
+ }
147
+ else if (!back && now - opened > RELAY_SPOT_JOIN_MS) {
139
148
  socket.close(RelaySpotCloseCode.LATE, 'Too late to come in.');
140
149
  }
141
150
  else if (others.length >= RELAY_SPOT_MAX) {
142
151
  socket.close(RelaySpotCloseCode.FULL, 'Full.');
143
152
  }
144
153
  else {
145
- socket.who = { opened };
146
- socket.send(JSON.stringify({ t: 'ready', opened }));
154
+ const k = key !== null && key !== void 0 ? key : RelayBytes.toBase64(RelayBytes.random(18));
155
+ socket.who = { opened, k };
156
+ const mine = message.t === 'open';
157
+ socket.send(JSON.stringify({ t: 'ready', opened, ...(mine ? { k } : {}) }));
147
158
  }
148
159
  }
149
160
  /** The others in the spot. */
@@ -156,6 +167,7 @@ export class RelaySpot {
156
167
  const id = (value) => typeof value === 'string' && value.length > 0 && value.length <= 64;
157
168
  switch (data.t) {
158
169
  case 'open':
170
+ return id(data.k) ? { t: 'open', k: data.k } : { t: 'open' };
159
171
  case 'join':
160
172
  case 'bye':
161
173
  return { t: data.t };
@@ -1,5 +1,6 @@
1
1
  import { type PageLanguage } from '../common/page-language.js';
2
2
  declare const zh: {
3
+ openInTa: string;
3
4
  title: string;
4
5
  invalid: string;
5
6
  inTa: string;
@@ -1,10 +1,11 @@
1
1
  import { pageLanguage } from '../common/page-language.js';
2
2
  const zh = {
3
- title: 'Ta 房间',
4
- invalid: '这不是一个完整的 Ta 房间邀请链接,请检查是否复制完整。',
3
+ openInTa: '在 Ta 中打开',
4
+ title: 'Ta 群聊',
5
+ invalid: '这不是一个完整的 Ta 群聊邀请链接,请检查是否复制完整。',
5
6
  inTa: '这是{by}在 Ta 里的加好友链接,要在 Ta 里打开:用 Ta 扫码,或把链接粘贴到 Ta 的快捷打开。',
6
7
  invited: '{by}邀请你加入',
7
- joinHint: '房主同意后,就能在这里和大家聊天。',
8
+ joinHint: '群主同意后,就能在这里和大家聊天。',
8
9
  name: '你的名字',
9
10
  namePlaceholder: '大家看到的名字',
10
11
  join: '申请加入',
@@ -16,16 +17,16 @@ const zh = {
16
17
  cancel: '取消申请',
17
18
  refused: '{by}没有同意你加入',
18
19
  again: '再申请一次',
19
- removed: '你已被移出这个房间',
20
- closed: '这个房间已被房主解散',
21
- inviteGone: '邀请已失效,请向房主要一个新链接',
22
- own: '这是你自己的房间,请在 Ta 里打开。',
20
+ removed: '你已被移出这个群聊',
21
+ closed: '这个群聊已被群主解散',
22
+ inviteGone: '邀请已失效,请向群主要一个新链接',
23
+ own: '这是你自己的群聊,请在 Ta 里打开。',
23
24
  connecting: '连接中…',
24
25
  online: '另有 {n} 人在线',
25
26
  nobody: '其他人都不在线',
26
27
  onlineNow: '在线',
27
28
  members: '成员',
28
- owner: '房主',
29
+ owner: '群主',
29
30
  you: '我',
30
31
  guest: '网页访客',
31
32
  doubleOf: '{name}的分身',
@@ -33,10 +34,10 @@ const zh = {
33
34
  task: '任务',
34
35
  agentOf: '{name}的智能体',
35
36
  rename: '修改我的名字',
36
- leave: '退出房间',
37
+ leave: '退出群聊',
37
38
  leaveAsk: '退出「{title}」?退出后要有新的邀请才能再进来。',
38
- game: '这个房间里有 Ta 的游戏,装了 Ta 才能一起玩;在这里可以聊天。',
39
- empty: '还没有人说话。只有房间里的人能看到,中继保存的是密文。',
39
+ game: '这个群里有 Ta 的游戏,装了 Ta 才能一起玩;在这里可以聊天。',
40
+ empty: '还没有人说话。只有群里的人能看到,中继保存的是密文。',
40
41
  placeholder: '发消息',
41
42
  send: '发送',
42
43
  failed: '没发出去:{reason}',
@@ -44,11 +45,12 @@ const zh = {
44
45
  close: '关闭',
45
46
  };
46
47
  const zhTw = {
47
- title: 'Ta 房間',
48
- invalid: '這不是一個完整的 Ta 房間邀請連結,請檢查是否複製完整。',
48
+ openInTa: '在 Ta 中開啟',
49
+ title: 'Ta 群聊',
50
+ invalid: '這不是一個完整的 Ta 群聊邀請連結,請檢查是否複製完整。',
49
51
  inTa: '這是{by}在 Ta 裡的加好友連結,要在 Ta 裡開啟:用 Ta 掃碼,或把連結貼上到 Ta 的快捷開啟。',
50
52
  invited: '{by}邀請你加入',
51
- joinHint: '房主同意後,就能在這裡和大家聊天。',
53
+ joinHint: '群主同意後,就能在這裡和大家聊天。',
52
54
  name: '你的名字',
53
55
  namePlaceholder: '大家看到的名字',
54
56
  join: '申請加入',
@@ -60,16 +62,16 @@ const zhTw = {
60
62
  cancel: '取消申請',
61
63
  refused: '{by}沒有同意你加入',
62
64
  again: '再申請一次',
63
- removed: '你已被移出這個房間',
64
- closed: '這個房間已被房主解散',
65
- inviteGone: '邀請已失效,請向房主要一個新連結',
66
- own: '這是你自己的房間,請在 Ta 裡開啟。',
65
+ removed: '你已被移出這個群聊',
66
+ closed: '這個群聊已被群主解散',
67
+ inviteGone: '邀請已失效,請向群主要一個新連結',
68
+ own: '這是你自己的群聊,請在 Ta 裡開啟。',
67
69
  connecting: '連線中…',
68
70
  online: '另有 {n} 人線上',
69
71
  nobody: '其他人都不線上',
70
72
  onlineNow: '線上',
71
73
  members: '成員',
72
- owner: '房主',
74
+ owner: '群主',
73
75
  you: '我',
74
76
  guest: '網頁訪客',
75
77
  doubleOf: '{name}的分身',
@@ -77,10 +79,10 @@ const zhTw = {
77
79
  task: '任務',
78
80
  agentOf: '{name}的智慧體',
79
81
  rename: '修改我的名字',
80
- leave: '退出房間',
82
+ leave: '退出群聊',
81
83
  leaveAsk: '退出「{title}」?退出後要有新的邀請才能再進來。',
82
- game: '這個房間裡有 Ta 的遊戲,裝了 Ta 才能一起玩;在這裡可以聊天。',
83
- empty: '還沒有人說話。只有房間裡的人能看到,中繼儲存的是密文。',
84
+ game: '這個群裡有 Ta 的遊戲,裝了 Ta 才能一起玩;在這裡可以聊天。',
85
+ empty: '還沒有人說話。只有群裡的人能看到,中繼儲存的是密文。',
84
86
  placeholder: '發訊息',
85
87
  send: '傳送',
86
88
  failed: '沒發出去:{reason}',
@@ -88,8 +90,9 @@ const zhTw = {
88
90
  close: '關閉',
89
91
  };
90
92
  const en = {
91
- title: 'A room of Ta',
92
- invalid: 'This is not a whole link that invites into a room of Ta: check it was copied in full.',
93
+ openInTa: 'Open in Ta',
94
+ title: 'A group chat of Ta',
95
+ invalid: 'This is not a whole link that invites into a group chat of Ta: check it was copied in full.',
93
96
  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.',
94
97
  invited: '{by} invites you to join',
95
98
  joinHint: 'Once the owner lets you in, you chat with everyone here.',
@@ -104,10 +107,10 @@ const en = {
104
107
  cancel: 'Cancel',
105
108
  refused: '{by} did not let you in',
106
109
  again: 'Ask again',
107
- removed: 'You were taken out of this room',
108
- closed: 'This room was closed by its owner',
110
+ removed: 'You were taken out of this group chat',
111
+ closed: 'This group chat was closed by its owner',
109
112
  inviteGone: 'The invitation no longer works: ask the owner for a new link',
110
- own: 'This is a room of your own: open it in Ta.',
113
+ own: 'This is a group chat of your own: open it in Ta.',
111
114
  connecting: 'Connecting…',
112
115
  online: '{n} more online',
113
116
  nobody: 'Nobody else online',
@@ -121,10 +124,10 @@ const en = {
121
124
  task: 'Task',
122
125
  agentOf: "{name}'s agent",
123
126
  rename: 'Change my name',
124
- leave: 'Leave the room',
127
+ leave: 'Leave the group chat',
125
128
  leaveAsk: 'Leave “{title}”? You come back only by a new invitation.',
126
- game: 'This room plays a game of Ta, which takes Ta to play; here you chat.',
127
- empty: 'Nothing said yet. Only those in the room read it: the relay keeps it sealed.',
129
+ game: 'This group chat plays a game of Ta, which takes Ta to play; here you chat.',
130
+ empty: 'Nothing said yet. Only those in the group chat read it: the relay keeps it sealed.',
128
131
  placeholder: 'Message',
129
132
  send: 'Send',
130
133
  failed: 'Not sent: {reason}',
@@ -132,11 +135,12 @@ const en = {
132
135
  close: 'Close',
133
136
  };
134
137
  const ja = {
135
- title: 'Ta のルーム',
136
- invalid: 'これは Ta ルームへの完全な招待リンクではありません。全体がコピーされているか確認してください。',
138
+ openInTa: 'Ta で開く',
139
+ title: 'Ta のグループチャット',
140
+ invalid: 'これは Ta グループチャットへの完全な招待リンクではありません。全体がコピーされているか確認してください。',
137
141
  inTa: 'これは {by} さんが Ta で友だちを追加するリンクで、Ta で開きます。Ta でスキャンするか、Ta のクイックオープンにペーストしてください。',
138
142
  invited: '{by}さんがあなたを招待しています',
139
- joinHint: 'ルーム管理者が承認すると、ここでみんなとチャットできます。',
143
+ joinHint: 'グループチャット管理者が承認すると、ここでみんなとチャットできます。',
140
144
  name: 'あなたの名前',
141
145
  namePlaceholder: 'みんなに見える名前',
142
146
  join: '参加をリクエスト',
@@ -148,16 +152,16 @@ const ja = {
148
152
  cancel: 'キャンセル',
149
153
  refused: '{by}さんはあなたの参加を承認しませんでした',
150
154
  again: 'もう一度リクエスト',
151
- removed: 'このルームから削除されました',
152
- closed: 'このルームはルーム管理者に閉じられました',
153
- inviteGone: '招待が無効です。ルーム管理者に新しいリンクをリクエストしてください',
154
- own: 'これはあなた自身のルームです。Ta で開いてください。',
155
+ removed: 'このグループチャットから削除されました',
156
+ closed: 'このグループチャットはグループチャット管理者に閉じられました',
157
+ inviteGone: '招待が無効です。グループチャット管理者に新しいリンクをリクエストしてください',
158
+ own: 'これはあなた自身のグループチャットです。Ta で開いてください。',
155
159
  connecting: '接続中…',
156
160
  online: '他に {n} 人がオンライン',
157
161
  nobody: '他に誰もオンラインではありません',
158
162
  onlineNow: 'オンライン',
159
163
  members: 'メンバー',
160
- owner: 'ルーム管理者',
164
+ owner: 'グループチャット管理者',
161
165
  you: '私',
162
166
  guest: 'ウェブゲスト',
163
167
  doubleOf: '{name}の分身',
@@ -165,10 +169,10 @@ const ja = {
165
169
  task: 'タスク',
166
170
  agentOf: '{name}のエージェント',
167
171
  rename: '名前を変更',
168
- leave: 'ルームを退出',
172
+ leave: 'グループチャットを退出',
169
173
  leaveAsk: '「{title}」を退出しますか?退出後は新しい招待でのみ戻ることができます。',
170
- game: 'このルームには Ta のゲームがあり、プレイするには Ta が必要です。ここでチャットできます。',
171
- empty: 'まだ誰も話していません。ルーム内の人だけが見ることができ、リレーは暗号化されて保存されます。',
174
+ game: 'このグループチャットには Ta のゲームがあり、プレイするには Ta が必要です。ここでチャットできます。',
175
+ empty: 'まだ誰も話していません。グループ内の人だけが見ることができ、リレーは暗号化されて保存されます。',
172
176
  placeholder: 'メッセージ',
173
177
  send: '送信',
174
178
  failed: '送信されませんでした:{reason}',
@@ -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-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";
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.open-in-ta{flex:none;display:inline-flex;align-items:center;height:32px;padding:0 14px;border-radius:16px;background:var(--fg);color:var(--bg);font-size:13.5px;font-weight:600;text-decoration:none;white-space:nowrap;-webkit-tap-highlight-color:transparent}\n.open-in-ta:active{opacity:.8}\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";
@@ -6,6 +6,8 @@ html,body{margin:0;height:100%;background:var(--bg);color:var(--fg);font:15px/1.
6
6
  button{font:inherit;color:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent}
7
7
  .app{display:flex;flex-direction:column;height:100dvh;max-width:760px;margin:0 auto}
8
8
  .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)}
9
+ .open-in-ta{flex:none;display:inline-flex;align-items:center;height:32px;padding:0 14px;border-radius:16px;background:var(--fg);color:var(--bg);font-size:13.5px;font-weight:600;text-decoration:none;white-space:nowrap;-webkit-tap-highlight-color:transparent}
10
+ .open-in-ta:active{opacity:.8}
9
11
  .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}
10
12
  .heading{flex:1;min-width:0;display:flex;flex-direction:column}
11
13
  .heading b{font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
@@ -1,6 +1,7 @@
1
1
  import { FaceUtil } from '../common/relay-faces.js';
2
2
  import { RelayHubUtil } from '../common/relay-hub-util.js';
3
3
  import { RelayHubs } from '../common/relay-hubs.js';
4
+ import { RelayOpenInTa } from '../common/relay-open-in-ta.js';
4
5
  import { RelayRoomChat } from '../common/relay-room-chat.js';
5
6
  import { ViewerMarkdown } from '../viewer/viewer-markdown.js';
6
7
  import { GuestI18n } from './guest-i18n.js';
@@ -36,6 +37,10 @@ class BrowserStore {
36
37
  }
37
38
  }
38
39
  }
40
+ /** Open in Ta: the link of this page, handed to the Ta app by the system (`ta://open?link=`). */
41
+ function openInTa() {
42
+ return Object.assign(el('a', t('openInTa')), { className: 'open-in-ta', href: RelayOpenInTa.link(location.href) });
43
+ }
39
44
  function div(className, ...children) {
40
45
  const node = el('div');
41
46
  node.className = className;
@@ -142,7 +147,7 @@ class GuestPage {
142
147
  const logo = el('span', 'Ta');
143
148
  logo.className = 'logo';
144
149
  const heading = div('heading', Object.assign(el('b'), { textContent: t('title') }));
145
- return div('top', logo, heading);
150
+ return div('top', logo, heading, openInTa());
146
151
  }
147
152
  join(error) {
148
153
  document.title = t('title');
@@ -382,7 +387,7 @@ function main() {
382
387
  if (link.kind) {
383
388
  // A room a package keeps for itself (friends of Moments): only a Ta joins it.
384
389
  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' }))));
390
+ document.body.replaceChildren(div('app', div('top', logo, openInTa()), div('center', Object.assign(el('p', t('inTa', { by: link.by })), { className: 'hint' }))));
386
391
  return;
387
392
  }
388
393
  new GuestPage(link).start();
@@ -1,5 +1,6 @@
1
1
  import { type PageLanguage } from '../common/page-language.js';
2
2
  declare const zh: {
3
+ openInTa: string;
3
4
  title: string;
4
5
  invalid: string;
5
6
  invited: string;
@@ -1,5 +1,6 @@
1
1
  import { linkLanguage } from '../common/page-language.js';
2
2
  const zh = {
3
+ openInTa: '在 Ta 中打开',
3
4
  title: '加入 Ta',
4
5
  invalid: '这不是一个完整的 Ta 邀请链接,请检查是否复制完整。',
5
6
  invited: '{owner}邀请你一起用 Ta',
@@ -47,6 +48,7 @@ const zh = {
47
48
  'role.guest': '访客',
48
49
  };
49
50
  const zhTw = {
51
+ openInTa: '在 Ta 中開啟',
50
52
  title: '加入 Ta',
51
53
  invalid: '這不是一個完整的 Ta 邀請連結,請檢查是否複製完整。',
52
54
  invited: '{owner}邀請你一起用 Ta',
@@ -94,6 +96,7 @@ const zhTw = {
94
96
  'role.guest': '訪客',
95
97
  };
96
98
  const en = {
99
+ openInTa: 'Open in Ta',
97
100
  title: 'Join a Ta',
98
101
  invalid: 'This is not a whole link that invites into a Ta: check that it was copied in full.',
99
102
  invited: '{owner} invites you to work in their Ta',
@@ -141,6 +144,7 @@ const en = {
141
144
  'role.guest': 'Guest',
142
145
  };
143
146
  const ja = {
147
+ openInTa: 'Ta で開く',
144
148
  title: 'Ta に参加',
145
149
  invalid: 'これは Ta への完全な招待リンクではありません。全体がコピーされているか確認してください。',
146
150
  invited: '{owner}さんが Ta での作業にあなたを招待しています',
package/esm/join/join.js CHANGED
@@ -1,4 +1,5 @@
1
1
  var _a;
2
+ import { RelayOpenInTa } from '../common/relay-open-in-ta.js';
2
3
  import { RELAY_WEB_PATH, RelayTeamJoining, RelayTeamLinkUtil, } from '../common/relay-team.js';
3
4
  import { GUEST_STYLE } from '../guest/guest-style.js';
4
5
  import { JoinI18n } from './join-i18n.js';
@@ -224,7 +225,9 @@ class JoinPage {
224
225
  const heading = el('div', 'heading');
225
226
  heading.append(el('b', undefined, t('title')));
226
227
  const top = el('div', 'top');
227
- top.append(logo, heading);
228
+ const open = el('a', 'open-in-ta', t('openInTa'));
229
+ open.href = RelayOpenInTa.link(location.href);
230
+ top.append(logo, heading, open);
228
231
  const center = el('div', 'center');
229
232
  center.append(...children);
230
233
  const app = el('div', 'app');
@@ -3,6 +3,7 @@ export * from './relay-file-storage.js';
3
3
  export * from './relay-files-host.js';
4
4
  export * from './relay-host.js';
5
5
  export * from './relay-hub-files.js';
6
+ export * from './relay-memory-storage.js';
6
7
  export * from './relay-server.js';
7
8
  export * from './relay-store.js';
8
9
  export * from './relay-viewer.js';
package/esm/node/index.js CHANGED
@@ -3,6 +3,7 @@ export * from './relay-file-storage.js';
3
3
  export * from './relay-files-host.js';
4
4
  export * from './relay-host.js';
5
5
  export * from './relay-hub-files.js';
6
+ export * from './relay-memory-storage.js';
6
7
  export * from './relay-server.js';
7
8
  export * from './relay-store.js';
8
9
  export * from './relay-viewer.js';
@@ -16,6 +16,8 @@ export declare class RelayFilesHost {
16
16
  protected readonly base: string;
17
17
  protected reading: number;
18
18
  protected readonly running: Set<AbortController>;
19
+ /** Asked for past {@link RELAY_FILES_MAX_PARALLEL}: read in turn, not turned away (a page of an older Ta asks for all at once). */
20
+ protected readonly waiting: ((go: boolean) => void)[];
19
21
  constructor(options: RelayFilesHostOptions);
20
22
  /** A frame of the device: a file to read, or something of a version it does not know. */
21
23
  receive(text: string): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import { RelayBytes } from '../common/relay-bytes.js';
2
- import { RELAY_FILE_CHUNK_BYTES, RELAY_FILE_MAX_BYTES, RELAY_FILES_MAX_PARALLEL, RELAY_FILES_PREFIX, RELAY_FILES_TIMEOUT_MS, } from '../common/relay-files.js';
2
+ import { RELAY_FILE_CHUNK_BYTES, RELAY_FILE_MAX_BYTES, RELAY_FILES_MAX_PARALLEL, RELAY_FILES_MAX_WAITING, RELAY_FILES_PREFIX, RELAY_FILES_TIMEOUT_MS, } from '../common/relay-files.js';
3
3
  /**
4
4
  * The files of the workspace on a channel of a device (RelayFiles): asks them of the ta serve of this
5
5
  * machine and sends them back sealed. It asks for nothing but a path of {@link RELAY_FILES_PREFIX}, with
@@ -11,6 +11,8 @@ export class RelayFilesHost {
11
11
  this.options = options;
12
12
  this.reading = 0;
13
13
  this.running = new Set();
14
+ /** Asked for past {@link RELAY_FILES_MAX_PARALLEL}: read in turn, not turned away (a page of an older Ta asks for all at once). */
15
+ this.waiting = [];
14
16
  // Only ever loopback, whatever the address of the socket says: what this reaches is one server.
15
17
  this.base = `http://127.0.0.1:${new URL(options.localUrl).port}`;
16
18
  }
@@ -30,6 +32,9 @@ export class RelayFilesHost {
30
32
  }
31
33
  /** The device went: what it asked for is not read to the end. */
32
34
  close() {
35
+ for (const go of this.waiting.splice(0)) {
36
+ go(false);
37
+ }
33
38
  for (const controller of this.running) {
34
39
  controller.abort();
35
40
  }
@@ -58,12 +63,20 @@ export class RelayFilesHost {
58
63
  return;
59
64
  }
60
65
  if (this.reading >= RELAY_FILES_MAX_PARALLEL) {
61
- this.options.send({ t: 'error', id, message: 'Too many files are loading at once.' });
62
- return;
66
+ if (this.waiting.length >= RELAY_FILES_MAX_WAITING) {
67
+ this.options.send({ t: 'error', id, message: 'Too many files are loading at once.' });
68
+ return;
69
+ }
70
+ // A read that ends hands its place to this one: no more than the most are read at once.
71
+ if (!(await new Promise(go => this.waiting.push(go)))) {
72
+ return;
73
+ }
74
+ }
75
+ else {
76
+ this.reading++;
63
77
  }
64
78
  const controller = new AbortController();
65
79
  this.running.add(controller);
66
- this.reading++;
67
80
  const timer = setTimeout(() => controller.abort(), RELAY_FILES_TIMEOUT_MS);
68
81
  try {
69
82
  const response = await fetch(target, { signal: controller.signal, redirect: 'error', headers: { accept: '*/*' } });
@@ -123,7 +136,13 @@ export class RelayFilesHost {
123
136
  finally {
124
137
  clearTimeout(timer);
125
138
  this.running.delete(controller);
126
- this.reading--;
139
+ const next = this.waiting.shift();
140
+ if (next) {
141
+ next(true);
142
+ }
143
+ else {
144
+ this.reading--;
145
+ }
127
146
  }
128
147
  }
129
148
  }
@@ -0,0 +1,26 @@
1
+ import type { RelayBlobStorage } from '../common/relay-blobs.js';
2
+ import type { RelayHubStorage } from '../common/relay-hub.js';
3
+ /** A copy of content in memory, deleted when it runs out. */
4
+ export declare class MemoryBlobStorage implements RelayBlobStorage {
5
+ protected readonly values: Map<string, unknown>;
6
+ protected timer?: ReturnType<typeof setTimeout>;
7
+ get<T>(key: string): Promise<T | undefined>;
8
+ put(key: string, value: unknown): Promise<void>;
9
+ deleteAll(): Promise<void>;
10
+ /** No copy is kept: nothing of it need stay in the relay's memory. */
11
+ get empty(): boolean;
12
+ setAlarm(at: number): Promise<void>;
13
+ }
14
+ /** A room in memory, as a Durable Object keeps it. */
15
+ export declare class MemoryHubStorage implements RelayHubStorage {
16
+ protected readonly values: Map<string, unknown>;
17
+ get<T>(key: string): Promise<T | undefined>;
18
+ put(key: string, value: unknown): Promise<void>;
19
+ delete(key: string): Promise<boolean>;
20
+ list<T>(options: {
21
+ prefix: string;
22
+ }): Promise<Map<string, T>>;
23
+ deleteAll(): Promise<void>;
24
+ /** No room was made, or it was closed. */
25
+ get empty(): boolean;
26
+ }
@@ -0,0 +1,60 @@
1
+ /** A copy of content in memory, deleted when it runs out. */
2
+ export class MemoryBlobStorage {
3
+ constructor() {
4
+ this.values = new Map();
5
+ }
6
+ async get(key) {
7
+ return this.values.get(key);
8
+ }
9
+ async put(key, value) {
10
+ this.values.set(key, value);
11
+ }
12
+ async deleteAll() {
13
+ this.values.clear();
14
+ clearTimeout(this.timer);
15
+ }
16
+ /** No copy is kept: nothing of it need stay in the relay's memory. */
17
+ get empty() {
18
+ return this.values.size === 0;
19
+ }
20
+ async setAlarm(at) {
21
+ var _a, _b;
22
+ clearTimeout(this.timer);
23
+ // Past the 24 days of a timer, it is found run out on the next read.
24
+ this.timer = setTimeout(() => this.values.clear(), Math.min(Math.max(at - Date.now(), 0), 2 ** 31 - 1));
25
+ (_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
26
+ }
27
+ }
28
+ /** A room in memory, as a Durable Object keeps it. */
29
+ export class MemoryHubStorage {
30
+ constructor() {
31
+ this.values = new Map();
32
+ }
33
+ async get(key) {
34
+ const value = this.values.get(key);
35
+ return value === undefined ? undefined : structuredClone(value);
36
+ }
37
+ async put(key, value) {
38
+ this.values.set(key, structuredClone(value));
39
+ }
40
+ async delete(key) {
41
+ return this.values.delete(key);
42
+ }
43
+ async list(options) {
44
+ const found = new Map();
45
+ for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
46
+ if (key.startsWith(options.prefix)) {
47
+ found.set(key, structuredClone(value));
48
+ }
49
+ }
50
+ return found;
51
+ }
52
+ async deleteAll() {
53
+ this.values.clear();
54
+ }
55
+ /** No room was made, or it was closed. */
56
+ get empty() {
57
+ return this.values.size === 0;
58
+ }
59
+ }
60
+ //# sourceMappingURL=relay-memory-storage.js.map