@celljs/ta-web 4.27.0 → 4.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/browser/assistant/assistant-role.d.ts +9 -4
- package/esm/browser/assistant/assistant-role.js +17 -5
- package/esm/browser/assistant/assistant-task-util.d.ts +6 -0
- package/esm/browser/assistant/assistant-task-util.js +12 -1
- package/esm/browser/assistant/assistant-view.js +4 -1
- package/esm/browser/assistant/assistant.d.ts +2 -1
- package/esm/browser/assistant/assistant.js +9 -7
- package/esm/browser/assistant/call-conversing.d.ts +45 -0
- package/esm/browser/assistant/call-conversing.js +91 -0
- package/esm/browser/assistant/call-face.d.ts +13 -0
- package/esm/browser/assistant/call-face.js +81 -0
- package/esm/browser/assistant/call-keeper.d.ts +8 -4
- package/esm/browser/assistant/call-keeper.js +32 -11
- package/esm/browser/assistant/call-partnering.d.ts +37 -0
- package/esm/browser/assistant/call-partnering.js +79 -0
- package/esm/browser/assistant/call-scenes.d.ts +25 -0
- package/esm/browser/assistant/call-scenes.js +82 -0
- package/esm/browser/assistant/call-screen.d.ts +3 -0
- package/esm/browser/assistant/call-screen.js +15 -0
- package/esm/browser/assistant/mic-sense.d.ts +31 -0
- package/esm/browser/assistant/mic-sense.js +119 -0
- package/esm/browser/assistant/noise-gate.d.ts +32 -0
- package/esm/browser/assistant/noise-gate.js +66 -0
- package/esm/browser/assistant/pcm-util.d.ts +10 -0
- package/esm/browser/assistant/pcm-util.js +55 -0
- package/esm/browser/assistant/read-aloud.d.ts +2 -1
- package/esm/browser/assistant/realtime-voice-protocol.d.ts +84 -0
- package/esm/browser/assistant/realtime-voice-protocol.js +40 -0
- package/esm/browser/assistant/realtime-voice.d.ts +50 -62
- package/esm/browser/assistant/realtime-voice.js +213 -134
- package/esm/browser/assistant/spoken-timeline.d.ts +27 -0
- package/esm/browser/assistant/spoken-timeline.js +49 -0
- package/esm/browser/assistant/voice-call-bar.d.ts +9 -2
- package/esm/browser/assistant/voice-call-bar.js +81 -31
- package/esm/browser/assistant/voice-call-protocol.d.ts +61 -4
- package/esm/browser/assistant/voice-call.d.ts +16 -23
- package/esm/browser/assistant/voice-call.js +134 -117
- package/esm/browser/assistant/voice-reading.d.ts +83 -0
- package/esm/browser/assistant/voice-reading.js +150 -0
- package/esm/browser/avatar/dino-talk.d.ts +15 -0
- package/esm/browser/avatar/dino-talk.js +34 -0
- package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/esm/browser/components/conversation-scroll-util.d.ts +8 -1
- package/esm/browser/components/conversation-scroll-util.js +21 -0
- package/esm/browser/components/conversation-scroll.js +10 -11
- package/esm/browser/components/gallery.js +28 -7
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/image-pull.d.ts +64 -0
- package/esm/browser/components/image-pull.js +202 -0
- package/esm/browser/components/kept-call-bar.js +2 -1
- package/esm/browser/components/lightbox.d.ts +1 -1
- package/esm/browser/components/lightbox.js +57 -2
- package/esm/browser/components/markdown.d.ts +3 -1
- package/esm/browser/components/markdown.js +8 -4
- package/esm/browser/components/partner-row.js +2 -1
- package/esm/browser/components/relay-services.d.ts +9 -3
- package/esm/browser/components/relay-services.js +73 -35
- package/esm/browser/components/session-view.js +4 -2
- package/esm/browser/components/settings-parts.js +2 -0
- package/esm/browser/components/ta-avatar.d.ts +15 -1
- package/esm/browser/components/ta-avatar.js +38 -5
- package/esm/browser/components/voice-services.js +6 -1
- package/esm/browser/extension/web-api-call.d.ts +64 -2
- package/esm/browser/extension/web-api-contributions.d.ts +1 -0
- package/esm/browser/extension/web-api-partners.d.ts +2 -0
- package/esm/browser/extension/web-extension-api.d.ts +6 -6
- package/esm/browser/extension/web-extension-context.js +1 -0
- package/esm/browser/extension/web-extension-protocol.d.ts +3 -1
- package/esm/browser/extension/web-extension-run.d.ts +3 -2
- package/esm/browser/extension/web-extension-run.js +2 -0
- package/esm/browser/i18n/locales.d.ts +24 -5
- package/esm/browser/i18n/messages-ja.js +25 -6
- package/esm/browser/i18n/messages-zh-tw.js +25 -6
- package/esm/browser/i18n/messages.d.ts +23 -4
- package/esm/browser/i18n/messages.js +50 -12
- package/esm/browser/markdown/code-renderers.d.ts +2 -0
- package/esm/browser/markdown/code-renderers.js +2 -0
- package/esm/browser/screen/page-answers.d.ts +2 -1
- package/esm/browser/screen/page-answers.js +7 -4
- package/esm/browser/settings/settings-protocol.d.ts +2 -0
- package/esm/browser/settings/settings-protocol.js +2 -0
- package/esm/browser/style/chat-list.d.ts +1 -1
- package/esm/browser/style/chat-list.js +1 -1
- package/esm/browser/style/conversation.d.ts +1 -1
- package/esm/browser/style/conversation.js +6 -1
- package/esm/browser/style/device.js +1 -0
- package/esm/browser/style/dialogs.d.ts +1 -1
- package/esm/browser/style/dialogs.js +1 -1
- package/esm/browser/style/layout.d.ts +1 -1
- package/esm/browser/style/layout.js +135 -57
- package/esm/browser/style/shell.d.ts +1 -1
- package/esm/browser/style/shell.js +8 -0
- package/esm/browser/style/video-call.d.ts +2 -0
- package/esm/browser/style/video-call.js +52 -0
- package/esm/browser/style.js +2 -0
- package/esm/browser/util/desktop.d.ts +10 -1
- package/esm/browser/util/desktop.js +10 -0
- package/esm/browser/util/image-pull.d.ts +61 -0
- package/esm/browser/util/image-pull.js +88 -0
- package/esm/browser/util/spoken.d.ts +3 -3
- package/esm/browser/util/spoken.js +4 -4
- package/esm/browser/video-call/call-camera.d.ts +59 -0
- package/esm/browser/video-call/call-camera.js +188 -0
- package/esm/browser/video-call/call-window.d.ts +19 -0
- package/esm/browser/video-call/call-window.js +80 -0
- package/esm/browser/video-call/clip-plan.d.ts +47 -0
- package/esm/browser/video-call/clip-plan.js +60 -0
- package/esm/browser/video-call/face-clips.d.ts +33 -0
- package/esm/browser/video-call/face-clips.js +93 -0
- package/esm/browser/video-call/face-files.d.ts +31 -0
- package/esm/browser/video-call/face-files.js +77 -0
- package/esm/browser/video-call/video-call-view.d.ts +19 -0
- package/esm/browser/video-call/video-call-view.js +214 -0
- package/esm/browser/video-call/video-face.d.ts +13 -0
- package/esm/browser/video-call/video-face.js +497 -0
- package/esm/browser/workbench-hosts.d.ts +1 -0
- package/esm/browser/workbench-protocol.d.ts +2 -0
- package/esm/browser/workbench-util.d.ts +5 -0
- package/esm/browser/workbench-util.js +18 -0
- package/esm/browser/workbench.d.ts +6 -0
- package/esm/browser/workbench.js +36 -5
- package/lib/browser/assistant/assistant-role.d.ts +9 -4
- package/lib/browser/assistant/assistant-role.js +17 -5
- package/lib/browser/assistant/assistant-task-util.d.ts +6 -0
- package/lib/browser/assistant/assistant-task-util.js +11 -0
- package/lib/browser/assistant/assistant-view.js +3 -0
- package/lib/browser/assistant/assistant.d.ts +2 -1
- package/lib/browser/assistant/assistant.js +9 -7
- package/lib/browser/assistant/call-conversing.d.ts +46 -0
- package/lib/browser/assistant/call-conversing.js +96 -0
- package/lib/browser/assistant/call-face.d.ts +14 -0
- package/lib/browser/assistant/call-face.js +117 -0
- package/lib/browser/assistant/call-keeper.d.ts +8 -4
- package/lib/browser/assistant/call-keeper.js +32 -11
- package/lib/browser/assistant/call-partnering.d.ts +38 -0
- package/lib/browser/assistant/call-partnering.js +83 -0
- package/lib/browser/assistant/call-scenes.d.ts +26 -0
- package/lib/browser/assistant/call-scenes.js +85 -0
- package/lib/browser/assistant/call-screen.d.ts +3 -0
- package/lib/browser/assistant/call-screen.js +15 -0
- package/lib/browser/assistant/mic-sense.d.ts +32 -0
- package/lib/browser/assistant/mic-sense.js +123 -0
- package/lib/browser/assistant/noise-gate.d.ts +33 -0
- package/lib/browser/assistant/noise-gate.js +71 -0
- package/lib/browser/assistant/pcm-util.d.ts +11 -0
- package/lib/browser/assistant/pcm-util.js +58 -0
- package/lib/browser/assistant/read-aloud.d.ts +2 -1
- package/lib/browser/assistant/realtime-voice-protocol.d.ts +85 -0
- package/lib/browser/assistant/realtime-voice-protocol.js +43 -0
- package/lib/browser/assistant/realtime-voice.d.ts +50 -62
- package/lib/browser/assistant/realtime-voice.js +217 -138
- package/lib/browser/assistant/spoken-timeline.d.ts +28 -0
- package/lib/browser/assistant/spoken-timeline.js +53 -0
- package/lib/browser/assistant/voice-call-bar.d.ts +9 -2
- package/lib/browser/assistant/voice-call-bar.js +81 -30
- package/lib/browser/assistant/voice-call-protocol.d.ts +61 -4
- package/lib/browser/assistant/voice-call.d.ts +16 -23
- package/lib/browser/assistant/voice-call.js +134 -117
- package/lib/browser/assistant/voice-reading.d.ts +84 -0
- package/lib/browser/assistant/voice-reading.js +156 -0
- package/lib/browser/avatar/dino-talk.d.ts +16 -0
- package/lib/browser/avatar/dino-talk.js +37 -0
- package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/lib/browser/components/conversation-scroll-util.d.ts +8 -1
- package/lib/browser/components/conversation-scroll-util.js +21 -0
- package/lib/browser/components/conversation-scroll.js +10 -11
- package/lib/browser/components/gallery.js +28 -7
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/image-pull.d.ts +65 -0
- package/lib/browser/components/image-pull.js +206 -0
- package/lib/browser/components/kept-call-bar.js +2 -1
- package/lib/browser/components/lightbox.d.ts +1 -1
- package/lib/browser/components/lightbox.js +57 -2
- package/lib/browser/components/markdown.d.ts +3 -1
- package/lib/browser/components/markdown.js +7 -3
- package/lib/browser/components/partner-row.js +2 -1
- package/lib/browser/components/relay-services.d.ts +9 -3
- package/lib/browser/components/relay-services.js +71 -33
- package/lib/browser/components/session-view.js +3 -1
- package/lib/browser/components/settings-parts.js +2 -0
- package/lib/browser/components/ta-avatar.d.ts +15 -1
- package/lib/browser/components/ta-avatar.js +38 -5
- package/lib/browser/components/voice-services.js +5 -0
- package/lib/browser/extension/web-api-call.d.ts +64 -2
- package/lib/browser/extension/web-api-contributions.d.ts +1 -0
- package/lib/browser/extension/web-api-partners.d.ts +2 -0
- package/lib/browser/extension/web-extension-api.d.ts +6 -6
- package/lib/browser/extension/web-extension-context.js +1 -0
- package/lib/browser/extension/web-extension-protocol.d.ts +3 -1
- package/lib/browser/extension/web-extension-run.d.ts +3 -2
- package/lib/browser/extension/web-extension-run.js +2 -0
- package/lib/browser/i18n/locales.d.ts +24 -5
- package/lib/browser/i18n/messages-ja.js +25 -6
- package/lib/browser/i18n/messages-zh-tw.js +25 -6
- package/lib/browser/i18n/messages.d.ts +23 -4
- package/lib/browser/i18n/messages.js +50 -12
- package/lib/browser/markdown/code-renderers.d.ts +2 -0
- package/lib/browser/markdown/code-renderers.js +3 -1
- package/lib/browser/screen/page-answers.d.ts +2 -1
- package/lib/browser/screen/page-answers.js +7 -4
- package/lib/browser/settings/settings-protocol.d.ts +2 -0
- package/lib/browser/settings/settings-protocol.js +2 -0
- package/lib/browser/style/chat-list.d.ts +1 -1
- package/lib/browser/style/chat-list.js +1 -1
- package/lib/browser/style/conversation.d.ts +1 -1
- package/lib/browser/style/conversation.js +6 -1
- package/lib/browser/style/device.js +1 -0
- package/lib/browser/style/dialogs.d.ts +1 -1
- package/lib/browser/style/dialogs.js +1 -1
- package/lib/browser/style/layout.d.ts +1 -1
- package/lib/browser/style/layout.js +135 -57
- package/lib/browser/style/shell.d.ts +1 -1
- package/lib/browser/style/shell.js +8 -0
- package/lib/browser/style/video-call.d.ts +3 -0
- package/lib/browser/style/video-call.js +55 -0
- package/lib/browser/style.js +2 -0
- package/lib/browser/util/desktop.d.ts +10 -1
- package/lib/browser/util/desktop.js +10 -0
- package/lib/browser/util/image-pull.d.ts +62 -0
- package/lib/browser/util/image-pull.js +91 -0
- package/lib/browser/util/spoken.d.ts +3 -3
- package/lib/browser/util/spoken.js +4 -4
- package/lib/browser/video-call/call-camera.d.ts +60 -0
- package/lib/browser/video-call/call-camera.js +192 -0
- package/lib/browser/video-call/call-window.d.ts +20 -0
- package/lib/browser/video-call/call-window.js +83 -0
- package/lib/browser/video-call/clip-plan.d.ts +48 -0
- package/lib/browser/video-call/clip-plan.js +64 -0
- package/lib/browser/video-call/face-clips.d.ts +34 -0
- package/lib/browser/video-call/face-clips.js +96 -0
- package/lib/browser/video-call/face-files.d.ts +32 -0
- package/lib/browser/video-call/face-files.js +82 -0
- package/lib/browser/video-call/video-call-view.d.ts +20 -0
- package/lib/browser/video-call/video-call-view.js +250 -0
- package/lib/browser/video-call/video-face.d.ts +14 -0
- package/lib/browser/video-call/video-face.js +533 -0
- package/lib/browser/workbench-hosts.d.ts +1 -0
- package/lib/browser/workbench-protocol.d.ts +2 -0
- package/lib/browser/workbench-util.d.ts +5 -0
- package/lib/browser/workbench-util.js +18 -0
- package/lib/browser/workbench.d.ts +6 -0
- package/lib/browser/workbench.js +35 -4
- package/package.json +7 -7
- package/public/faces/README.md +27 -0
- package/public/faces/clap.mp4 +0 -0
- package/public/faces/dance.mp4 +0 -0
- package/public/faces/happy.mp4 +0 -0
- package/public/faces/heart.mp4 +0 -0
- package/public/faces/idle-1.mp4 +0 -0
- package/public/faces/idle-2.mp4 +0 -0
- package/public/faces/idle-3.mp4 +0 -0
- package/public/faces/laugh.mp4 +0 -0
- package/public/faces/lips.json +1 -0
- package/public/faces/listening.mp4 +0 -0
- package/public/faces/poster.jpg +0 -0
- package/public/faces/shy.mp4 +0 -0
- package/public/faces/sorry.mp4 +0 -0
- package/public/faces/stretch.mp4 +0 -0
- package/public/faces/surprised.mp4 +0 -0
- package/public/faces/talk-1.mp4 +0 -0
- package/public/faces/talk-2.mp4 +0 -0
- package/public/faces/think-2.mp4 +0 -0
- package/public/faces/thinking.mp4 +0 -0
- package/public/faces/wave.mp4 +0 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useWebExtensions } from '../hooks.js';
|
|
3
|
+
import { CLIP_FPS, ClipPlan, ClipSync } from './clip-plan.js';
|
|
4
|
+
import { FaceClips } from './face-clips.js';
|
|
5
|
+
import { FaceFiles } from './face-files.js';
|
|
6
|
+
/** How often the face looks at the call (its phase), in ms. */
|
|
7
|
+
const TICK_MS = 80;
|
|
8
|
+
/** How fast she goes back to the sofa from a dance or a stretch, as the call goes on. */
|
|
9
|
+
const HURRY_RATE = 2.5;
|
|
10
|
+
/** How much longer a reading may wait while the mouth starts, at most, in ms. */
|
|
11
|
+
const STARTING_MS = 6000;
|
|
12
|
+
/** How long the sound may not go on before the clip holds still too, in ms (the clock of sound moves in steps). */
|
|
13
|
+
const STILL_MS = 120;
|
|
14
|
+
/** The frames of a clip when faces/lips.json does not say (5 s and a sixth at 24 fps). */
|
|
15
|
+
const FRAMES = 124;
|
|
16
|
+
/** How many frames the clip shown may be from the one a mouth was drawn for, laid over it moved with the face. */
|
|
17
|
+
const NEAR_FRAMES = 3;
|
|
18
|
+
/**
|
|
19
|
+
* The person of a video call: two layers of video, the one in front playing, the other taking over with a short fade
|
|
20
|
+
* when the clip changes. As Ta reads with a voice service, the clip is the one its ClipPlan has for that moment of the
|
|
21
|
+
* sound, and the mouth an extension draws for that moment is laid over it (MouthLayer); otherwise clips play by the
|
|
22
|
+
* state of the call.
|
|
23
|
+
*/
|
|
24
|
+
export function VideoFace({ call, onReady, onFailed }) {
|
|
25
|
+
var _a;
|
|
26
|
+
var _b;
|
|
27
|
+
const layers = [React.useRef(null), React.useRef(null)];
|
|
28
|
+
const box = React.useRef(null);
|
|
29
|
+
const canvas = React.useRef(null);
|
|
30
|
+
const [front, setFront] = React.useState(0);
|
|
31
|
+
const [{ callMouth }] = useWebExtensions();
|
|
32
|
+
const mouth = React.useRef(callMouth);
|
|
33
|
+
mouth.current = callMouth;
|
|
34
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the layers are refs, set up once a call
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
var _a;
|
|
37
|
+
var _b, _c;
|
|
38
|
+
const doc = (_b = (_a = box.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) !== null && _b !== void 0 ? _b : document;
|
|
39
|
+
const view = (_c = doc.defaultView) !== null && _c !== void 0 ? _c : window;
|
|
40
|
+
const videos = layers.map(layer => layer.current).filter((video) => !!video);
|
|
41
|
+
if (videos.length !== 2) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let gone = false;
|
|
45
|
+
let shown = 0;
|
|
46
|
+
let kind;
|
|
47
|
+
let ready = false;
|
|
48
|
+
const faces = FaceFiles.of(doc);
|
|
49
|
+
const frames = (clip) => { var _a; return (_a = faces.frames(clip)) !== null && _a !== void 0 ? _a : FRAMES; };
|
|
50
|
+
// The clip each layer plays, by name, and the one the layer behind is loading to come in front.
|
|
51
|
+
const names = [undefined, undefined];
|
|
52
|
+
let loading;
|
|
53
|
+
let last;
|
|
54
|
+
// The sentence whose look played (moodFor), and whether that clip is over: once a sentence.
|
|
55
|
+
let moodFor;
|
|
56
|
+
let moodDone = false;
|
|
57
|
+
// What she said she would do (FaceClips.show), and the sentence that said it: it plays once she listens.
|
|
58
|
+
let coming;
|
|
59
|
+
let comingFor;
|
|
60
|
+
const words = () => {
|
|
61
|
+
const reading = call.state.reading;
|
|
62
|
+
return reading === null || reading === void 0 ? void 0 : reading.pieces[reading.at];
|
|
63
|
+
};
|
|
64
|
+
const wanted = () => {
|
|
65
|
+
const { phase, paused } = call.state;
|
|
66
|
+
const plain = FaceClips.kind(phase, !!paused);
|
|
67
|
+
if (plain === 'listening') {
|
|
68
|
+
// What she said she would do, once she said it; then it plays to its end, unless Ta thinks or speaks.
|
|
69
|
+
if (coming) {
|
|
70
|
+
return coming;
|
|
71
|
+
}
|
|
72
|
+
return FaceClips.isShow(kind) && !moodDone ? kind : plain;
|
|
73
|
+
}
|
|
74
|
+
if (plain !== 'speaking') {
|
|
75
|
+
return plain;
|
|
76
|
+
}
|
|
77
|
+
const said = words();
|
|
78
|
+
const mood = FaceClips.mood(said);
|
|
79
|
+
return mood && (moodFor !== said || (kind === mood && !moodDone)) ? mood : 'speaking';
|
|
80
|
+
};
|
|
81
|
+
/** Plays `clip` in the layer behind from `at` seconds, which comes in front once it plays. */
|
|
82
|
+
const show = (clip, at = 0) => {
|
|
83
|
+
const back = 1 - shown;
|
|
84
|
+
const video = videos[back];
|
|
85
|
+
last = clip;
|
|
86
|
+
names[back] = clip;
|
|
87
|
+
loading = clip;
|
|
88
|
+
video.dataset.clip = clip;
|
|
89
|
+
const src = faces.clip(clip);
|
|
90
|
+
if (video.src !== src) {
|
|
91
|
+
video.src = src;
|
|
92
|
+
}
|
|
93
|
+
video.currentTime = at;
|
|
94
|
+
video.playbackRate = 1;
|
|
95
|
+
void video.play().then(() => {
|
|
96
|
+
if (names[back] !== clip || gone) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
loading = undefined;
|
|
100
|
+
shown = back;
|
|
101
|
+
setFront(back);
|
|
102
|
+
videos[1 - back].pause();
|
|
103
|
+
if (!ready) {
|
|
104
|
+
ready = true;
|
|
105
|
+
onReady();
|
|
106
|
+
}
|
|
107
|
+
}, () => {
|
|
108
|
+
// Another clip took the layer meanwhile (its load stopped this one): not a failure.
|
|
109
|
+
if (names[back] !== clip || gone) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
loading = undefined;
|
|
113
|
+
if (!ready) {
|
|
114
|
+
onFailed();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
const play = (next) => {
|
|
119
|
+
if (next !== kind && (FaceClips.isMood(next) || FaceClips.isShow(next))) {
|
|
120
|
+
moodFor = words();
|
|
121
|
+
moodDone = false;
|
|
122
|
+
}
|
|
123
|
+
if (next === coming) {
|
|
124
|
+
coming = undefined;
|
|
125
|
+
}
|
|
126
|
+
kind = next;
|
|
127
|
+
show(FaceClips.next(next, last));
|
|
128
|
+
};
|
|
129
|
+
// The plans of the readings, by their say: which clip shows at each moment of their sound.
|
|
130
|
+
const plans = new Map();
|
|
131
|
+
const planOf = (say) => {
|
|
132
|
+
let plan = plans.get(say);
|
|
133
|
+
if (!plan) {
|
|
134
|
+
const used = new Set();
|
|
135
|
+
plan = new ClipPlan(frames, (seconds, before) => {
|
|
136
|
+
const reading = call.sounds.nowReading();
|
|
137
|
+
return FaceClips.at((reading === null || reading === void 0 ? void 0 : reading.say) === say ? reading : undefined, seconds, before !== null && before !== void 0 ? before : last, used);
|
|
138
|
+
});
|
|
139
|
+
plans.set(say, plan);
|
|
140
|
+
for (const old of plans.keys()) {
|
|
141
|
+
if (old < say - 1) {
|
|
142
|
+
plans.delete(old);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return plan;
|
|
147
|
+
};
|
|
148
|
+
/** The reading that drives the face now: one of a voice service, playing, while Ta speaks. */
|
|
149
|
+
const driving = () => {
|
|
150
|
+
const reading = call.sounds.nowReading();
|
|
151
|
+
return reading && !call.state.paused && call.state.phase === 'speaking' && reading.now() >= 0 ? reading : undefined;
|
|
152
|
+
};
|
|
153
|
+
const ended = (event) => {
|
|
154
|
+
if (event.target !== videos[shown]) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (FaceClips.isMood(kind) || FaceClips.isShow(kind)) {
|
|
158
|
+
moodDone = true;
|
|
159
|
+
}
|
|
160
|
+
if (!driving()) {
|
|
161
|
+
play(wanted());
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* She stood up to dance or stretch and the call goes on (the user speaks, Ta thinks or answers): she hurries
|
|
166
|
+
* back to the sofa, its end, rather than the clip cutting away; true while she does.
|
|
167
|
+
*/
|
|
168
|
+
const hurrying = () => {
|
|
169
|
+
const video = videos[shown];
|
|
170
|
+
if (!FaceClips.isShow(kind) || moodDone || names[shown] !== kind || video.ended) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
if (call.state.phase !== 'listening' || call.state.heard.trim()) {
|
|
174
|
+
video.playbackRate = HURRY_RATE;
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
};
|
|
178
|
+
const failed = () => !ready && onFailed();
|
|
179
|
+
for (const video of videos) {
|
|
180
|
+
video.addEventListener('ended', ended);
|
|
181
|
+
video.addEventListener('error', failed);
|
|
182
|
+
}
|
|
183
|
+
// The clips as they are now, not as a cache kept them from a Ta before (faces/README.md); then the face moves.
|
|
184
|
+
void faces.ready.then(() => !gone && play(wanted()));
|
|
185
|
+
const timer = setInterval(() => {
|
|
186
|
+
const said = call.state.phase === 'speaking' ? words() : undefined;
|
|
187
|
+
const then = FaceClips.show(said);
|
|
188
|
+
if (then && said !== comingFor) {
|
|
189
|
+
comingFor = said;
|
|
190
|
+
coming = then;
|
|
191
|
+
}
|
|
192
|
+
if (!faces.loaded || hurrying() || driving()) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const next = wanted();
|
|
196
|
+
if (next !== kind) {
|
|
197
|
+
play(next);
|
|
198
|
+
}
|
|
199
|
+
// Paused (the page hidden), it holds still; it moves again as the call does.
|
|
200
|
+
const now = videos[shown];
|
|
201
|
+
if (call.state.paused && !now.paused) {
|
|
202
|
+
now.pause();
|
|
203
|
+
}
|
|
204
|
+
else if (!call.state.paused && now.paused && ready && names[shown]) {
|
|
205
|
+
void now.play().catch(() => undefined);
|
|
206
|
+
}
|
|
207
|
+
}, TICK_MS);
|
|
208
|
+
const layer = new MouthLayer(call, planOf, canvas.current, view, faces, () => {
|
|
209
|
+
const reading = driving();
|
|
210
|
+
const clip = names[shown];
|
|
211
|
+
return reading && clip ? { reading, video: videos[shown], clip } : undefined;
|
|
212
|
+
});
|
|
213
|
+
void layer.open(mouth.current);
|
|
214
|
+
layer.watch(videos);
|
|
215
|
+
// Each frame: the clip of the moment of the sound, kept on its clock, and the mouth drawn for it.
|
|
216
|
+
let held;
|
|
217
|
+
let heldAt = 0;
|
|
218
|
+
let frame = view.requestAnimationFrame(function tick() {
|
|
219
|
+
if (gone) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
frame = view.requestAnimationFrame(tick);
|
|
223
|
+
const reading = driving();
|
|
224
|
+
if (!reading) {
|
|
225
|
+
layer.clear();
|
|
226
|
+
held = undefined;
|
|
227
|
+
if (!hurrying()) {
|
|
228
|
+
for (const video of videos) {
|
|
229
|
+
video.playbackRate = 1;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (!faces.loaded) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const seconds = reading.now();
|
|
238
|
+
if (hurrying()) {
|
|
239
|
+
layer.follow(reading, seconds);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const at = planOf(reading.say).at(seconds);
|
|
243
|
+
const video = videos[shown];
|
|
244
|
+
if (names[shown] !== at.clip) {
|
|
245
|
+
if (loading !== at.clip) {
|
|
246
|
+
kind = 'speaking';
|
|
247
|
+
show(at.clip, at.frame / CLIP_FPS);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
// The sound stopped short (what comes next is late): she holds still until it goes on.
|
|
252
|
+
const time = view.performance.now();
|
|
253
|
+
if (seconds !== held) {
|
|
254
|
+
held = seconds;
|
|
255
|
+
heldAt = time;
|
|
256
|
+
}
|
|
257
|
+
const still = time - heldAt > STILL_MS;
|
|
258
|
+
if (still !== video.paused) {
|
|
259
|
+
void (still ? video.pause() : video.play().catch(() => undefined));
|
|
260
|
+
}
|
|
261
|
+
const sync = ClipSync.step(at.frame / CLIP_FPS, video.currentTime);
|
|
262
|
+
if (sync.seek !== undefined) {
|
|
263
|
+
video.currentTime = sync.seek;
|
|
264
|
+
}
|
|
265
|
+
video.playbackRate = sync.rate;
|
|
266
|
+
}
|
|
267
|
+
layer.follow(reading, seconds);
|
|
268
|
+
});
|
|
269
|
+
return () => {
|
|
270
|
+
gone = true;
|
|
271
|
+
view.cancelAnimationFrame(frame);
|
|
272
|
+
layer.close();
|
|
273
|
+
clearInterval(timer);
|
|
274
|
+
for (const video of videos) {
|
|
275
|
+
video.removeEventListener('ended', ended);
|
|
276
|
+
video.removeEventListener('error', failed);
|
|
277
|
+
video.pause();
|
|
278
|
+
video.removeAttribute('src');
|
|
279
|
+
video.load();
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}, [call]);
|
|
283
|
+
const poster = FaceFiles.poster((_b = (_a = box.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) !== null && _b !== void 0 ? _b : document);
|
|
284
|
+
return (React.createElement("div", { ref: box, className: "ta-video-clips" },
|
|
285
|
+
layers.map((layer, index) => (React.createElement("video", {
|
|
286
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: two fixed layers
|
|
287
|
+
key: index, ref: layer, className: `ta-video-clip${front === index ? ' ta-front' : ''}`, poster: poster, muted: true, playsInline: true, preload: "auto", disablePictureInPicture: true }))),
|
|
288
|
+
React.createElement("canvas", { ref: canvas, className: "ta-video-mouth" })));
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The mouth an extension draws for what Ta reads (WebCallMouth), laid over the clip: told the sound of each reading as
|
|
292
|
+
* it comes with the frame of the clip at each moment of it (ClipPlan), it gives that frame's lower face drawn again
|
|
293
|
+
* for that sound. As each frame of the clip is shown (requestVideoFrameCallback), that frame and the mouth of that
|
|
294
|
+
* moment of the sound are drawn together, the mouth moved with her face when it was drawn for a frame near it: the
|
|
295
|
+
* clip and the sound keep their own clocks a little apart. The reading waits for it as long as it asks (holdMs).
|
|
296
|
+
*/
|
|
297
|
+
class MouthLayer {
|
|
298
|
+
constructor(call, planOf, canvas, view, faces, showing) {
|
|
299
|
+
this.call = call;
|
|
300
|
+
this.planOf = planOf;
|
|
301
|
+
this.canvas = canvas;
|
|
302
|
+
this.view = view;
|
|
303
|
+
this.faces = faces;
|
|
304
|
+
this.showing = showing;
|
|
305
|
+
this.closed = false;
|
|
306
|
+
/** Of each reading: the seconds of its sound that came, and the slots told. */
|
|
307
|
+
this.sounds = new Map();
|
|
308
|
+
this.atSlot = -1;
|
|
309
|
+
/** The canvas shows the frames of the clip now, not the layers of video under it. */
|
|
310
|
+
this.drawing = false;
|
|
311
|
+
}
|
|
312
|
+
async open(mouth) {
|
|
313
|
+
var _a;
|
|
314
|
+
const session = await (mouth === null || mouth === void 0 ? void 0 : mouth.open().catch(() => undefined));
|
|
315
|
+
if (!session) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (this.closed) {
|
|
319
|
+
session.close();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
this.session = session;
|
|
323
|
+
this.missed = (_a = this.call.sounds.nowReading()) === null || _a === void 0 ? void 0 : _a.say;
|
|
324
|
+
this.call.sounds.hold(session.holdMs);
|
|
325
|
+
this.offSound = this.call.sounds.on((say, pcm, rate) => this.sound(say, pcm, rate));
|
|
326
|
+
}
|
|
327
|
+
sound(say, pcm, rate) {
|
|
328
|
+
var _a;
|
|
329
|
+
var _b, _c;
|
|
330
|
+
const session = this.session;
|
|
331
|
+
if (!session || say === this.missed) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (!this.sounds.has(say)) {
|
|
335
|
+
// A reading begins: it waits as long as the mouth asks, more while the mouth starts.
|
|
336
|
+
this.call.sounds.hold(session.holdMs + Math.min(STARTING_MS, (_b = (_a = session.readyIn) === null || _a === void 0 ? void 0 : _a.call(session)) !== null && _b !== void 0 ? _b : 0));
|
|
337
|
+
}
|
|
338
|
+
const heard = (_c = this.sounds.get(say)) !== null && _c !== void 0 ? _c : { seconds: 0, told: 0 };
|
|
339
|
+
this.sounds.set(say, heard);
|
|
340
|
+
for (const old of this.sounds.keys()) {
|
|
341
|
+
if (old < say - 1) {
|
|
342
|
+
this.sounds.delete(old);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (pcm) {
|
|
346
|
+
heard.seconds += pcm.byteLength / 2 / rate;
|
|
347
|
+
}
|
|
348
|
+
const upto = pcm ? Math.floor(heard.seconds * session.fps) : Math.ceil(heard.seconds * session.fps);
|
|
349
|
+
const plan = this.planOf(say);
|
|
350
|
+
const slots = [];
|
|
351
|
+
for (let slot = heard.told; slot < upto; slot++) {
|
|
352
|
+
const { clip, frame } = plan.at(slot / session.fps);
|
|
353
|
+
slots.push([clip, frame]);
|
|
354
|
+
}
|
|
355
|
+
const first = heard.told;
|
|
356
|
+
heard.told = Math.max(heard.told, upto);
|
|
357
|
+
session.sound(say, pcm, rate, slots, first);
|
|
358
|
+
}
|
|
359
|
+
/** The reading plays at `seconds` of its sound: the extension knows what it need not draw any more. */
|
|
360
|
+
follow(reading, seconds) {
|
|
361
|
+
const session = this.session;
|
|
362
|
+
if (!session) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (this.say !== undefined && this.say !== reading.say) {
|
|
366
|
+
session.cut(this.say);
|
|
367
|
+
}
|
|
368
|
+
this.say = reading.say;
|
|
369
|
+
const slot = Math.floor(seconds * session.fps);
|
|
370
|
+
if (slot !== this.atSlot) {
|
|
371
|
+
this.atSlot = slot;
|
|
372
|
+
session.at(reading.say, slot);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/** Draws as each frame of the layers of video is shown, the one in front. */
|
|
376
|
+
watch(videos) {
|
|
377
|
+
const offs = videos.map(video => {
|
|
378
|
+
if (typeof video.requestVideoFrameCallback !== 'function') {
|
|
379
|
+
return () => undefined;
|
|
380
|
+
}
|
|
381
|
+
const shown = (_now, frame) => {
|
|
382
|
+
handle = video.requestVideoFrameCallback(shown);
|
|
383
|
+
this.shown(video, frame.mediaTime);
|
|
384
|
+
};
|
|
385
|
+
let handle = video.requestVideoFrameCallback(shown);
|
|
386
|
+
return () => video.cancelVideoFrameCallback(handle);
|
|
387
|
+
});
|
|
388
|
+
this.offFrames = () => {
|
|
389
|
+
for (const off of offs) {
|
|
390
|
+
off();
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/** A frame of `video` is shown, `mediaTime` into its clip: it is drawn, with the mouth of the moment over it. */
|
|
395
|
+
shown(video, mediaTime) {
|
|
396
|
+
var _a, _b, _c;
|
|
397
|
+
const session = this.session;
|
|
398
|
+
const canvas = this.canvas;
|
|
399
|
+
const now = this.showing();
|
|
400
|
+
if (!session || !canvas || !now || now.video !== video || !video.videoWidth) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const context = this.fit(canvas);
|
|
404
|
+
if (!context) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const width = canvas.width;
|
|
408
|
+
const height = canvas.height;
|
|
409
|
+
const scale = Math.max(width / video.videoWidth, height / video.videoHeight);
|
|
410
|
+
const left = (width - video.videoWidth * scale) * 0.5;
|
|
411
|
+
const top = (height - video.videoHeight * scale) * 0.3;
|
|
412
|
+
context.drawImage(video, left, top, video.videoWidth * scale, video.videoHeight * scale);
|
|
413
|
+
this.drawing = true;
|
|
414
|
+
const shownFrame = Math.round(mediaTime * CLIP_FPS);
|
|
415
|
+
const drawn = this.nearest(session, now.reading.say, Math.floor(now.reading.now() * session.fps), now.clip, shownFrame);
|
|
416
|
+
const at = this.place(drawn, now.clip, shownFrame);
|
|
417
|
+
if (drawn && at) {
|
|
418
|
+
context.drawImage(drawn.image, left + at[0] * scale, top + at[1] * scale, at[2] * scale, at[3] * scale);
|
|
419
|
+
}
|
|
420
|
+
// How many frames showed while Ta read, and how many with her mouth: read by checks of the call (and by anyone curious).
|
|
421
|
+
canvas.dataset.frames = String(Number((_a = canvas.dataset.frames) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
422
|
+
canvas.dataset.mouths = String(Number((_b = canvas.dataset.mouths) !== null && _b !== void 0 ? _b : 0) + (drawn && at ? 1 : 0));
|
|
423
|
+
if (drawn && at) {
|
|
424
|
+
canvas.dataset.apart = String(Number((_c = canvas.dataset.apart) !== null && _c !== void 0 ? _c : 0) + Math.abs(drawn.frame - shownFrame));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* The mouth of the moment of the sound, or of the slot just before or after it if that one was drawn for a frame
|
|
429
|
+
* nearer the one shown (the frame comes to the screen a little after its moment): a mouth a slot early or late is
|
|
430
|
+
* not seen, one laid over a frame it was not drawn for is.
|
|
431
|
+
*/
|
|
432
|
+
nearest(session, say, slot, clip, frame) {
|
|
433
|
+
let best;
|
|
434
|
+
for (const near of [slot, slot - 1, slot + 1]) {
|
|
435
|
+
const drawn = session.frame(say, near);
|
|
436
|
+
if ((drawn === null || drawn === void 0 ? void 0 : drawn.clip) === clip && (!best || Math.abs(drawn.frame - frame) < Math.abs(best.frame - frame))) {
|
|
437
|
+
best = drawn;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return best !== null && best !== void 0 ? best : session.frame(say, slot);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Where the mouth drawn goes over `frame` of `clip`: its place in the frame it was drawn for, moved and scaled as her
|
|
444
|
+
* face is from that frame to this one; undefined when it is of another clip, or of a frame too far.
|
|
445
|
+
*/
|
|
446
|
+
place(drawn, clip, frame) {
|
|
447
|
+
if (!drawn || drawn.clip !== clip || Math.abs(drawn.frame - frame) > NEAR_FRAMES) {
|
|
448
|
+
return undefined;
|
|
449
|
+
}
|
|
450
|
+
const boxes = this.faces.boxes(clip);
|
|
451
|
+
const from = boxes === null || boxes === void 0 ? void 0 : boxes[drawn.frame];
|
|
452
|
+
const to = boxes === null || boxes === void 0 ? void 0 : boxes[Math.min(frame, boxes.length - 1)];
|
|
453
|
+
const [x, y, w, h] = drawn.box;
|
|
454
|
+
if (!from || !to || drawn.frame === frame) {
|
|
455
|
+
return [x, y, w, h];
|
|
456
|
+
}
|
|
457
|
+
const sx = (to[2] - to[0]) / Math.max(1, from[2] - from[0]);
|
|
458
|
+
const sy = (to[3] - to[1]) / Math.max(1, from[3] - from[1]);
|
|
459
|
+
return [to[0] + (x - from[0]) * sx, to[1] + (y - from[1]) * sy, w * sx, h * sy];
|
|
460
|
+
}
|
|
461
|
+
/** Nothing over the clip: Ta is not reading with its voice service now. */
|
|
462
|
+
clear() {
|
|
463
|
+
var _a;
|
|
464
|
+
if (this.say !== undefined) {
|
|
465
|
+
(_a = this.session) === null || _a === void 0 ? void 0 : _a.cut(this.say);
|
|
466
|
+
this.say = undefined;
|
|
467
|
+
this.atSlot = -1;
|
|
468
|
+
}
|
|
469
|
+
if (this.drawing && this.canvas) {
|
|
470
|
+
this.drawing = false;
|
|
471
|
+
this.fit(this.canvas);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
/** The canvas the size it shows at, cleared. */
|
|
475
|
+
fit(canvas) {
|
|
476
|
+
const ratio = Math.min(2, this.view.devicePixelRatio || 1);
|
|
477
|
+
const width = Math.round(canvas.clientWidth * ratio);
|
|
478
|
+
const height = Math.round(canvas.clientHeight * ratio);
|
|
479
|
+
if (canvas.width !== width || canvas.height !== height) {
|
|
480
|
+
canvas.width = width;
|
|
481
|
+
canvas.height = height;
|
|
482
|
+
}
|
|
483
|
+
const context = canvas.getContext('2d');
|
|
484
|
+
context === null || context === void 0 ? void 0 : context.clearRect(0, 0, width, height);
|
|
485
|
+
return context;
|
|
486
|
+
}
|
|
487
|
+
close() {
|
|
488
|
+
var _a, _b, _c;
|
|
489
|
+
this.closed = true;
|
|
490
|
+
(_a = this.offSound) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
491
|
+
(_b = this.offFrames) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
492
|
+
(_c = this.session) === null || _c === void 0 ? void 0 : _c.close();
|
|
493
|
+
this.session = undefined;
|
|
494
|
+
this.call.sounds.hold(0);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
//# sourceMappingURL=video-face.js.map
|
|
@@ -41,6 +41,7 @@ export declare abstract class WorkbenchHosts extends WorkbenchLists {
|
|
|
41
41
|
protected abstract open(credential: Credential): {
|
|
42
42
|
connection: TaConnection;
|
|
43
43
|
refused(): Promise<boolean>;
|
|
44
|
+
direct?(server: TaServerInfo): void;
|
|
44
45
|
};
|
|
45
46
|
abstract signOut(): void;
|
|
46
47
|
}
|
|
@@ -88,6 +88,8 @@ export interface WorkbenchPages {
|
|
|
88
88
|
readonly agent: boolean;
|
|
89
89
|
/** Answers `kind` (`<package>/<kind>`, `ta/<kind>`) from now on; the function returned stops. */
|
|
90
90
|
answer(kind: string, handler: (payload: unknown) => unknown): () => void;
|
|
91
|
+
/** The device the page runs on, as it lays itself out (setDevice). */
|
|
92
|
+
readonly device: 'phone' | 'tablet' | 'computer';
|
|
91
93
|
setDevice(device: 'phone' | 'tablet' | 'computer'): void;
|
|
92
94
|
}
|
|
93
95
|
export interface TaWorkbench {
|
|
@@ -60,6 +60,11 @@ export declare namespace WorkbenchUtil {
|
|
|
60
60
|
function reachable(base: string, fetcher?: typeof fetch): Promise<boolean>;
|
|
61
61
|
/** The hosts kept in `storage`; the token or pairing an older version kept becomes the first. */
|
|
62
62
|
function readHosts(storage: Storage | undefined, now?: number): HostList;
|
|
63
|
+
/**
|
|
64
|
+
* A pairing with the ways to its computer that computer told (TaServerInfo.relays), the same credential when they did not
|
|
65
|
+
* change or it told none (a ta serve of before), or it is no pairing.
|
|
66
|
+
*/
|
|
67
|
+
function routed(credential: Credential, relays: readonly string[] | undefined): Credential;
|
|
63
68
|
/** Which ta serve a credential reaches, to know whose lists were kept: that of the page (`host`) for a token alone. */
|
|
64
69
|
function serverOf(credential: Credential, host: string): string;
|
|
65
70
|
/** Where the ta serve of a token answers: its own address, or that of the page. */
|
|
@@ -131,6 +131,24 @@ export var WorkbenchUtil;
|
|
|
131
131
|
return credential ? HostUtil.use({ hosts: [] }, serverOf(credential, pageHost()), credential, now) : { hosts: [] };
|
|
132
132
|
}
|
|
133
133
|
WorkbenchUtil.readHosts = readHosts;
|
|
134
|
+
/**
|
|
135
|
+
* A pairing with the ways to its computer that computer told (TaServerInfo.relays), the same credential when they did not
|
|
136
|
+
* change or it told none (a ta serve of before), or it is no pairing.
|
|
137
|
+
*/
|
|
138
|
+
function routed(credential, relays) {
|
|
139
|
+
if (!('pairing' in credential) || !Array.isArray(relays)) {
|
|
140
|
+
return credential;
|
|
141
|
+
}
|
|
142
|
+
const told = RelayPairingUtil.routes(relays);
|
|
143
|
+
const before = RelayPairingUtil.routes(credential.pairing.relays);
|
|
144
|
+
if (told.join(' ') === before.join(' ')) {
|
|
145
|
+
return credential;
|
|
146
|
+
}
|
|
147
|
+
const { relays: _before, ...pairing } = credential.pairing;
|
|
148
|
+
// Its own relay alone is what a pairing without ways does.
|
|
149
|
+
return { pairing: told.length && told.join(' ') !== pairing.relay ? { ...pairing, relays: told } : pairing };
|
|
150
|
+
}
|
|
151
|
+
WorkbenchUtil.routed = routed;
|
|
134
152
|
/** Which ta serve a credential reaches, to know whose lists were kept: that of the page (`host`) for a token alone. */
|
|
135
153
|
function serverOf(credential, host) {
|
|
136
154
|
if ('pairing' in credential) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TaConnection } from '@celljs/ta-client';
|
|
2
|
+
import { type TaServerInfo } from '@celljs/ta-protocol';
|
|
2
3
|
import { PresenceReporter } from './presence/presence-reporter.js';
|
|
3
4
|
import { PageAnswers } from './screen/page-answers.js';
|
|
4
5
|
import { WorkbenchCalls } from './workbench-calls.js';
|
|
@@ -12,6 +13,10 @@ export declare class TaWorkbenchImpl extends WorkbenchHosts implements TaWorkben
|
|
|
12
13
|
/** What ta serve may ask this page, and what it is told of the page (docs/design/ta-app-use.md 4.1). */
|
|
13
14
|
readonly pages: PageAnswers;
|
|
14
15
|
protected retryTimer?: ReturnType<typeof setTimeout>;
|
|
16
|
+
/** By computer, what it said a direct connection to it takes (TaServerInfo.direct), for the connections of later. */
|
|
17
|
+
protected readonly directs: Map<string, {
|
|
18
|
+
stun: string[];
|
|
19
|
+
}>;
|
|
15
20
|
/** A restart asked for: whether a build was installed over the one running, and whether its connection closed yet. */
|
|
16
21
|
protected restart?: {
|
|
17
22
|
update: boolean;
|
|
@@ -59,6 +64,7 @@ export declare class TaWorkbenchImpl extends WorkbenchHosts implements TaWorkben
|
|
|
59
64
|
protected open(credential: Credential): {
|
|
60
65
|
connection: TaConnection;
|
|
61
66
|
refused(): Promise<boolean>;
|
|
67
|
+
direct?(server: TaServerInfo): void;
|
|
62
68
|
};
|
|
63
69
|
/**
|
|
64
70
|
* Back to the sign-in, loaded again: what the page holds of the computer (the double's and the open
|
package/esm/browser/workbench.js
CHANGED
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Component } from '@celljs/core';
|
|
8
8
|
import { TaConnection } from '@celljs/ta-client';
|
|
9
9
|
import { TaErrorCode, TaRoomWatchUtil } from '@celljs/ta-protocol';
|
|
10
|
-
import {
|
|
10
|
+
import { RelayRouteSocket } from '@celljs/ta-relay';
|
|
11
11
|
import { HostUtil } from './hosts.js';
|
|
12
12
|
import { PresenceReporter } from './presence/presence-reporter.js';
|
|
13
13
|
import { PageAnswers } from './screen/page-answers.js';
|
|
@@ -47,6 +47,8 @@ let TaWorkbenchImpl = class TaWorkbenchImpl extends WorkbenchHosts {
|
|
|
47
47
|
this.connection.pages.attach(info).catch(() => undefined);
|
|
48
48
|
}
|
|
49
49
|
}, { agent: ScreenUtil.agent(), desktop: typeof globalThis.taDesktop === 'object' });
|
|
50
|
+
/** By computer, what it said a direct connection to it takes (TaServerInfo.direct), for the connections of later. */
|
|
51
|
+
this.directs = new Map();
|
|
50
52
|
this.attempts = 0;
|
|
51
53
|
this.graceMs = GRACE_MS;
|
|
52
54
|
/**
|
|
@@ -193,7 +195,7 @@ let TaWorkbenchImpl = class TaWorkbenchImpl extends WorkbenchHosts {
|
|
|
193
195
|
/** Tries again later while ta serve is not running, until a sign-in or sign-out of later replaces it. */
|
|
194
196
|
async connect(credential) {
|
|
195
197
|
const generation = this.generation;
|
|
196
|
-
const { connection, refused } = this.open(credential);
|
|
198
|
+
const { connection, refused, direct } = this.open(credential);
|
|
197
199
|
try {
|
|
198
200
|
await connection.connect();
|
|
199
201
|
}
|
|
@@ -304,7 +306,10 @@ let TaWorkbenchImpl = class TaWorkbenchImpl extends WorkbenchHosts {
|
|
|
304
306
|
if (generation !== this.generation) {
|
|
305
307
|
return;
|
|
306
308
|
}
|
|
307
|
-
|
|
309
|
+
direct === null || direct === void 0 ? void 0 : direct(server);
|
|
310
|
+
// Through a relay, the ways to the computer it tells now are kept, tried in order the next time.
|
|
311
|
+
const kept = WorkbenchUtil.routed(credential, server.relays);
|
|
312
|
+
this.keepHosts(HostUtil.use(this.list, WorkbenchUtil.serverOf(credential, pageHost()), kept, Date.now(), { user: server.user, host: server.host }));
|
|
308
313
|
this.update({ status: 'online', error: undefined, retryAt: undefined, server });
|
|
309
314
|
this.presence.resend();
|
|
310
315
|
this.pages.tell();
|
|
@@ -314,13 +319,39 @@ let TaWorkbenchImpl = class TaWorkbenchImpl extends WorkbenchHosts {
|
|
|
314
319
|
open(credential) {
|
|
315
320
|
if ('pairing' in credential) {
|
|
316
321
|
let socket;
|
|
322
|
+
const id = WorkbenchUtil.serverOf(credential, pageHost());
|
|
317
323
|
const connection = new TaConnection({
|
|
318
324
|
url: credential.pairing.relay,
|
|
319
325
|
token: '',
|
|
320
|
-
createSocket: () =>
|
|
326
|
+
createSocket: () => {
|
|
327
|
+
var _a;
|
|
328
|
+
// By the first of the ways to the computer that opens (docs/design/ta-relays.md 12), held at the relays
|
|
329
|
+
// while it is away (Ta restarting, the computer waking): open the moment it is back.
|
|
330
|
+
const saved = (_a = this.list.hosts.find(one => one.id === id)) === null || _a === void 0 ? void 0 : _a.credential;
|
|
331
|
+
// Once in, directly to the computer when it said it can (docs/design/ta-relays.md 12.5): known from the last time.
|
|
332
|
+
socket = new RelayRouteSocket(saved && 'pairing' in saved ? saved.pairing : credential.pairing, {
|
|
333
|
+
wait: true,
|
|
334
|
+
direct: () => this.directs.get(id),
|
|
335
|
+
});
|
|
336
|
+
socket.onwait = () => this.current.status === 'connecting' && this.update({ status: 'offline', error: 'away', retryAt: undefined });
|
|
337
|
+
return socket;
|
|
338
|
+
},
|
|
321
339
|
});
|
|
322
340
|
// Through a relay, the host says so when it refuses.
|
|
323
|
-
return {
|
|
341
|
+
return {
|
|
342
|
+
connection,
|
|
343
|
+
refused: async () => (socket === null || socket === void 0 ? void 0 : socket.closeCode) === RelayRouteSocket.REFUSED,
|
|
344
|
+
direct: server => {
|
|
345
|
+
// What the computer says now, for the connections of later; the first one tries it at once.
|
|
346
|
+
if (server.direct) {
|
|
347
|
+
this.directs.set(id, server.direct);
|
|
348
|
+
socket === null || socket === void 0 ? void 0 : socket.direct(server.direct);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
this.directs.delete(id);
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
};
|
|
324
355
|
}
|
|
325
356
|
const serve = WorkbenchUtil.serveUrl(credential);
|
|
326
357
|
const connection = new TaConnection({ url: WorkbenchUtil.socketUrl(serve), token: credential.token });
|