clavarium 0.2.200-next.1 → 0.2.201-next.1
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/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/boxes.mjs +30 -4
- package/web/app.js +4 -2
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.201-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.201-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/boxes.mjs
CHANGED
|
@@ -106,6 +106,21 @@ export function forSpeech(text) {
|
|
|
106
106
|
.slice(0, 1500);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/* THE BOX'S CLOCK: its lights follow the hours of its place. The time zone is the page's that made its code
|
|
110
|
+
(its browser's), else this server's; the box is told its offset from UTC at each connection and every hour
|
|
111
|
+
after, so summer time comes by itself. */
|
|
112
|
+
export function zoneOf(zone) {
|
|
113
|
+
const z = String(zone ?? '').trim();
|
|
114
|
+
try { if (z && /^[A-Za-z_]+(?:\/[A-Za-z0-9_+-]+){0,2}$/.test(z)) { new Intl.DateTimeFormat('en', { timeZone: z }); return z; } } catch { /* unknown */ }
|
|
115
|
+
return '';
|
|
116
|
+
}
|
|
117
|
+
export function offsetOf(zone, now) {
|
|
118
|
+
const z = zoneOf(zone) || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
119
|
+
const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', { timeZone: z, hourCycle: 'h23', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }).formatToParts(new Date(now)).map((p) => [p.type, p.value]));
|
|
120
|
+
const local = Date.UTC(+parts.year, +parts.month - 1, +parts.day, +parts.hour, +parts.minute);
|
|
121
|
+
return Math.round((local - Math.floor(now / 60_000) * 60_000) / 60_000);
|
|
122
|
+
}
|
|
123
|
+
|
|
109
124
|
export const DOING_WITHIN_MS = 120_000;
|
|
110
125
|
/* A LONG RECORDING (a meeting, a class): asked in words, stopped by the button or the wake word. */
|
|
111
126
|
export const RECORD_ASKED = /\b(?:lance|d[ée]marre|commence|d[ée]bute)\w*\b.{0,25}\benregistrement\b|\benregistre\b.{0,20}\b(?:r[ée]union|conversation|cours|discussion|consultation)\b/i;
|
|
@@ -178,11 +193,11 @@ export class Boxes {
|
|
|
178
193
|
return this.#all().map(({ keyHash, ...b }) => ({ ...b, online: this.#links.has(b.id), muted: this.#links.get(b.id)?.muted ?? null, volume: b.volume ?? this.#links.get(b.id)?.volume ?? VOLUME_DEFAULT }));
|
|
179
194
|
}
|
|
180
195
|
|
|
181
|
-
code(conversation, name) {
|
|
196
|
+
code(conversation, name, zone = '') {
|
|
182
197
|
if (!this.#exists(conversation)) throw new Refusal(404, 'No such conversation.');
|
|
183
198
|
const code = newCode();
|
|
184
199
|
const label = String(name ?? '').trim().slice(0, NAME_MAX);
|
|
185
|
-
this.#codes.set(plainCode(code), { conversation, name: label, until: this.#now() + CODE_MINUTES * 60_000 });
|
|
200
|
+
this.#codes.set(plainCode(code), { conversation, name: label, zone: zoneOf(zone), until: this.#now() + CODE_MINUTES * 60_000 });
|
|
186
201
|
return { code, minutes: CODE_MINUTES };
|
|
187
202
|
}
|
|
188
203
|
|
|
@@ -202,6 +217,7 @@ export class Boxes {
|
|
|
202
217
|
type: String(body.type ?? '').slice(0, 40), firmware: String(body.firmware ?? '').slice(0, 20),
|
|
203
218
|
capabilities: Array.isArray(body.capabilities) ? body.capabilities.map(String).slice(0, 20) : [],
|
|
204
219
|
createdAt: new Date(now).toISOString(), seenAt: null,
|
|
220
|
+
...(wanted.zone ? { zone: wanted.zone } : {}),
|
|
205
221
|
};
|
|
206
222
|
this.#save([...this.#all(), box]);
|
|
207
223
|
this.#log(`voice box paired: ${name} (${box.conversation})`);
|
|
@@ -324,7 +340,13 @@ export class Boxes {
|
|
|
324
340
|
}
|
|
325
341
|
|
|
326
342
|
/* Where it is (a home, a family house): grouped by it, named with it. */
|
|
327
|
-
|
|
343
|
+
zone(id, zone) {
|
|
344
|
+
const z = zoneOf(zone);
|
|
345
|
+
if (!z) throw new Refusal(400, 'Not a time zone.');
|
|
346
|
+
this.#change(id, { zone: z });
|
|
347
|
+
this.#links.get(id)?.send({ t: 'clock', offset: offsetOf(z, this.#now()) });
|
|
348
|
+
}
|
|
349
|
+
place(id, place) { this.#change(id, { place: String(place ?? '').trim().slice(0, NAME_MAX) }); }
|
|
328
350
|
|
|
329
351
|
move(id, conversation) {
|
|
330
352
|
if (!this.#exists(conversation)) throw new Refusal(404, 'No such conversation.');
|
|
@@ -450,6 +472,8 @@ export class Boxes {
|
|
|
450
472
|
const wanted = link.box().volume ?? VOLUME_DEFAULT;
|
|
451
473
|
if (m.volume !== wanted) { send({ t: 'volume', id: randomUUID(), level: wanted }); m.volume = wanted; }
|
|
452
474
|
}
|
|
475
|
+
if (m.t === 'hello') send({ t: 'clock', offset: offsetOf(link.box().zone, this.#now()) });
|
|
476
|
+
if (m.t === 'ping' && this.#now() - (link.clockAt ?? 0) > 3_600_000) { link.clockAt = this.#now(); send({ t: 'clock', offset: offsetOf(link.box().zone, this.#now()) }); }
|
|
453
477
|
if (m.t === 'hello') { link.muted = m.muted === true; link.volume = Number.isFinite(m.volume) ? m.volume : null; this.#change(box.id, { firmware: String(m.firmware ?? '').slice(0, 20) }); seen(); return; }
|
|
454
478
|
if (m.t === 'record.start' && this.#recordDir) {
|
|
455
479
|
mkdirSync(this.#recordDir, { recursive: true });
|
|
@@ -584,6 +608,7 @@ export class Boxes {
|
|
|
584
608
|
* POST /api/boxes/<id>/rename {name}
|
|
585
609
|
* POST /api/boxes/<id>/move {conversation}: one conversation at a time
|
|
586
610
|
* POST /api/boxes/<id>/place {place}: where it is (a home), shown with its name
|
|
611
|
+
* POST /api/boxes/<id>/zone {zone}: its time zone (IANA), for its clock; the page gives its own
|
|
587
612
|
* POST /api/boxes/<id>/revoke
|
|
588
613
|
* POST /api/boxes/<id>/volume {level 0-100}
|
|
589
614
|
* POST /api/boxes/<id>/wifi-scan -> {networks}
|
|
@@ -602,7 +627,7 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
|
|
|
602
627
|
for await (const piece of request) { text += piece; if (text.length > 8192) return send(413, { error: 'Too long.' }); }
|
|
603
628
|
const body = text ? JSON.parse(text) : {};
|
|
604
629
|
if (pathname === '/api/boxes/code') {
|
|
605
|
-
const made = boxes.code(String(body.conversation ?? ''), body.name);
|
|
630
|
+
const made = boxes.code(String(body.conversation ?? ''), body.name, body.zone);
|
|
606
631
|
/* With this page's address: the key, and a link (its QR code) that opens the box's page filled in. */
|
|
607
632
|
const origin = /^https?:\/\/[^/\s]+$/.test(String(body.origin ?? '')) ? String(body.origin) : '';
|
|
608
633
|
if (!origin) return send(201, made);
|
|
@@ -618,6 +643,7 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
|
|
|
618
643
|
case 'rename': boxes.rename(id, body.name); return send(200, { ok: true });
|
|
619
644
|
case 'move': boxes.move(id, String(body.conversation ?? '')); return send(200, { ok: true });
|
|
620
645
|
case 'place': boxes.place(id, body.place); return send(200, { ok: true });
|
|
646
|
+
case 'zone': boxes.zone(id, body.zone); return send(200, { ok: true });
|
|
621
647
|
case 'revoke': boxes.revoke(id); return send(200, { ok: true });
|
|
622
648
|
case 'volume': return answered(await boxes.setVolume(id, body.level));
|
|
623
649
|
case 'wifi-scan': { const r = await boxes.command(id, { t: 'wifi.scan' }); return send(200, { networks: Array.isArray(r.networks) ? r.networks : [] }); }
|
package/web/app.js
CHANGED
|
@@ -4442,7 +4442,7 @@
|
|
|
4442
4442
|
row.hidden = true;
|
|
4443
4443
|
const call = async (op, args) => { try { return { ok: true, data: await post(`${API}/tether/${op}`, args) }; } catch (error) { return { ok: false, text: error.message }; } };
|
|
4444
4444
|
/* A device that pairs (a voice box): a one-use code for the conversation that asked, made here. */
|
|
4445
|
-
const pair = async (room) => { const r = await post(`${API}/boxes/code`, { conversation: String(job.agent).replace(/^conversation:/, ''), name: room }); return { url: location.origin, code: r.code }; };
|
|
4445
|
+
const pair = async (room) => { const r = await post(`${API}/boxes/code`, { conversation: String(job.agent).replace(/^conversation:/, ''), name: room, zone: Intl.DateTimeFormat().resolvedOptions().timeZone }); return { url: location.origin, code: r.code }; };
|
|
4446
4446
|
try { const { runJob } = await import('/vendor/tether/jobs.js'); await runJob(job, { call, root: place, pair }); }
|
|
4447
4447
|
catch (error) { place.textContent = `It could not start: ${error.message}`; }
|
|
4448
4448
|
setTimeout(() => { jobPlaces.delete(job.id); after?.(); }, 4000);
|
|
@@ -8864,6 +8864,8 @@
|
|
|
8864
8864
|
/* Where it is (a home): typed once, then offered for the next ones. */
|
|
8865
8865
|
const place = el('input'); place.value = b.place ?? ''; place.maxLength = 40; place.placeholder = 'Place (a home)'; place.setAttribute('list', 'box-places'); place.setAttribute('aria-label', `Place of ${b.name}`);
|
|
8866
8866
|
place.addEventListener('change', async () => { await post(`${API}/boxes/${b.id}/place`, { place: place.value.trim() }).catch(() => {}); await paintBoxes(); });
|
|
8867
|
+
/* A box paired before it knew its time zone takes this page's: its lights follow the hours here. */
|
|
8868
|
+
if (!b.zone) void post(`${API}/boxes/${b.id}/zone`, { zone: Intl.DateTimeFormat().resolvedOptions().timeZone }).catch(() => {});
|
|
8867
8869
|
/* Louder, softer: kept here, given to the box now or when it comes back. */
|
|
8868
8870
|
const vol = el('input'); vol.type = 'range'; vol.min = '0'; vol.max = '100'; vol.step = '5'; vol.value = String(b.volume ?? 80); vol.setAttribute('aria-label', `Volume of ${b.name}`);
|
|
8869
8871
|
const volSaid = el('small', 'hint', `${vol.value} %`);
|
|
@@ -8893,7 +8895,7 @@
|
|
|
8893
8895
|
$('box-code').addEventListener('click', async () => {
|
|
8894
8896
|
if (!$('box-conversation').value) { $('box-conversation').focus(); $('box-code-minutes').textContent = 'Choose the conversation it speaks in first.'; $('box-ready').hidden = false; return; }
|
|
8895
8897
|
try {
|
|
8896
|
-
const r = await post(`${API}/boxes/code`, { conversation: $('box-conversation').value, name: $('box-room').value.trim(), origin: location.origin });
|
|
8898
|
+
const r = await post(`${API}/boxes/code`, { conversation: $('box-conversation').value, name: $('box-room').value.trim(), origin: location.origin, zone: Intl.DateTimeFormat().resolvedOptions().timeZone });
|
|
8897
8899
|
$('box-code-shown').textContent = r.code; $('box-code-minutes').textContent = `valid ${r.minutes} minutes, once`;
|
|
8898
8900
|
$('box-key').textContent = r.key ?? '';
|
|
8899
8901
|
$('box-link').href = r.link ?? '#';
|