@celljs/ta-web 4.39.0 → 4.41.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/chat/chat-shown.js +2 -2
- package/esm/browser/components/busy.d.ts +5 -0
- package/esm/browser/components/busy.js +17 -0
- package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/extension/icons.js +15 -1
- package/esm/browser/extension/web-api-hosts.d.ts +22 -0
- package/esm/browser/extension/web-api-hosts.js +2 -0
- package/esm/browser/extension/web-api-play.d.ts +9 -1
- package/esm/browser/extension/web-api-spec.js +3 -0
- package/esm/browser/extension/web-extension-api.d.ts +7 -0
- package/esm/browser/extension/web-extension-context.js +6 -3
- package/esm/browser/extension/web-file-drag.d.ts +3 -0
- package/esm/browser/extension/web-file-drag.js +4 -0
- package/esm/browser/extension/web-hosts.d.ts +7 -0
- package/esm/browser/extension/web-hosts.js +29 -0
- package/esm/browser/hosts.d.ts +2 -0
- package/esm/browser/hosts.js +9 -0
- package/esm/browser/i18n/en/chat.d.ts +1 -0
- package/esm/browser/i18n/en/chat.js +1 -0
- package/esm/browser/i18n/ja/chat.js +1 -0
- package/esm/browser/i18n/locales.d.ts +2 -1
- package/esm/browser/i18n/messages.d.ts +1 -0
- package/esm/browser/i18n/zh/chat.js +1 -0
- package/esm/browser/i18n/zh-tw/chat.js +1 -0
- package/esm/browser/sandbox/sandbox-runtime-code.js +1 -1
- package/esm/browser/sandbox/work/work-api.d.ts +9 -0
- package/esm/browser/sandbox/work/work-api.js +4 -8
- package/esm/browser/sandbox/work/work-docs.js +26 -2
- package/esm/browser/sandbox/work/work-frame.d.ts +22 -2
- package/esm/browser/sandbox/work/work-frame.js +60 -9
- package/esm/browser/sandbox/work/work-senses.d.ts +100 -0
- package/esm/browser/sandbox/work/work-senses.js +352 -0
- package/esm/browser/share/shared-extensions.js +13 -1
- package/esm/browser/share/shared-link.d.ts +3 -1
- package/esm/browser/share/shared-link.js +17 -1
- package/esm/browser/share/shared-page.js +27 -3
- package/esm/browser/style/conversation.d.ts +1 -1
- package/esm/browser/style/conversation.js +2 -2
- package/esm/browser/style/shared.d.ts +1 -1
- package/esm/browser/style/shared.js +3 -0
- package/esm/browser/workbench-hosts.d.ts +1 -0
- package/esm/browser/workbench-hosts.js +9 -0
- package/esm/browser/workbench-protocol.d.ts +5 -0
- package/lib/browser/chat/chat-shown.js +2 -2
- package/lib/browser/components/busy.d.ts +5 -0
- package/lib/browser/components/busy.js +17 -0
- package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/extension/icons.js +14 -0
- package/lib/browser/extension/web-api-hosts.d.ts +23 -0
- package/lib/browser/extension/web-api-hosts.js +3 -0
- package/lib/browser/extension/web-api-play.d.ts +9 -1
- package/lib/browser/extension/web-api-spec.js +3 -0
- package/lib/browser/extension/web-extension-api.d.ts +7 -0
- package/lib/browser/extension/web-extension-context.js +6 -3
- package/lib/browser/extension/web-file-drag.d.ts +4 -0
- package/lib/browser/extension/web-file-drag.js +7 -0
- package/lib/browser/extension/web-hosts.d.ts +8 -0
- package/lib/browser/extension/web-hosts.js +32 -0
- package/lib/browser/hosts.d.ts +2 -0
- package/lib/browser/hosts.js +9 -0
- package/lib/browser/i18n/en/chat.d.ts +1 -0
- package/lib/browser/i18n/en/chat.js +1 -0
- package/lib/browser/i18n/ja/chat.js +1 -0
- package/lib/browser/i18n/locales.d.ts +2 -1
- package/lib/browser/i18n/messages.d.ts +1 -0
- package/lib/browser/i18n/zh/chat.js +1 -0
- package/lib/browser/i18n/zh-tw/chat.js +1 -0
- package/lib/browser/sandbox/sandbox-runtime-code.js +1 -1
- package/lib/browser/sandbox/work/work-api.d.ts +9 -0
- package/lib/browser/sandbox/work/work-api.js +4 -8
- package/lib/browser/sandbox/work/work-docs.js +26 -2
- package/lib/browser/sandbox/work/work-frame.d.ts +22 -2
- package/lib/browser/sandbox/work/work-frame.js +60 -9
- package/lib/browser/sandbox/work/work-senses.d.ts +101 -0
- package/lib/browser/sandbox/work/work-senses.js +356 -0
- package/lib/browser/share/shared-extensions.js +13 -1
- package/lib/browser/share/shared-link.d.ts +3 -1
- package/lib/browser/share/shared-link.js +16 -0
- package/lib/browser/share/shared-page.js +27 -3
- package/lib/browser/style/conversation.d.ts +1 -1
- package/lib/browser/style/conversation.js +2 -2
- package/lib/browser/style/shared.d.ts +1 -1
- package/lib/browser/style/shared.js +3 -0
- package/lib/browser/workbench-hosts.d.ts +1 -0
- package/lib/browser/workbench-hosts.js +9 -0
- package/lib/browser/workbench-protocol.d.ts +5 -0
- package/package.json +7 -7
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { TA_WORK_SENSES, TaWorkSense } from '@celljs/ta-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* The signals of the devices (docs/design/ta-works.md 7.9), worked out from what they read: an angle, an acceleration,
|
|
4
|
+
* the spectrum of a sound, two small grey frames. What the microphone heard and the camera saw stays here.
|
|
5
|
+
*/
|
|
6
|
+
export var SenseMath;
|
|
7
|
+
(function (SenseMath) {
|
|
8
|
+
const clamp = (value, low = -1, high = 1) => Math.min(high, Math.max(low, Number.isFinite(value) ? value : 0));
|
|
9
|
+
const round = (value) => Math.round(value * 100) / 100;
|
|
10
|
+
/** Degrees of tilt that read as all the way. */
|
|
11
|
+
SenseMath.TILT_RANGE = 35;
|
|
12
|
+
/**
|
|
13
|
+
* Tilt of `deviceorientation`, {x, y} each -1 to 1: x to the right, y toward the user, from `neutral` (the beta it
|
|
14
|
+
* was held at as it started); the axes turned with the screen (`angle`, 0, 90, 180, 270).
|
|
15
|
+
*/
|
|
16
|
+
function tilt(beta, gamma, neutral, angle = 0) {
|
|
17
|
+
const forward = (beta - neutral) / SenseMath.TILT_RANGE;
|
|
18
|
+
const side = gamma / SenseMath.TILT_RANGE;
|
|
19
|
+
const turned = ((angle % 360) + 360) % 360;
|
|
20
|
+
const [x, y] = turned === 90 ? [forward, -side] : turned === 180 ? [-side, -forward] : turned === 270 ? [-forward, side] : [side, forward];
|
|
21
|
+
return { x: round(clamp(x)), y: round(clamp(y)) };
|
|
22
|
+
}
|
|
23
|
+
SenseMath.tilt = tilt;
|
|
24
|
+
/** The beta a phone is held at as it starts, taken as level: 0 (flat) to 70 (upright). */
|
|
25
|
+
function neutral(beta) {
|
|
26
|
+
return clamp(beta, 0, 70);
|
|
27
|
+
}
|
|
28
|
+
SenseMath.neutral = neutral;
|
|
29
|
+
/** m/s² of acceleration (gravity left out) that is a shake. */
|
|
30
|
+
SenseMath.SHAKE = 14;
|
|
31
|
+
/** How hard a shake was, 0 to 1 (0: none), of `devicemotion`'s acceleration. */
|
|
32
|
+
function shake(x, y, z) {
|
|
33
|
+
const force = Math.hypot(x || 0, y || 0, z || 0);
|
|
34
|
+
return force < SenseMath.SHAKE ? 0 : round(clamp((force - SenseMath.SHAKE) / 16 + 0.3, 0, 1));
|
|
35
|
+
}
|
|
36
|
+
SenseMath.shake = shake;
|
|
37
|
+
/**
|
|
38
|
+
* How loud a sound is and how hard it is blown, each 0 to 1, of the bytes of an AnalyserNode's
|
|
39
|
+
* `getByteFrequencyData` (`binHz` apart). A blow is wind on the microphone: loud below 400 Hz, much more than above.
|
|
40
|
+
*/
|
|
41
|
+
function sound(bins, binHz) {
|
|
42
|
+
let low = 0;
|
|
43
|
+
let lows = 0;
|
|
44
|
+
let mid = 0;
|
|
45
|
+
let mids = 0;
|
|
46
|
+
for (let index = 1; index < bins.length && index * binHz <= 4000; index++) {
|
|
47
|
+
if (index * binHz < 400) {
|
|
48
|
+
low += bins[index];
|
|
49
|
+
lows++;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
mid += bins[index];
|
|
53
|
+
mids++;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const lowMean = lows ? low / lows : 0;
|
|
57
|
+
const midMean = mids ? mid / mids : 0;
|
|
58
|
+
const all = lows + mids ? (low + mid) / (lows + mids) : 0;
|
|
59
|
+
const loud = clamp((all - 40) / 110, 0, 1);
|
|
60
|
+
const blow = lowMean > 120 && lowMean > midMean * 1.4 ? clamp((lowMean - 110) / 100, 0, 1) : 0;
|
|
61
|
+
return { loud: round(loud), blow: round(blow) };
|
|
62
|
+
}
|
|
63
|
+
SenseMath.sound = sound;
|
|
64
|
+
/** How far apart two grey pixels must be to be something that moved. */
|
|
65
|
+
SenseMath.MOVED = 32;
|
|
66
|
+
/**
|
|
67
|
+
* What moved between two grey frames of the front camera (`width` by `height`, a byte a pixel): where, mirrored as a
|
|
68
|
+
* selfie is, {x, y} -1 to 1, and how much of the frame, 0 to 1.
|
|
69
|
+
*/
|
|
70
|
+
function move(before, now, width, height) {
|
|
71
|
+
let count = 0;
|
|
72
|
+
let sumX = 0;
|
|
73
|
+
let sumY = 0;
|
|
74
|
+
for (let y = 0; y < height; y++) {
|
|
75
|
+
for (let x = 0; x < width; x++) {
|
|
76
|
+
const index = y * width + x;
|
|
77
|
+
if (Math.abs(now[index] - before[index]) > SenseMath.MOVED) {
|
|
78
|
+
count++;
|
|
79
|
+
sumX += x;
|
|
80
|
+
sumY += y;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const amount = count / (width * height || 1);
|
|
85
|
+
if (amount < 0.01) {
|
|
86
|
+
return { x: 0, y: 0, amount: 0 };
|
|
87
|
+
}
|
|
88
|
+
const cx = sumX / count / Math.max(1, width - 1);
|
|
89
|
+
const cy = sumY / count / Math.max(1, height - 1);
|
|
90
|
+
return { x: round(clamp(1 - 2 * cx)), y: round(clamp(2 * cy - 1)), amount: round(clamp(amount * 3, 0, 1)) };
|
|
91
|
+
}
|
|
92
|
+
SenseMath.move = move;
|
|
93
|
+
})(SenseMath || (SenseMath = {}));
|
|
94
|
+
/** How many a second of a sense, the rest dropped; a value much the same as the last one waits for a while. */
|
|
95
|
+
class SenseGate {
|
|
96
|
+
constructor(perSecond) {
|
|
97
|
+
this.perSecond = perSecond;
|
|
98
|
+
this.last = 0;
|
|
99
|
+
}
|
|
100
|
+
allow(value, now) {
|
|
101
|
+
const text = JSON.stringify(value);
|
|
102
|
+
if (now - this.last < 1000 / this.perSecond || (text === this.sent && now - this.last < 500)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
this.last = now;
|
|
106
|
+
this.sent = text;
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** The devices of the browser the page runs in. */
|
|
111
|
+
export const BROWSER_SENSE_DEVICES = {
|
|
112
|
+
async motion() {
|
|
113
|
+
var _a;
|
|
114
|
+
if (typeof window === 'undefined' || !('DeviceOrientationEvent' in window)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
// A computer has the events and never fires them: only where fingers touch.
|
|
118
|
+
if (!((_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, '(pointer: coarse)').matches)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
const asks = [window.DeviceOrientationEvent, window.DeviceMotionEvent];
|
|
122
|
+
for (const ask of asks) {
|
|
123
|
+
if (typeof (ask === null || ask === void 0 ? void 0 : ask.requestPermission) === 'function' && (await ask.requestPermission().catch(() => 'denied')) !== 'granted') {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
},
|
|
129
|
+
media(device) {
|
|
130
|
+
const media = typeof navigator === 'undefined' ? undefined : navigator.mediaDevices;
|
|
131
|
+
if (!(media === null || media === void 0 ? void 0 : media.getUserMedia)) {
|
|
132
|
+
return Promise.reject(new Error('No microphone or camera here.'));
|
|
133
|
+
}
|
|
134
|
+
return media.getUserMedia(device === 'mic'
|
|
135
|
+
? { audio: { echoCancellation: false, noiseSuppression: false, autoGainControl: false } }
|
|
136
|
+
: { video: { facingMode: 'user', width: { ideal: 160 }, height: { ideal: 120 } } });
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* What a work senses where the page shows it (docs/design/ta-works.md 7.9): the page reads the devices and gives the
|
|
141
|
+
* work's frame signals alone (SenseMath), each as often as TA_WORK_SENSES says, none while the page is hidden.
|
|
142
|
+
* `request` asks the devices in a tap of the user (iOS lets motion be asked nowhere else), at once, before anything
|
|
143
|
+
* it waits for; asked again it adds. `stop` lets the microphone and the camera go. A sense whose device is not here,
|
|
144
|
+
* or not allowed, is not one of `names`: the frame draws a stand-in to touch in its place.
|
|
145
|
+
*/
|
|
146
|
+
export class WorkSenses {
|
|
147
|
+
constructor(devices = BROWSER_SENSE_DEVICES) {
|
|
148
|
+
this.devices = devices;
|
|
149
|
+
this.wanted = new Set();
|
|
150
|
+
this.asked = new Map();
|
|
151
|
+
this.ready = new Set();
|
|
152
|
+
this.streams = new Map();
|
|
153
|
+
this.stopped = false;
|
|
154
|
+
}
|
|
155
|
+
/** Asks the devices of these senses; resolves with the senses that work here. Call it in a tap of the user. */
|
|
156
|
+
request(names) {
|
|
157
|
+
const senses = TaWorkSense.of(names);
|
|
158
|
+
for (const name of senses) {
|
|
159
|
+
this.wanted.add(name);
|
|
160
|
+
}
|
|
161
|
+
const waits = TaWorkSense.devices(senses).map(device => {
|
|
162
|
+
let asking = this.asked.get(device);
|
|
163
|
+
if (!asking) {
|
|
164
|
+
asking = this.ask(device);
|
|
165
|
+
this.asked.set(device, asking);
|
|
166
|
+
}
|
|
167
|
+
return asking;
|
|
168
|
+
});
|
|
169
|
+
return Promise.all(waits).then(() => this.names);
|
|
170
|
+
}
|
|
171
|
+
/** The senses asked for whose device works here. */
|
|
172
|
+
get names() {
|
|
173
|
+
return TaWorkSense.NAMES.filter(name => this.wanted.has(name) && this.ready.has(TA_WORK_SENSES[name].device));
|
|
174
|
+
}
|
|
175
|
+
async ask(device) {
|
|
176
|
+
try {
|
|
177
|
+
if (device === 'motion') {
|
|
178
|
+
if (await this.devices.motion()) {
|
|
179
|
+
this.ready.add(device);
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const stream = await this.devices.media(device);
|
|
184
|
+
if (this.stopped) {
|
|
185
|
+
WorkSenses.release(stream);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.streams.set(device, stream);
|
|
189
|
+
this.ready.add(device);
|
|
190
|
+
}
|
|
191
|
+
catch (_a) {
|
|
192
|
+
// Not here, or not allowed: a stand-in instead.
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Reads the devices of the senses that work here, telling each signal; `missing` once a device said it was here and
|
|
197
|
+
* then gave nothing (its senses are no longer of `names`: stand-ins instead). Returns how to stop reading.
|
|
198
|
+
*/
|
|
199
|
+
listen(emit, missing, now = Date.now) {
|
|
200
|
+
const names = this.names;
|
|
201
|
+
const gates = new Map(names.map(name => [name, new SenseGate(TA_WORK_SENSES[name].perSecond)]));
|
|
202
|
+
const tell = (name, value) => {
|
|
203
|
+
var _a;
|
|
204
|
+
if ((_a = gates.get(name)) === null || _a === void 0 ? void 0 : _a.allow(value, now())) {
|
|
205
|
+
emit(name, value);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const stops = [];
|
|
209
|
+
if (this.ready.has('motion') && (gates.has('tilt') || gates.has('shake'))) {
|
|
210
|
+
stops.push(this.readMotion(tell, gates, () => {
|
|
211
|
+
this.ready.delete('motion');
|
|
212
|
+
missing === null || missing === void 0 ? void 0 : missing();
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
const mic = this.streams.get('mic');
|
|
216
|
+
if (mic && (gates.has('blow') || gates.has('loud'))) {
|
|
217
|
+
stops.push(this.readSound(mic, tell, gates));
|
|
218
|
+
}
|
|
219
|
+
const camera = this.streams.get('camera');
|
|
220
|
+
if (camera && gates.has('move')) {
|
|
221
|
+
stops.push(this.readCamera(camera, tell));
|
|
222
|
+
}
|
|
223
|
+
return () => {
|
|
224
|
+
for (const stop of stops) {
|
|
225
|
+
stop();
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
stop() {
|
|
230
|
+
this.stopped = true;
|
|
231
|
+
for (const stream of this.streams.values()) {
|
|
232
|
+
WorkSenses.release(stream);
|
|
233
|
+
}
|
|
234
|
+
this.streams.clear();
|
|
235
|
+
this.ready.delete('mic');
|
|
236
|
+
this.ready.delete('camera');
|
|
237
|
+
}
|
|
238
|
+
static release(stream) {
|
|
239
|
+
for (const track of stream.getTracks()) {
|
|
240
|
+
track.stop();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
static hidden() {
|
|
244
|
+
return typeof document !== 'undefined' && document.visibilityState === 'hidden';
|
|
245
|
+
}
|
|
246
|
+
readMotion(tell, gates, silent) {
|
|
247
|
+
let neutral;
|
|
248
|
+
let heard = false;
|
|
249
|
+
const quiet = setTimeout(() => !heard && !WorkSenses.hidden() && silent(), this.constructor.SILENT_MS);
|
|
250
|
+
const oriented = (event) => {
|
|
251
|
+
var _a;
|
|
252
|
+
var _b;
|
|
253
|
+
if (event.beta === null || event.gamma === null) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
heard = true;
|
|
257
|
+
if (WorkSenses.hidden()) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
neutral !== null && neutral !== void 0 ? neutral : (neutral = SenseMath.neutral(event.beta));
|
|
261
|
+
tell('tilt', SenseMath.tilt(event.beta, event.gamma, neutral, (_b = (_a = screen.orientation) === null || _a === void 0 ? void 0 : _a.angle) !== null && _b !== void 0 ? _b : 0));
|
|
262
|
+
};
|
|
263
|
+
const moved = (event) => {
|
|
264
|
+
var _a, _b, _c;
|
|
265
|
+
const acceleration = event.acceleration;
|
|
266
|
+
heard || (heard = !gates.has('tilt') && !!acceleration);
|
|
267
|
+
const power = acceleration ? SenseMath.shake((_a = acceleration.x) !== null && _a !== void 0 ? _a : 0, (_b = acceleration.y) !== null && _b !== void 0 ? _b : 0, (_c = acceleration.z) !== null && _c !== void 0 ? _c : 0) : 0;
|
|
268
|
+
if (power > 0 && !WorkSenses.hidden()) {
|
|
269
|
+
tell('shake', { power });
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
if (gates.has('tilt')) {
|
|
273
|
+
window.addEventListener('deviceorientation', oriented);
|
|
274
|
+
}
|
|
275
|
+
if (gates.has('shake')) {
|
|
276
|
+
window.addEventListener('devicemotion', moved);
|
|
277
|
+
}
|
|
278
|
+
return () => {
|
|
279
|
+
clearTimeout(quiet);
|
|
280
|
+
window.removeEventListener('deviceorientation', oriented);
|
|
281
|
+
window.removeEventListener('devicemotion', moved);
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
readSound(stream, tell, gates) {
|
|
285
|
+
var _a;
|
|
286
|
+
const Context = (_a = window.AudioContext) !== null && _a !== void 0 ? _a : window.webkitAudioContext;
|
|
287
|
+
if (!Context) {
|
|
288
|
+
return () => undefined;
|
|
289
|
+
}
|
|
290
|
+
const context = new Context();
|
|
291
|
+
const analyser = context.createAnalyser();
|
|
292
|
+
analyser.fftSize = 1024;
|
|
293
|
+
analyser.smoothingTimeConstant = 0.5;
|
|
294
|
+
context.createMediaStreamSource(stream).connect(analyser);
|
|
295
|
+
void context.resume().catch(() => undefined);
|
|
296
|
+
const bins = new Uint8Array(analyser.frequencyBinCount);
|
|
297
|
+
const binHz = context.sampleRate / analyser.fftSize;
|
|
298
|
+
const timer = setInterval(() => {
|
|
299
|
+
if (WorkSenses.hidden()) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
analyser.getByteFrequencyData(bins);
|
|
303
|
+
const { loud, blow } = SenseMath.sound(bins, binHz);
|
|
304
|
+
if (gates.has('loud')) {
|
|
305
|
+
tell('loud', loud);
|
|
306
|
+
}
|
|
307
|
+
if (gates.has('blow')) {
|
|
308
|
+
tell('blow', blow);
|
|
309
|
+
}
|
|
310
|
+
}, 50);
|
|
311
|
+
return () => {
|
|
312
|
+
clearInterval(timer);
|
|
313
|
+
void context.close().catch(() => undefined);
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
readCamera(stream, tell) {
|
|
317
|
+
const width = 32;
|
|
318
|
+
const height = 24;
|
|
319
|
+
const video = document.createElement('video');
|
|
320
|
+
video.muted = true;
|
|
321
|
+
video.playsInline = true;
|
|
322
|
+
video.srcObject = stream;
|
|
323
|
+
void video.play().catch(() => undefined);
|
|
324
|
+
const canvas = document.createElement('canvas');
|
|
325
|
+
canvas.width = width;
|
|
326
|
+
canvas.height = height;
|
|
327
|
+
const context = canvas.getContext('2d', { willReadFrequently: true });
|
|
328
|
+
let before;
|
|
329
|
+
const timer = setInterval(() => {
|
|
330
|
+
if (!context || WorkSenses.hidden() || video.readyState < 2) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
context.drawImage(video, 0, 0, width, height);
|
|
334
|
+
const rgba = context.getImageData(0, 0, width, height).data;
|
|
335
|
+
const grey = new Uint8Array(width * height);
|
|
336
|
+
for (let index = 0; index < grey.length; index++) {
|
|
337
|
+
grey[index] = (rgba[index * 4] * 3 + rgba[index * 4 + 1] * 6 + rgba[index * 4 + 2]) / 10;
|
|
338
|
+
}
|
|
339
|
+
if (before) {
|
|
340
|
+
tell('move', SenseMath.move(before, grey, width, height));
|
|
341
|
+
}
|
|
342
|
+
before = grey;
|
|
343
|
+
}, 66);
|
|
344
|
+
return () => {
|
|
345
|
+
clearInterval(timer);
|
|
346
|
+
video.srcObject = null;
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/** How long the motion sensors may stay silent before they are taken as not here (a computer that says it is touched). */
|
|
351
|
+
WorkSenses.SILENT_MS = 1500;
|
|
352
|
+
//# sourceMappingURL=work-senses.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TaMemoryStore } from '@celljs/ta-protocol';
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { useBusy } from '../components/busy.js';
|
|
3
4
|
import { ConversationView } from '../components/conversation-view.js';
|
|
@@ -16,6 +17,8 @@ import { WebDialog } from '../components/web-dialog.js';
|
|
|
16
17
|
import { useDevice } from '../device/device.js';
|
|
17
18
|
import { WEB_ICONS } from '../extension/icons.js';
|
|
18
19
|
import { Game3DView, GameView } from '../game/game-view.js';
|
|
20
|
+
import { WorkFrame } from '../sandbox/work/work-frame.js';
|
|
21
|
+
import { WorkSenses } from '../sandbox/work/work-senses.js';
|
|
19
22
|
/**
|
|
20
23
|
* The web extensions that draw in conversations, for a conversation shared by a link (docs/design/ta-link.md 2.6):
|
|
21
24
|
* the built-in packages that say so (`pi.shares`) lie next to the page, `ext/<name>.js`. They start with an API
|
|
@@ -80,6 +83,9 @@ export var SharedExtensions;
|
|
|
80
83
|
Avatar: TaAvatar,
|
|
81
84
|
Game: games.game,
|
|
82
85
|
Game3D: games.game3d,
|
|
86
|
+
// A game of the conversation plays here, alone: its frame and senses are the page's, as in Ta.
|
|
87
|
+
WorkFrame,
|
|
88
|
+
WorkSenses,
|
|
83
89
|
FullScreen,
|
|
84
90
|
Stack: PhoneStack,
|
|
85
91
|
Face,
|
|
@@ -102,7 +108,8 @@ export var SharedExtensions;
|
|
|
102
108
|
useAsks: () => [],
|
|
103
109
|
useTasks: () => [],
|
|
104
110
|
useHomeItems: () => [],
|
|
105
|
-
|
|
111
|
+
// What a game asks before it uses the microphone or the camera: the browser's own question.
|
|
112
|
+
confirm: (title, message) => Promise.resolve(typeof window !== 'undefined' && window.confirm([title, message].filter(Boolean).join('\n\n'))),
|
|
106
113
|
input: () => Promise.resolve(undefined),
|
|
107
114
|
editor: () => Promise.resolve(undefined),
|
|
108
115
|
};
|
|
@@ -130,6 +137,11 @@ export var SharedExtensions;
|
|
|
130
137
|
fileUrl: refuse,
|
|
131
138
|
reloadExtensions: () => Promise.resolve(),
|
|
132
139
|
openTemporary: refuse,
|
|
140
|
+
// No Ta behind the page: no chats, no packages; what an extension keeps is kept in memory, gone with the page.
|
|
141
|
+
rooms: undefined,
|
|
142
|
+
onRoomEvent: undefined,
|
|
143
|
+
packages: undefined,
|
|
144
|
+
storage: new TaMemoryStore(),
|
|
133
145
|
};
|
|
134
146
|
return orNothing(api);
|
|
135
147
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type RelayContentItem, type RelayContentLink, type RelayConversation } from '@celljs/ta-relay';
|
|
1
|
+
import { type RelayContentItem, type RelayContentLink, type RelayConversation, type RelayWork } from '@celljs/ta-relay';
|
|
2
2
|
/**
|
|
3
3
|
* A conversation shared by a link, opened in a browser (docs/design/ta-link.md 2.6): the viewer of the relay
|
|
4
4
|
* (`/s`) opens it and hands it to this page of the same relay, which draws it as Ta does, with the cards, plots
|
|
@@ -7,5 +7,7 @@ import { type RelayContentItem, type RelayContentLink, type RelayConversation }
|
|
|
7
7
|
export declare namespace SharedPageUtil {
|
|
8
8
|
/** The link the address of this page holds in its fragment (`#v=1&h=…&s=…`), as the viewer of the relay has it. */
|
|
9
9
|
function link(href?: string): RelayContentLink | undefined;
|
|
10
|
+
/** A work shared (RELAY_WORK_KIND): one block, drawn as a reply draws it. */
|
|
11
|
+
function work(item: RelayContentItem): RelayWork | undefined;
|
|
10
12
|
function conversation(item: RelayContentItem): RelayConversation | undefined;
|
|
11
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RELAY_CONTENT_PATH, RELAY_CONVERSATION_KIND } from '@celljs/ta-relay';
|
|
1
|
+
import { RELAY_CONTENT_PATH, RELAY_CONVERSATION_KIND, RELAY_WORK_KIND, } from '@celljs/ta-relay';
|
|
2
2
|
import { RelayContentUtil } from '@celljs/ta-relay/lib/common/relay-content';
|
|
3
3
|
/**
|
|
4
4
|
* A conversation shared by a link, opened in a browser (docs/design/ta-link.md 2.6): the viewer of the relay
|
|
@@ -22,6 +22,22 @@ export var SharedPageUtil;
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
SharedPageUtil.link = link;
|
|
25
|
+
/** A work shared (RELAY_WORK_KIND): one block, drawn as a reply draws it. */
|
|
26
|
+
function work(item) {
|
|
27
|
+
if (item.kind !== RELAY_WORK_KIND) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const work = JSON.parse(new TextDecoder().decode(item.data));
|
|
32
|
+
return work && typeof work.language === 'string' && typeof work.code === 'string'
|
|
33
|
+
? { v: 1, language: work.language, code: work.code, title: typeof work.title === 'string' ? work.title : item.title }
|
|
34
|
+
: undefined;
|
|
35
|
+
}
|
|
36
|
+
catch (_a) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
SharedPageUtil.work = work;
|
|
25
41
|
function conversation(item) {
|
|
26
42
|
if (item.kind !== RELAY_CONVERSATION_KIND) {
|
|
27
43
|
return undefined;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { TaWorkBlock } from '@celljs/ta-protocol';
|
|
1
2
|
import { RELAY_CONTENT_PATH } from '@celljs/ta-relay';
|
|
2
3
|
import { RelayContentError, RelayContentHandoff, RelayContentUtil } from '@celljs/ta-relay/lib/common/relay-content';
|
|
4
|
+
import { RelayOpenInTa } from '@celljs/ta-relay/lib/common/relay-open-in-ta';
|
|
3
5
|
import { Check, Link2 } from 'lucide-react';
|
|
4
6
|
import * as React from 'react';
|
|
5
7
|
import { ConversationView } from '../components/conversation-view.js';
|
|
6
8
|
import { Dino, dinoFavicon } from '../components/dino.js';
|
|
7
9
|
import { Icon } from '../components/icon.js';
|
|
8
10
|
import { Loading } from '../components/loading.js';
|
|
11
|
+
import { Markdown } from '../components/markdown.js';
|
|
9
12
|
import { Device } from '../device/device.js';
|
|
10
13
|
import { MessageRenderers, ToolRenderers } from '../extension/extension-view.js';
|
|
11
14
|
import { useSettings } from '../hooks.js';
|
|
@@ -21,6 +24,11 @@ function useShared(link) {
|
|
|
21
24
|
let live = true;
|
|
22
25
|
const kept = RelayContentHandoff.take(link.share);
|
|
23
26
|
const show = (item) => {
|
|
27
|
+
const work = SharedPageUtil.work(item);
|
|
28
|
+
if (work) {
|
|
29
|
+
setShown({ step: 'work', item, work });
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
24
32
|
const conversation = SharedPageUtil.conversation(item);
|
|
25
33
|
if (!conversation) {
|
|
26
34
|
// Not a conversation: the viewer shows it.
|
|
@@ -109,9 +117,12 @@ export function SharedPage({ link }) {
|
|
|
109
117
|
const shown = useShared(link);
|
|
110
118
|
const drawn = useRenderers();
|
|
111
119
|
const conversation = shown.step === 'shown' ? shown.conversation : undefined;
|
|
112
|
-
const
|
|
120
|
+
const work = shown.step === 'work' ? shown.work : undefined;
|
|
121
|
+
const title = (conversation === null || conversation === void 0 ? void 0 : conversation.title) || (work === null || work === void 0 ? void 0 : work.title) || (shown.step === 'shown' ? shown.item.title : '');
|
|
113
122
|
useSharedDocument(title);
|
|
114
|
-
const date = shown.step === 'shown'
|
|
123
|
+
const date = shown.step === 'shown' || shown.step === 'work'
|
|
124
|
+
? new Intl.DateTimeFormat(language, { dateStyle: 'medium', timeStyle: 'short' }).format(shown.item.createdAt)
|
|
125
|
+
: '';
|
|
115
126
|
const count = (_a = conversation === null || conversation === void 0 ? void 0 : conversation.messages.filter(message => message.role === 'user' || message.role === 'assistant').length) !== null && _a !== void 0 ? _a : 0;
|
|
116
127
|
return (React.createElement("div", { className: "ta-shared" },
|
|
117
128
|
React.createElement("header", { className: "ta-shared-top" },
|
|
@@ -120,7 +131,20 @@ export function SharedPage({ link }) {
|
|
|
120
131
|
React.createElement(CopyLink, null)),
|
|
121
132
|
React.createElement("main", { className: "ta-scroll ta-conversation ta-shared-main" },
|
|
122
133
|
shown.step === 'failed' && React.createElement("div", { className: "ta-shared-center ta-muted" }, t('ta.shared.failed')),
|
|
123
|
-
(shown.step === 'loading' || (conversation && !drawn)) && React.createElement(Loading, null),
|
|
134
|
+
(shown.step === 'loading' || ((conversation || work) && !drawn)) && React.createElement(Loading, null),
|
|
135
|
+
work && drawn && (React.createElement(React.Fragment, null,
|
|
136
|
+
React.createElement("div", { className: "ta-shared-head" },
|
|
137
|
+
React.createElement("h1", null, title),
|
|
138
|
+
React.createElement("p", { className: "ta-shared-meta" },
|
|
139
|
+
React.createElement("span", null, t('ta.shared.sharedAt', { date })))),
|
|
140
|
+
React.createElement(CodeRenderers.Provider, { value: drawn.codeRenderers },
|
|
141
|
+
React.createElement("div", { className: "ta-shared-work" },
|
|
142
|
+
React.createElement(Markdown, { text: TaWorkBlock.fenced(work.language, work.code) }))),
|
|
143
|
+
React.createElement("footer", { className: "ta-shared-foot" },
|
|
144
|
+
React.createElement("a", { className: "ta-button ta-primary ta-shared-mine", href: RelayOpenInTa.link(`${location.origin}${RELAY_CONTENT_PATH}${location.hash}`) }, t('ta.shared.makeMine')),
|
|
145
|
+
React.createElement("span", null, t('ta.shared.footer')),
|
|
146
|
+
React.createElement("span", null, t('ta.shared.secure')),
|
|
147
|
+
React.createElement("a", { className: "ta-shared-report", href: `${RELAY_CONTENT_PATH}?report${location.hash}` }, t('ta.shared.report'))))),
|
|
124
148
|
conversation && drawn && (React.createElement(React.Fragment, null,
|
|
125
149
|
React.createElement("div", { className: "ta-shared-head" },
|
|
126
150
|
React.createElement("h1", null, title),
|