@celljs/ta-relay 4.13.1 → 4.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +9 -1
- package/README.md +9 -1
- package/esm/common/index.d.ts +3 -0
- package/esm/common/index.js +3 -0
- package/esm/common/page-language.d.ts +14 -0
- package/esm/common/page-language.js +27 -0
- package/esm/common/relay-friends.js +29 -4
- package/esm/common/relay-host-calls.d.ts +34 -0
- package/esm/common/relay-host-calls.js +126 -0
- package/esm/common/relay-hubs-connection.d.ts +9 -1
- package/esm/common/relay-hubs-connection.js +33 -1
- package/esm/common/relay-hubs-protocol.d.ts +9 -1
- package/esm/common/relay-hubs.d.ts +7 -0
- package/esm/common/relay-hubs.js +20 -3
- package/esm/common/relay-identity.d.ts +11 -0
- package/esm/common/relay-identity.js +12 -1
- package/esm/common/relay-protocol.d.ts +1 -1
- package/esm/common/relay-protocol.js +2 -1
- package/esm/common/relay-team.d.ts +169 -0
- package/esm/common/relay-team.js +248 -0
- package/esm/common/relay-web.d.ts +13 -0
- package/esm/common/relay-web.js +61 -0
- package/esm/guest/guest-i18n.d.ts +6 -1
- package/esm/guest/guest-i18n.js +98 -5
- package/esm/guest/guest.js +1 -1
- package/esm/join/join-i18n.d.ts +65 -0
- package/esm/join/join-i18n.js +233 -0
- package/esm/join/join.d.ts +1 -0
- package/esm/join/join.js +433 -0
- package/esm/node/relay-server.d.ts +7 -0
- package/esm/node/relay-server.js +28 -3
- package/esm/node/relay-viewer.d.ts +2 -0
- package/esm/node/relay-viewer.js +9 -4
- package/esm/viewer/viewer-i18n.d.ts +6 -1
- package/esm/viewer/viewer-i18n.js +107 -3
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.js +3 -0
- package/lib/common/page-language.d.ts +15 -0
- package/lib/common/page-language.js +31 -0
- package/lib/common/relay-friends.js +29 -4
- package/lib/common/relay-host-calls.d.ts +35 -0
- package/lib/common/relay-host-calls.js +130 -0
- package/lib/common/relay-hubs-connection.d.ts +9 -1
- package/lib/common/relay-hubs-connection.js +33 -1
- package/lib/common/relay-hubs-protocol.d.ts +9 -1
- package/lib/common/relay-hubs.d.ts +7 -0
- package/lib/common/relay-hubs.js +20 -3
- package/lib/common/relay-identity.d.ts +11 -0
- package/lib/common/relay-identity.js +12 -1
- package/lib/common/relay-protocol.d.ts +1 -1
- package/lib/common/relay-protocol.js +2 -1
- package/lib/common/relay-team.d.ts +170 -0
- package/lib/common/relay-team.js +252 -0
- package/lib/common/relay-web.d.ts +14 -0
- package/lib/common/relay-web.js +64 -0
- package/lib/guest/guest-i18n.d.ts +6 -1
- package/lib/guest/guest-i18n.js +99 -6
- package/lib/guest/guest.js +1 -1
- package/lib/join/join-i18n.d.ts +66 -0
- package/lib/join/join-i18n.js +236 -0
- package/lib/join/join.d.ts +2 -0
- package/lib/join/join.js +435 -0
- package/lib/node/relay-server.d.ts +7 -0
- package/lib/node/relay-server.js +27 -2
- package/lib/node/relay-viewer.d.ts +2 -0
- package/lib/node/relay-viewer.js +6 -1
- package/lib/viewer/viewer-i18n.d.ts +6 -1
- package/lib/viewer/viewer-i18n.js +108 -4
- package/package.json +4 -4
- package/viewer/join.html +93 -0
- package/viewer/page.html +9 -9
- package/viewer/room.html +10 -10
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pageLanguage } from '../common/page-language.js';
|
|
1
2
|
const zh = {
|
|
2
3
|
title: 'Ta 分享',
|
|
3
4
|
loading: '正在打开…',
|
|
@@ -47,6 +48,55 @@ const zh = {
|
|
|
47
48
|
script: '运行脚本',
|
|
48
49
|
use: '使用 {name}',
|
|
49
50
|
};
|
|
51
|
+
const zhTw = {
|
|
52
|
+
title: 'Ta 分享',
|
|
53
|
+
loading: '正在開啟…',
|
|
54
|
+
conversation: '對話',
|
|
55
|
+
file: '檔案',
|
|
56
|
+
sharedAt: '分享於 {date}',
|
|
57
|
+
messages: '{n} 條訊息',
|
|
58
|
+
passwordTitle: '這個分享需要口令',
|
|
59
|
+
passwordHint: '口令不在連結裡,請向分享的人要。',
|
|
60
|
+
password: '口令',
|
|
61
|
+
open: '開啟',
|
|
62
|
+
wrong: '口令不對,再試一次。',
|
|
63
|
+
busy: '口令錯得太多了,請過幾分鐘再試。',
|
|
64
|
+
gone: '這個連結已經失效:分享已停止或已過期。',
|
|
65
|
+
offline: '分享的人的電腦現在沒有執行 Ta,請稍後再試。',
|
|
66
|
+
self: '這是僅自己可見的分享,只有分享的人能在自己的 Ta 裡開啟。',
|
|
67
|
+
people: '這條連結只給指定的 Ta 好友:請在你自己的 Ta 應用裡掃碼或貼上開啟。',
|
|
68
|
+
invalid: '這不是一個完整的 Ta 分享連結,請檢查是否複製完整。',
|
|
69
|
+
timeout: '等了太久還沒收到,請稍後再試。',
|
|
70
|
+
large: '內容太大,打不開。',
|
|
71
|
+
failed: '打不開這個分享。',
|
|
72
|
+
you: '你',
|
|
73
|
+
ta: 'Ta',
|
|
74
|
+
outputsOmitted: '分享時沒有附上工具的輸出。',
|
|
75
|
+
imagesOmitted: '分享時去掉了 {n} 張圖片。',
|
|
76
|
+
redacted: '分享時隱去了 {n} 處疑似金鑰。',
|
|
77
|
+
image: '[圖片]',
|
|
78
|
+
download: '下載 {name}',
|
|
79
|
+
footer: '在 Ta 應用裡掃碼或貼上這個連結,可以把它匯入為你自己的對話接著聊。',
|
|
80
|
+
agentKind: '智慧體名片',
|
|
81
|
+
agentHint: '在 Ta 裡掃碼或貼上這個連結,就能把它加為你的智慧體;加進來時,它會先看看你的專案,把職責調整得貼合你那邊的情況。',
|
|
82
|
+
copy: '複製連結',
|
|
83
|
+
copied: '已複製',
|
|
84
|
+
failedCall: '失敗',
|
|
85
|
+
output: '輸出',
|
|
86
|
+
error: '出錯了',
|
|
87
|
+
secure: '端到端加密:中繼看不到內容',
|
|
88
|
+
run: '執行',
|
|
89
|
+
read: '讀取',
|
|
90
|
+
write: '寫入',
|
|
91
|
+
edit: '編輯',
|
|
92
|
+
search: '搜尋',
|
|
93
|
+
find: '查詢',
|
|
94
|
+
list: '列出',
|
|
95
|
+
fetch: '開啟網頁',
|
|
96
|
+
webSearch: '搜尋網頁',
|
|
97
|
+
script: '執行指令碼',
|
|
98
|
+
use: '使用 {name}',
|
|
99
|
+
};
|
|
50
100
|
const en = {
|
|
51
101
|
title: 'Shared from Ta',
|
|
52
102
|
loading: 'Opening…',
|
|
@@ -96,15 +146,69 @@ const en = {
|
|
|
96
146
|
script: 'Run a script',
|
|
97
147
|
use: 'Use {name}',
|
|
98
148
|
};
|
|
149
|
+
const ja = {
|
|
150
|
+
title: 'Ta から共有',
|
|
151
|
+
loading: '開いています…',
|
|
152
|
+
conversation: '会話',
|
|
153
|
+
file: 'ファイル',
|
|
154
|
+
sharedAt: '{date} に共有',
|
|
155
|
+
messages: '{n} 件のメッセージ',
|
|
156
|
+
passwordTitle: 'この共有にはパスワードが必要です',
|
|
157
|
+
passwordHint: 'パスワードはリンクに含まれていません。共有した人に尋ねてください。',
|
|
158
|
+
password: 'パスワード',
|
|
159
|
+
open: '開く',
|
|
160
|
+
wrong: 'パスワードが違います。もう一度試してください。',
|
|
161
|
+
busy: 'パスワード入力を間違えすぎました。数分後にもう一度試してください。',
|
|
162
|
+
gone: 'このリンクはもう有効ではありません。共有が停止されたか期限切れです。',
|
|
163
|
+
offline: '共有したコンピュータは現在 Ta を実行していません。後で再度試してください。',
|
|
164
|
+
self: 'この共有は共有者だけが自分の Ta で開くことができます。',
|
|
165
|
+
people: 'このリンクは指定された Ta 友だちのみが対象です。自分の Ta アプリでスキャンするかペーストして開いてください。',
|
|
166
|
+
invalid: 'これは Ta の完全なリンクではありません。全体がコピーされているか確認してください。',
|
|
167
|
+
timeout: '到着に時間がかかりすぎました。後で再度試してください。',
|
|
168
|
+
large: 'サイズが大きすぎて開くことができません。',
|
|
169
|
+
failed: 'この共有は開くことができません。',
|
|
170
|
+
you: 'あなた',
|
|
171
|
+
ta: 'Ta',
|
|
172
|
+
outputsOmitted: 'ツールの出力は共有されていません。',
|
|
173
|
+
imagesOmitted: '共有時に {n} 枚の画像が除外されました。',
|
|
174
|
+
redacted: 'シークレットのように見えた {n} 個の項目が削除されました。',
|
|
175
|
+
image: '[画像]',
|
|
176
|
+
download: '{name} をダウンロード',
|
|
177
|
+
footer: 'Ta アプリでこのリンクをスキャンするかペーストして、自分の会話としてインポートして続けることができます。',
|
|
178
|
+
agentKind: 'エージェントのカード',
|
|
179
|
+
agentHint: 'Ta でこのリンクをスキャンするかペーストしてあなたのエージェントとして追加できます。参加すると、まずあなたのプロジェクトを確認して、その状況に合わせて役割を調整します。',
|
|
180
|
+
copy: 'リンクをコピー',
|
|
181
|
+
copied: 'コピーされました',
|
|
182
|
+
failedCall: '失敗',
|
|
183
|
+
output: '出力',
|
|
184
|
+
error: 'エラー',
|
|
185
|
+
secure: 'エンドツーエンド暗号化。リレーは読むことができません',
|
|
186
|
+
run: '実行',
|
|
187
|
+
read: '読取',
|
|
188
|
+
write: '書込',
|
|
189
|
+
edit: '編集',
|
|
190
|
+
search: '検索',
|
|
191
|
+
find: '検索',
|
|
192
|
+
list: 'リスト',
|
|
193
|
+
fetch: '開く',
|
|
194
|
+
webSearch: 'ウェブを検索',
|
|
195
|
+
script: 'スクリプトを実行',
|
|
196
|
+
use: '{name} を使用',
|
|
197
|
+
};
|
|
198
|
+
/** The words of each language of Ta, checked by scripts/check-i18n.ts. */
|
|
199
|
+
export const VIEWER_WORDS = { 'zh-CN': zh, 'zh-TW': zhTw, 'en-US': en, 'ja-JP': ja };
|
|
99
200
|
export var ViewerI18n;
|
|
100
201
|
(function (ViewerI18n) {
|
|
101
|
-
ViewerI18n.
|
|
202
|
+
ViewerI18n.language = pageLanguage();
|
|
203
|
+
/** Chinese or Japanese: Latin among the words has a space on each side. */
|
|
204
|
+
ViewerI18n.cjk = ViewerI18n.language !== 'en-US';
|
|
205
|
+
const words = VIEWER_WORDS[ViewerI18n.language];
|
|
102
206
|
function t(id, values = {}) {
|
|
103
|
-
return
|
|
207
|
+
return words[id].replace(/\{(\w+)\}/g, (_, name) => { var _a; return String((_a = values[name]) !== null && _a !== void 0 ? _a : ''); });
|
|
104
208
|
}
|
|
105
209
|
ViewerI18n.t = t;
|
|
106
210
|
function date(at) {
|
|
107
|
-
return new Date(at).toLocaleString(ViewerI18n.
|
|
211
|
+
return new Date(at).toLocaleString(ViewerI18n.language, {
|
|
108
212
|
year: 'numeric',
|
|
109
213
|
month: 'short',
|
|
110
214
|
day: 'numeric',
|
package/lib/common/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './relay-conversation';
|
|
|
8
8
|
export * from './relay-faces';
|
|
9
9
|
export * from './relay-files';
|
|
10
10
|
export * from './relay-friends';
|
|
11
|
+
export * from './relay-host-calls';
|
|
11
12
|
export * from './relay-hub';
|
|
12
13
|
export * from './relay-hub-util';
|
|
13
14
|
export * from './relay-hubs';
|
|
@@ -21,4 +22,6 @@ export * from './relay-room-chat';
|
|
|
21
22
|
export * from './relay-share';
|
|
22
23
|
export * from './relay-socket';
|
|
23
24
|
export * from './relay-spot';
|
|
25
|
+
export * from './relay-team';
|
|
26
|
+
export * from './relay-web';
|
|
24
27
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/common/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __exportStar(require("./relay-conversation"), exports);
|
|
|
24
24
|
__exportStar(require("./relay-faces"), exports);
|
|
25
25
|
__exportStar(require("./relay-files"), exports);
|
|
26
26
|
__exportStar(require("./relay-friends"), exports);
|
|
27
|
+
__exportStar(require("./relay-host-calls"), exports);
|
|
27
28
|
__exportStar(require("./relay-hub"), exports);
|
|
28
29
|
__exportStar(require("./relay-hub-util"), exports);
|
|
29
30
|
__exportStar(require("./relay-hubs"), exports);
|
|
@@ -37,4 +38,6 @@ __exportStar(require("./relay-room-chat"), exports);
|
|
|
37
38
|
__exportStar(require("./relay-share"), exports);
|
|
38
39
|
__exportStar(require("./relay-socket"), exports);
|
|
39
40
|
__exportStar(require("./relay-spot"), exports);
|
|
41
|
+
__exportStar(require("./relay-team"), exports);
|
|
42
|
+
__exportStar(require("./relay-web"), exports);
|
|
40
43
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** A language of the pages of the relay, the languages of Ta. */
|
|
2
|
+
export type PageLanguage = 'zh-CN' | 'zh-TW' | 'en-US' | 'ja-JP';
|
|
3
|
+
/**
|
|
4
|
+
* The language of a page, from the browser's (`navigator.language`): Traditional Chinese for Taiwan, Hong Kong, Macau
|
|
5
|
+
* and `Hant`, Simplified for other Chinese, Japanese, else English; as TaLanguageUtil.of of ta-protocol, which the
|
|
6
|
+
* relay does without.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pageLanguage(tag?: string | undefined): PageLanguage;
|
|
9
|
+
/**
|
|
10
|
+
* The language of a page a link opens: the first of the browser's languages that is Chinese or Japanese, else the
|
|
11
|
+
* language the link was made in (`linked`, the inviter's), else English. A browser in English alone, as many are
|
|
12
|
+
* whatever their users read, gets the page in the words of who sent the link.
|
|
13
|
+
*/
|
|
14
|
+
export declare function linkLanguage(languages: readonly string[], linked?: string): PageLanguage;
|
|
15
|
+
//# sourceMappingURL=page-language.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pageLanguage = pageLanguage;
|
|
4
|
+
exports.linkLanguage = linkLanguage;
|
|
5
|
+
/**
|
|
6
|
+
* The language of a page, from the browser's (`navigator.language`): Traditional Chinese for Taiwan, Hong Kong, Macau
|
|
7
|
+
* and `Hant`, Simplified for other Chinese, Japanese, else English; as TaLanguageUtil.of of ta-protocol, which the
|
|
8
|
+
* relay does without.
|
|
9
|
+
*/
|
|
10
|
+
function pageLanguage(tag = typeof navigator === 'undefined' ? undefined : navigator.language) {
|
|
11
|
+
const said = (tag !== null && tag !== void 0 ? tag : '').toLowerCase().replace(/_/g, '-');
|
|
12
|
+
if (/^zh(\b|-)/.test(said)) {
|
|
13
|
+
return /-hant\b/.test(said) || (!/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said)) ? 'zh-TW' : 'zh-CN';
|
|
14
|
+
}
|
|
15
|
+
return /^ja(\b|-)/.test(said) ? 'ja-JP' : 'en-US';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The language of a page a link opens: the first of the browser's languages that is Chinese or Japanese, else the
|
|
19
|
+
* language the link was made in (`linked`, the inviter's), else English. A browser in English alone, as many are
|
|
20
|
+
* whatever their users read, gets the page in the words of who sent the link.
|
|
21
|
+
*/
|
|
22
|
+
function linkLanguage(languages, linked) {
|
|
23
|
+
for (const tag of languages) {
|
|
24
|
+
const language = pageLanguage(tag);
|
|
25
|
+
if (language !== 'en-US') {
|
|
26
|
+
return language;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return linked && /^(zh|ja|en)\b/i.test(linked) ? pageLanguage(linked) : 'en-US';
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=page-language.js.map
|
|
@@ -120,7 +120,13 @@ class RelayFriends {
|
|
|
120
120
|
? this.rooms
|
|
121
121
|
.asksOf(mine.id)
|
|
122
122
|
.filter(ask => !ask.guest && !chosen.has(ask.id))
|
|
123
|
-
.map(ask => ({
|
|
123
|
+
.map(ask => ({
|
|
124
|
+
id: ask.id,
|
|
125
|
+
name: ask.name,
|
|
126
|
+
...(relay_identity_1.RelayIdentityUtil.isLook(ask.look) ? { look: ask.look } : {}),
|
|
127
|
+
at: ask.at,
|
|
128
|
+
via: 'link',
|
|
129
|
+
}))
|
|
124
130
|
: [];
|
|
125
131
|
const offers = book.offers.filter(offer => !chosen.has(offer.id) && !asks.some(ask => ask.id === offer.id)).map(RelayFriendsUtil.requestOf);
|
|
126
132
|
return [...asks, ...offers].sort((a, b) => a.at - b.at);
|
|
@@ -129,7 +135,10 @@ class RelayFriends {
|
|
|
129
135
|
asked(ask) {
|
|
130
136
|
if (!ask.guest && !this.read().friends.some(friend => friend.id === ask.id) && !this.told.has(ask.member)) {
|
|
131
137
|
this.told.add(ask.member);
|
|
132
|
-
this.emit({
|
|
138
|
+
this.emit({
|
|
139
|
+
type: 'friend',
|
|
140
|
+
request: { id: ask.id, name: ask.name, ...(relay_identity_1.RelayIdentityUtil.isLook(ask.look) ? { look: ask.look } : {}), at: ask.at, via: 'link' },
|
|
141
|
+
});
|
|
133
142
|
this.emit({ type: 'rooms' });
|
|
134
143
|
}
|
|
135
144
|
this.changed();
|
|
@@ -177,12 +186,14 @@ class RelayFriends {
|
|
|
177
186
|
const mine = rooms.find(room => room.owner && room.kind === exports.RELAY_FRIENDS_KIND);
|
|
178
187
|
return this.read()
|
|
179
188
|
.friends.map(friend => {
|
|
189
|
+
var _a, _b;
|
|
180
190
|
const member = mine === null || mine === void 0 ? void 0 : mine.members.find(item => item.id === friend.id && !item.owner);
|
|
181
191
|
const theirs = this.theirs(rooms, friend.id);
|
|
182
192
|
const owner = theirs === null || theirs === void 0 ? void 0 : theirs.members.find(item => item.owner);
|
|
183
193
|
return {
|
|
184
194
|
id: friend.id,
|
|
185
195
|
name: (member === null || member === void 0 ? void 0 : member.name) || (owner === null || owner === void 0 ? void 0 : owner.name) || friend.name,
|
|
196
|
+
...(relay_identity_1.RelayIdentityUtil.isLook(((_a = member !== null && member !== void 0 ? member : owner) !== null && _a !== void 0 ? _a : friend).look) ? { look: ((_b = member !== null && member !== void 0 ? member : owner) !== null && _b !== void 0 ? _b : friend).look } : {}),
|
|
186
197
|
status: member && (theirs === null || theirs === void 0 ? void 0 : theirs.status) === 'member' ? 'friend' : 'adding',
|
|
187
198
|
online: !!(member === null || member === void 0 ? void 0 : member.online) || !!(owner === null || owner === void 0 ? void 0 : owner.online),
|
|
188
199
|
metAt: friend.metAt,
|
|
@@ -209,7 +220,13 @@ class RelayFriends {
|
|
|
209
220
|
const now = Date.now();
|
|
210
221
|
for (const member of members) {
|
|
211
222
|
const known = book.friends.find(friend => friend.id === member.id);
|
|
212
|
-
if (known &&
|
|
223
|
+
if (known &&
|
|
224
|
+
(known.name !== member.name ||
|
|
225
|
+
known.look !== member.look ||
|
|
226
|
+
known.sign !== member.sign ||
|
|
227
|
+
known.box !== member.box ||
|
|
228
|
+
now - known.seenAt > DAY_MS)) {
|
|
229
|
+
delete known.look;
|
|
213
230
|
Object.assign(known, relay_identity_1.RelayIdentityUtil.publicOf(member), { seenAt: now });
|
|
214
231
|
changed = true;
|
|
215
232
|
}
|
|
@@ -407,6 +424,7 @@ var RelayFriendsUtil;
|
|
|
407
424
|
return {
|
|
408
425
|
id: friend.id,
|
|
409
426
|
name: String((_a = friend.name) !== null && _a !== void 0 ? _a : '').slice(0, 40),
|
|
427
|
+
...(relay_identity_1.RelayIdentityUtil.isLook(friend.look) ? { look: friend.look } : {}),
|
|
410
428
|
...(typeof friend.sign === 'string' ? { sign: friend.sign } : {}),
|
|
411
429
|
...(typeof friend.box === 'string' ? { box: friend.box } : {}),
|
|
412
430
|
metAt: friend.metAt,
|
|
@@ -429,7 +447,14 @@ var RelayFriendsUtil;
|
|
|
429
447
|
}
|
|
430
448
|
RelayFriendsUtil.mergeFriend = mergeFriend;
|
|
431
449
|
function requestOf(offer) {
|
|
432
|
-
return {
|
|
450
|
+
return {
|
|
451
|
+
id: offer.id,
|
|
452
|
+
name: offer.name,
|
|
453
|
+
...(relay_identity_1.RelayIdentityUtil.isLook(offer.look) ? { look: offer.look } : {}),
|
|
454
|
+
at: offer.at,
|
|
455
|
+
via: 'room',
|
|
456
|
+
room: offer.room,
|
|
457
|
+
};
|
|
433
458
|
}
|
|
434
459
|
RelayFriendsUtil.requestOf = requestOf;
|
|
435
460
|
/** `friends.json` as it is now: those of before kept only if they were Moments friends (see migrate). */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type RelayPairing } from './relay-pairing';
|
|
2
|
+
import { RelaySocket } from './relay-socket';
|
|
3
|
+
/**
|
|
4
|
+
* Calls of the host of a package on another Ta, through the relay with a device of it (end to end): asking to come in
|
|
5
|
+
* with the device of a link (RelayTeamJoining), or reading what is shared with the user there from their own Ta. The
|
|
6
|
+
* other Ta checks every call as it does those of its pages.
|
|
7
|
+
*/
|
|
8
|
+
export declare class RelayHostCalls {
|
|
9
|
+
protected readonly pairing: RelayPairing;
|
|
10
|
+
/** The package whose host is called. */
|
|
11
|
+
protected readonly name: string;
|
|
12
|
+
protected socket?: RelaySocket;
|
|
13
|
+
protected opening?: Promise<void>;
|
|
14
|
+
protected next: number;
|
|
15
|
+
protected readonly calls: Map<number, {
|
|
16
|
+
resolve(value: unknown): void;
|
|
17
|
+
reject(error: Error): void;
|
|
18
|
+
timer: ReturnType<typeof setTimeout>;
|
|
19
|
+
}>;
|
|
20
|
+
protected closed: boolean;
|
|
21
|
+
constructor(pairing: RelayPairing,
|
|
22
|
+
/** The package whose host is called. */
|
|
23
|
+
name: string);
|
|
24
|
+
/** From the pairing link of a device. */
|
|
25
|
+
static of(link: string, name: string): RelayHostCalls;
|
|
26
|
+
open(): Promise<void>;
|
|
27
|
+
/** Opens, again after a pause when the connection drops before it opened (not when the other Ta refused the device). */
|
|
28
|
+
protected tryOpen(tries: number): Promise<void>;
|
|
29
|
+
protected openOnce(): Promise<void>;
|
|
30
|
+
callHost(method: string, ...params: unknown[]): Promise<unknown>;
|
|
31
|
+
close(): void;
|
|
32
|
+
protected failAll(error: Error): void;
|
|
33
|
+
protected receive(data: string): void;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=relay-host-calls.d.ts.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelayHostCalls = void 0;
|
|
4
|
+
const relay_pairing_1 = require("./relay-pairing");
|
|
5
|
+
const relay_socket_1 = require("./relay-socket");
|
|
6
|
+
/** How long a call to another Ta waits for its answer. */
|
|
7
|
+
const CALL_MS = 30000;
|
|
8
|
+
/** Tries to reach it, a while apart: a Ta that just made the link may be on its way to the relay. */
|
|
9
|
+
const OPEN_TRIES = 6;
|
|
10
|
+
const OPEN_PAUSE_MS = 700;
|
|
11
|
+
/**
|
|
12
|
+
* Calls of the host of a package on another Ta, through the relay with a device of it (end to end): asking to come in
|
|
13
|
+
* with the device of a link (RelayTeamJoining), or reading what is shared with the user there from their own Ta. The
|
|
14
|
+
* other Ta checks every call as it does those of its pages.
|
|
15
|
+
*/
|
|
16
|
+
class RelayHostCalls {
|
|
17
|
+
constructor(pairing,
|
|
18
|
+
/** The package whose host is called. */
|
|
19
|
+
name) {
|
|
20
|
+
this.pairing = pairing;
|
|
21
|
+
this.name = name;
|
|
22
|
+
this.next = 1;
|
|
23
|
+
this.calls = new Map();
|
|
24
|
+
this.closed = false;
|
|
25
|
+
}
|
|
26
|
+
/** From the pairing link of a device. */
|
|
27
|
+
static of(link, name) {
|
|
28
|
+
return new RelayHostCalls(relay_pairing_1.RelayPairingUtil.parse(link), name);
|
|
29
|
+
}
|
|
30
|
+
open() {
|
|
31
|
+
var _a;
|
|
32
|
+
(_a = this.opening) !== null && _a !== void 0 ? _a : (this.opening = this.tryOpen(OPEN_TRIES));
|
|
33
|
+
return this.opening;
|
|
34
|
+
}
|
|
35
|
+
/** Opens, again after a pause when the connection drops before it opened (not when the other Ta refused the device). */
|
|
36
|
+
async tryOpen(tries) {
|
|
37
|
+
for (let left = tries;; left--) {
|
|
38
|
+
try {
|
|
39
|
+
await this.openOnce();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (left <= 1 || this.closed || error.refused) {
|
|
44
|
+
this.opening = undefined;
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
await new Promise(resolve => setTimeout(resolve, OPEN_PAUSE_MS));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
openOnce() {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
let opened = false;
|
|
54
|
+
const socket = new relay_socket_1.RelaySocket(this.pairing);
|
|
55
|
+
this.socket = socket;
|
|
56
|
+
socket.onopen = () => {
|
|
57
|
+
opened = true;
|
|
58
|
+
resolve();
|
|
59
|
+
};
|
|
60
|
+
socket.onerror = () => {
|
|
61
|
+
if (!opened) {
|
|
62
|
+
reject(new Error('The other Ta did not answer: is it running?'));
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
socket.onclose = event => {
|
|
66
|
+
const refused = event.code === relay_socket_1.RelaySocket.REFUSED;
|
|
67
|
+
const error = Object.assign(new Error(refused ? 'The other Ta no longer knows this device.' : 'The connection to the other Ta was lost.'), {
|
|
68
|
+
refused,
|
|
69
|
+
});
|
|
70
|
+
if (!opened) {
|
|
71
|
+
reject(error);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this.failAll(error);
|
|
75
|
+
this.opening = undefined;
|
|
76
|
+
};
|
|
77
|
+
socket.onmessage = message => this.receive(message.data);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async callHost(method, ...params) {
|
|
81
|
+
await this.open();
|
|
82
|
+
const id = this.next++;
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
var _a;
|
|
85
|
+
const timer = setTimeout(() => {
|
|
86
|
+
this.calls.delete(id);
|
|
87
|
+
reject(new Error('The other Ta did not answer in time.'));
|
|
88
|
+
}, CALL_MS);
|
|
89
|
+
this.calls.set(id, { resolve, reject, timer });
|
|
90
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({ jsonrpc: '2.0', id, method: 'TaPackageServer/callPackageHost', params: [this.name, method, params] }));
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
close() {
|
|
94
|
+
var _a;
|
|
95
|
+
this.closed = true;
|
|
96
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
|
|
97
|
+
this.failAll(new Error('Stopped.'));
|
|
98
|
+
}
|
|
99
|
+
failAll(error) {
|
|
100
|
+
for (const call of this.calls.values()) {
|
|
101
|
+
clearTimeout(call.timer);
|
|
102
|
+
call.reject(error);
|
|
103
|
+
}
|
|
104
|
+
this.calls.clear();
|
|
105
|
+
}
|
|
106
|
+
receive(data) {
|
|
107
|
+
var _a;
|
|
108
|
+
let message;
|
|
109
|
+
try {
|
|
110
|
+
message = JSON.parse(data);
|
|
111
|
+
}
|
|
112
|
+
catch (_b) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const call = typeof message.id === 'number' ? this.calls.get(message.id) : undefined;
|
|
116
|
+
if (!call) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.calls.delete(message.id);
|
|
120
|
+
clearTimeout(call.timer);
|
|
121
|
+
if (message.error) {
|
|
122
|
+
call.reject(new Error((_a = message.error.message) !== null && _a !== void 0 ? _a : 'Failed.'));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
call.resolve(message.result);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.RelayHostCalls = RelayHostCalls;
|
|
130
|
+
//# sourceMappingURL=relay-host-calls.js.map
|
|
@@ -5,8 +5,9 @@ import { type RelayHubEntry, type RelayHubFailure, type RelayHubRequest } from '
|
|
|
5
5
|
/** What a member sends in a message, signed and sealed: data of an extension, or a word of Ta itself. */
|
|
6
6
|
export interface MessageBody {
|
|
7
7
|
d?: unknown;
|
|
8
|
-
/** A member's new name, for the owner to put in the roster. */
|
|
8
|
+
/** A member's new name, for the owner to put in the roster; with its look (RelayPublicIdentity.look), '' for none. */
|
|
9
9
|
name?: string;
|
|
10
|
+
look?: string;
|
|
10
11
|
/** Asks the one it is sent to to be friends: the link of the sender's room of friends (RelayFriends.offer). */
|
|
11
12
|
friend?: string;
|
|
12
13
|
}
|
|
@@ -43,6 +44,8 @@ export declare class Live {
|
|
|
43
44
|
timer?: ReturnType<typeof setTimeout>;
|
|
44
45
|
pingTimer?: ReturnType<typeof setInterval>;
|
|
45
46
|
awaitingPong: boolean;
|
|
47
|
+
/** The look this Ta last sent the owner, for the roster to say: once, whatever the owner does with it. */
|
|
48
|
+
toldLook?: string;
|
|
46
49
|
/** Events are handled one after another: opening them is async. */
|
|
47
50
|
chain: Promise<void>;
|
|
48
51
|
constructor(record: RelayRoomRecord);
|
|
@@ -94,6 +97,11 @@ export declare abstract class RelayHubsConnection {
|
|
|
94
97
|
/** A member asks the user to be friends, by the link of its room of friends. */
|
|
95
98
|
protected offered(_live: Live, _from: RelayPublicIdentity, _link: string): void;
|
|
96
99
|
protected readRoster(live: Live, sealed: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* The roster says this Ta as it is now: its look, set while the room was away or the owner offline. The owner writes it,
|
|
102
|
+
* a member tells the owner, once a connection. A room joined with another identity keeps that one's.
|
|
103
|
+
*/
|
|
104
|
+
protected keepLook(live: Live): Promise<void>;
|
|
97
105
|
protected guestOf(live: Live, member: string): boolean;
|
|
98
106
|
protected signOf(live: Live): (member: string) => string | undefined;
|
|
99
107
|
protected readEntry(live: Live, entry: RelayHubEntry, tell: boolean): Promise<void>;
|
|
@@ -76,6 +76,7 @@ class RelayHubsConnection {
|
|
|
76
76
|
ask: ask.member,
|
|
77
77
|
id: ask.id,
|
|
78
78
|
name: ask.name,
|
|
79
|
+
...(relay_identity_1.RelayIdentityUtil.isLook(ask.look) ? { look: ask.look } : {}),
|
|
79
80
|
friend: friends.has(ask.id),
|
|
80
81
|
...(ask.guest ? { guest: true } : {}),
|
|
81
82
|
at: ask.at,
|
|
@@ -417,6 +418,35 @@ class RelayHubsConnection {
|
|
|
417
418
|
this.heardMembers(members.filter(member => member.id !== own && !member.guest));
|
|
418
419
|
if (!members.some(member => member.member === live.record.member) && !live.record.own && live.record.status === 'member') {
|
|
419
420
|
this.setStatus(live, 'gone', 'removed');
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
// Not awaited: what it sends waits for the room to be ready, which may wait for this event.
|
|
424
|
+
void this.keepLook(live);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* The roster says this Ta as it is now: its look, set while the room was away or the owner offline. The owner writes it,
|
|
428
|
+
* a member tells the owner, once a connection. A room joined with another identity keeps that one's.
|
|
429
|
+
*/
|
|
430
|
+
async keepLook(live) {
|
|
431
|
+
var _a, _b;
|
|
432
|
+
if (live.record.status !== 'member' || live.record.identity || !live.roster) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const identity = await this.identity();
|
|
436
|
+
const look = (_a = identity.look) !== null && _a !== void 0 ? _a : '';
|
|
437
|
+
const self = live.roster.members.find(member => member.member === live.record.member);
|
|
438
|
+
if (!self || ((_b = self.look) !== null && _b !== void 0 ? _b : '') === look) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (live.record.own) {
|
|
442
|
+
await this.writeRoster(live, members => members.map(member => (member.member === self.member ? relay_identity_1.RelayIdentityUtil.withLook(member, look) : member))).catch(() => undefined);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const owner = live.roster.members.find(member => member.owner);
|
|
446
|
+
if (owner && live.toldLook !== look) {
|
|
447
|
+
await this.sendBody(live, { name: identity.name, look }, owner.member).then(() => {
|
|
448
|
+
live.toldLook = look;
|
|
449
|
+
}, () => undefined);
|
|
420
450
|
}
|
|
421
451
|
}
|
|
422
452
|
guestOf(live, member) {
|
|
@@ -473,7 +503,9 @@ class RelayHubsConnection {
|
|
|
473
503
|
if (typeof signed.b.name === 'string') {
|
|
474
504
|
if (live.record.own && sender) {
|
|
475
505
|
const name = signed.b.name.trim().slice(0, 40);
|
|
476
|
-
|
|
506
|
+
// A Ta of before tells its name alone: its look stays as it was.
|
|
507
|
+
const look = typeof signed.b.look === 'string' ? signed.b.look : sender.look;
|
|
508
|
+
await this.writeRoster(live, members => members.map(member => (member.member === from ? relay_identity_1.RelayIdentityUtil.withLook({ ...member, name }, look) : member))).catch(() => undefined);
|
|
477
509
|
}
|
|
478
510
|
return;
|
|
479
511
|
}
|
|
@@ -56,6 +56,8 @@ export interface RelayRoomMember {
|
|
|
56
56
|
/** The identity of its Ta. */
|
|
57
57
|
id: string;
|
|
58
58
|
name: string;
|
|
59
|
+
/** The look of its double (RelayPublicIdentity.look). */
|
|
60
|
+
look?: string;
|
|
59
61
|
owner: boolean;
|
|
60
62
|
online: boolean;
|
|
61
63
|
self: boolean;
|
|
@@ -88,6 +90,8 @@ export interface RelayRoomRequest {
|
|
|
88
90
|
/** Its identity, and the name it gives. */
|
|
89
91
|
id: string;
|
|
90
92
|
name: string;
|
|
93
|
+
/** The look of its double (RelayPublicIdentity.look). */
|
|
94
|
+
look?: string;
|
|
91
95
|
/** Met before, in another room. */
|
|
92
96
|
friend: boolean;
|
|
93
97
|
/** Asks from a browser, without Ta: admitted, it only chats. */
|
|
@@ -98,7 +102,7 @@ export interface RelayRoomRequest {
|
|
|
98
102
|
* One the user chose as a friend (docs/design/ta-link.md 3.1), in `friends.json`: its keys once known (from its link
|
|
99
103
|
* only its id and name), when chosen and last heard of.
|
|
100
104
|
*/
|
|
101
|
-
export interface RelayFriend extends Pick<RelayPublicIdentity, 'id' | 'name'>, Partial<Pick<RelayPublicIdentity, 'sign' | 'box'>> {
|
|
105
|
+
export interface RelayFriend extends Pick<RelayPublicIdentity, 'id' | 'name'>, Partial<Pick<RelayPublicIdentity, 'sign' | 'box' | 'look'>> {
|
|
102
106
|
metAt: number;
|
|
103
107
|
seenAt: number;
|
|
104
108
|
}
|
|
@@ -106,6 +110,8 @@ export interface RelayFriend extends Pick<RelayPublicIdentity, 'id' | 'name'>, P
|
|
|
106
110
|
export interface RelayFriendInfo {
|
|
107
111
|
id: string;
|
|
108
112
|
name: string;
|
|
113
|
+
/** The look of its double (RelayPublicIdentity.look). */
|
|
114
|
+
look?: string;
|
|
109
115
|
status: 'friend' | 'adding';
|
|
110
116
|
online: boolean;
|
|
111
117
|
metAt: number;
|
|
@@ -115,6 +121,8 @@ export interface RelayFriendInfo {
|
|
|
115
121
|
export interface RelayFriendRequest {
|
|
116
122
|
id: string;
|
|
117
123
|
name: string;
|
|
124
|
+
/** The look of its double (RelayPublicIdentity.look). */
|
|
125
|
+
look?: string;
|
|
118
126
|
at: number;
|
|
119
127
|
via: 'link' | 'room';
|
|
120
128
|
room?: string;
|
|
@@ -17,6 +17,13 @@ export declare class RelayHubs extends RelayHubsConnection {
|
|
|
17
17
|
onEvent(listener: (event: RelayRoomEvent) => void): () => void;
|
|
18
18
|
/** The name others see; the owners of rooms this Ta is in hear it. */
|
|
19
19
|
setName(name: string): Promise<RelayPublicIdentity>;
|
|
20
|
+
/**
|
|
21
|
+
* The kind of dinosaur the double of this Ta is (RelayPublicIdentity.look), which others draw it by; none for a
|
|
22
|
+
* look that is none. The owners of rooms this Ta is in hear it, as a name.
|
|
23
|
+
*/
|
|
24
|
+
setLook(look: string | undefined): Promise<RelayPublicIdentity>;
|
|
25
|
+
/** Keeps the identity with a new name or look, and tells the rooms this Ta is in. */
|
|
26
|
+
protected changeSelf(identity: RelayIdentity): Promise<RelayPublicIdentity>;
|
|
20
27
|
list(): RelayRoomInfo[];
|
|
21
28
|
room(id: string): RelayRoomInfo | undefined;
|
|
22
29
|
create(input: {
|
package/lib/common/relay-hubs.js
CHANGED
|
@@ -74,7 +74,20 @@ class RelayHubs extends relay_hubs_connection_1.RelayHubsConnection {
|
|
|
74
74
|
if (!trimmed) {
|
|
75
75
|
throw new Error('A name is needed.');
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
return this.changeSelf({ ...(await this.identity()), name: trimmed });
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The kind of dinosaur the double of this Ta is (RelayPublicIdentity.look), which others draw it by; none for a
|
|
81
|
+
* look that is none. The owners of rooms this Ta is in hear it, as a name.
|
|
82
|
+
*/
|
|
83
|
+
async setLook(look) {
|
|
84
|
+
const identity = await this.identity();
|
|
85
|
+
const next = relay_identity_1.RelayIdentityUtil.withLook(identity, look);
|
|
86
|
+
return next.look === identity.look ? relay_identity_1.RelayIdentityUtil.publicOf(identity) : this.changeSelf(next);
|
|
87
|
+
}
|
|
88
|
+
/** Keeps the identity with a new name or look, and tells the rooms this Ta is in. */
|
|
89
|
+
async changeSelf(identity) {
|
|
90
|
+
var _a;
|
|
78
91
|
this.options.store.write('identity', identity);
|
|
79
92
|
this.own = identity;
|
|
80
93
|
for (const live of this.live.values()) {
|
|
@@ -83,12 +96,15 @@ class RelayHubs extends relay_hubs_connection_1.RelayHubsConnection {
|
|
|
83
96
|
continue;
|
|
84
97
|
}
|
|
85
98
|
if (live.record.own) {
|
|
86
|
-
await this.writeRoster(live, members => members.map(member => (member.id === identity.id ? { ...member, name:
|
|
99
|
+
await this.writeRoster(live, members => members.map(member => (member.id === identity.id ? relay_identity_1.RelayIdentityUtil.withLook({ ...member, name: identity.name }, identity.look) : member))).catch(() => undefined);
|
|
87
100
|
}
|
|
88
101
|
else if (live.roster) {
|
|
89
102
|
const owner = live.roster.members.find(member => member.owner);
|
|
90
103
|
if (owner) {
|
|
91
|
-
|
|
104
|
+
const look = (_a = identity.look) !== null && _a !== void 0 ? _a : '';
|
|
105
|
+
await this.sendBody(live, { name: identity.name, look }, owner.member).then(() => {
|
|
106
|
+
live.toldLook = look;
|
|
107
|
+
}, () => undefined);
|
|
92
108
|
}
|
|
93
109
|
}
|
|
94
110
|
}
|
|
@@ -544,6 +560,7 @@ class RelayHubs extends relay_hubs_connection_1.RelayHubsConnection {
|
|
|
544
560
|
member: member.member,
|
|
545
561
|
id: member.id,
|
|
546
562
|
name: member.name,
|
|
563
|
+
...(relay_identity_1.RelayIdentityUtil.isLook(member.look) ? { look: member.look } : {}),
|
|
547
564
|
owner: !!member.owner,
|
|
548
565
|
online: member.member === record.member ? ((_a = live.socket) === null || _a === void 0 ? void 0 : _a.readyState) === relay_hubs_connection_1.OPEN && live.synced : live.online.has(member.member),
|
|
549
566
|
self: member.member === record.member,
|