clavarium 0.2.164-next.1 → 0.2.167-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 +6 -6
- package/package.json +2 -2
- package/server/boxes.mjs +39 -13
- package/server/main.mjs +6 -3
- package/server/talk.mjs +5 -2
- package/web/app.js +24 -7
- package/web/index.html +5 -4
- package/web/style.css +4 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.167-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.167-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
13
13
|
"@xterm/xterm": "^6.0.0",
|
|
14
14
|
"clavarium-binder": "0.1.43-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.1",
|
|
16
|
-
"clavarium-parley": "0.17.
|
|
16
|
+
"clavarium-parley": "0.17.32-next.1",
|
|
17
17
|
"clavarium-tether": "0.1.0-next.40",
|
|
18
18
|
"mermaid": "11.17.2",
|
|
19
19
|
"node-pty": "^1.1.0",
|
|
@@ -747,9 +747,9 @@
|
|
|
747
747
|
}
|
|
748
748
|
},
|
|
749
749
|
"node_modules/clavarium-parley": {
|
|
750
|
-
"version": "0.17.
|
|
751
|
-
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.
|
|
752
|
-
"integrity": "sha512-
|
|
750
|
+
"version": "0.17.32-next.1",
|
|
751
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.32-next.1.tgz",
|
|
752
|
+
"integrity": "sha512-nE0i749jZBXtBm5o7Wg1tGrKaLl3Z8YwQ6NEnVDhEQaHClnfmGIwecNTUdlDA3I3PYzboawhtsjt7VAsW+hUtQ==",
|
|
753
753
|
"license": "MIT",
|
|
754
754
|
"bin": {
|
|
755
755
|
"parley": "bin/parley.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.167-next.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@xterm/xterm": "^6.0.0",
|
|
47
47
|
"clavarium-binder": "0.1.43-next.1",
|
|
48
48
|
"clavarium-docket": "0.1.1",
|
|
49
|
-
"clavarium-parley": "0.17.
|
|
49
|
+
"clavarium-parley": "0.17.32-next.1",
|
|
50
50
|
"clavarium-tether": "0.1.0-next.40",
|
|
51
51
|
"mermaid": "11.17.2",
|
|
52
52
|
"node-pty": "^1.1.0",
|
package/server/boxes.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
*
|
|
3
3
|
* A press on its button, a sentence: the box streams it here, the dictation
|
|
4
4
|
* engine (voice.mjs) turns it into text, and the text is said in the box's
|
|
5
|
-
* conversation
|
|
5
|
+
* conversation by the box itself, in its own name (Parley's speakers, #215). What the tool
|
|
6
6
|
* then says or asks there is read aloud (speech.mjs) and played by the box.
|
|
7
7
|
* Protocol v1: DEVICES.md.
|
|
8
8
|
*
|
|
@@ -26,6 +26,14 @@ export const SENTENCE_MAX = 15 * 32_000 + 32_000; /* 15 s of 16 kHz 16-bit
|
|
|
26
26
|
export const ANSWER_MINUTES = 5; /* after a sentence, what the tool says is spoken */
|
|
27
27
|
export const TRIES_PER_MINUTE = 10;
|
|
28
28
|
export const NAME_MAX = 40;
|
|
29
|
+
/* Where a box in setup answers, on its own Wi-Fi: ESP-IDF's access point address, the same on
|
|
30
|
+
every box (written from its parts: it is no machine of anybody's). */
|
|
31
|
+
export const SETUP_ADDRESS = `http://${[192, 168, 4, 1].join('.')}/`;
|
|
32
|
+
|
|
33
|
+
/* The setup key: this server's address, the room, a pairing code -- one paste, or one link. */
|
|
34
|
+
export function setupKey(origin, room, code) {
|
|
35
|
+
return `GAMBELI-${Buffer.from(JSON.stringify({ u: origin, r: room, c: code })).toString('base64url')}`;
|
|
36
|
+
}
|
|
29
37
|
const ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; /* nothing read two ways: no 0/O, 1/I */
|
|
30
38
|
|
|
31
39
|
export const hashOf = (key) => createHash('sha256').update(String(key)).digest('hex');
|
|
@@ -62,16 +70,19 @@ export function forSpeech(text) {
|
|
|
62
70
|
|
|
63
71
|
export class Boxes {
|
|
64
72
|
#file; #codes = new Map(); #links = new Map(); #tries = []; #now;
|
|
65
|
-
#exists; #hear; #say; #speak; #log;
|
|
73
|
+
#exists; #hear; #say; #speak; #log; #changed;
|
|
66
74
|
|
|
67
75
|
/* file: a JsonFile holding [{ id, name, conversation, keyHash, firmware, createdAt, seenAt }].
|
|
68
76
|
exists(conversation), hear(wav) -> text, say(conversation, text, room), speak(text) -> PCM 16 kHz. */
|
|
69
|
-
constructor({ file, exists = () => true, hear, say, speak, now = () => Date.now(), log = () => {} }) {
|
|
70
|
-
this.#file = file; this.#exists = exists; this.#hear = hear; this.#say = say; this.#speak = speak; this.#now = now; this.#log = log;
|
|
77
|
+
constructor({ file, exists = () => true, hear, say, speak, changed = () => {}, now = () => Date.now(), log = () => {} }) {
|
|
78
|
+
this.#file = file; this.#changed = changed; this.#exists = exists; this.#hear = hear; this.#say = say; this.#speak = speak; this.#now = now; this.#log = log;
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
#all() { const v = this.#file.get(); return Array.isArray(v) ? v : []; }
|
|
74
|
-
#save(list) { this.#file.set(list); }
|
|
82
|
+
#save(list) { this.#file.set(list); try { this.#changed(); } catch { /* the caller's */ } }
|
|
83
|
+
|
|
84
|
+
/* The boxes of one conversation, as its thread names them: { id, name, place }. */
|
|
85
|
+
speakersOf(conversation) { return this.#all().filter((b) => b.conversation === conversation).map((b) => ({ id: b.id, name: b.name, ...(b.place ? { place: b.place } : {}) })); }
|
|
75
86
|
|
|
76
87
|
/* What the operator sees: never the key, nor its hash. */
|
|
77
88
|
all() {
|
|
@@ -120,6 +131,9 @@ export class Boxes {
|
|
|
120
131
|
this.#change(id, { name: label });
|
|
121
132
|
}
|
|
122
133
|
|
|
134
|
+
/* Where it is (a home, a family house): grouped by it, named with it. */
|
|
135
|
+
place(id, place) { this.#change(id, { place: String(place ?? '').trim().slice(0, NAME_MAX) }); }
|
|
136
|
+
|
|
123
137
|
move(id, conversation) {
|
|
124
138
|
if (!this.#exists(conversation)) throw new Refusal(404, 'No such conversation.');
|
|
125
139
|
this.#change(id, { conversation });
|
|
@@ -157,12 +171,14 @@ export class Boxes {
|
|
|
157
171
|
});
|
|
158
172
|
}
|
|
159
173
|
|
|
160
|
-
/* The tool said or asked something in a conversation
|
|
161
|
-
|
|
174
|
+
/* The tool said or asked something in a conversation. Addressed (`to`: box ids, #215): said by
|
|
175
|
+
those boxes of this conversation. Not addressed: said by its boxes that were just talked to. */
|
|
176
|
+
async agentSaid(conversation, text, to = null) {
|
|
162
177
|
const words = forSpeech(text);
|
|
163
178
|
if (!words) return;
|
|
164
179
|
const now = this.#now();
|
|
165
|
-
const
|
|
180
|
+
const mine = [...this.#links.values()].filter((l) => l.box().conversation === conversation);
|
|
181
|
+
const boxes = Array.isArray(to) && to.length ? mine.filter((l) => to.includes(l.box().id)) : mine.filter((l) => l.heardAt > now - ANSWER_MINUTES * 60_000);
|
|
166
182
|
if (boxes.length === 0) return;
|
|
167
183
|
let pcm;
|
|
168
184
|
try { pcm = await this.#speak(words); } catch (error) { this.#log(`voice box: no voice for the answer (${error.message})`); for (const l of boxes) l.send({ t: 'cue', name: 'error' }); return; }
|
|
@@ -223,7 +239,7 @@ export class Boxes {
|
|
|
223
239
|
try { text = String(await this.#hear(wavOf(pcm)) ?? '').trim(); } catch (error) { this.#log(`voice box: dictation failed (${error.message})`); link.send({ t: 'cue', name: 'error' }); return; }
|
|
224
240
|
if (!text) { link.send({ t: 'cue', name: 'error' }); return; }
|
|
225
241
|
const box = link.box();
|
|
226
|
-
try { await this.#say(box.conversation, text, box.name); } catch (error) { this.#log(`voice box: not said in ${box.conversation} (${error.message})`); link.send({ t: 'cue', name: 'error' }); return; }
|
|
242
|
+
try { await this.#say(box.conversation, text, { id: box.id, name: box.name, ...(box.place ? { place: box.place } : {}) }); } catch (error) { this.#log(`voice box: not said in ${box.conversation} (${error.message})`); link.send({ t: 'cue', name: 'error' }); return; }
|
|
227
243
|
link.heardAt = this.#now();
|
|
228
244
|
}
|
|
229
245
|
|
|
@@ -244,9 +260,10 @@ export class Boxes {
|
|
|
244
260
|
|
|
245
261
|
/* The operator's side, behind the sign-on:
|
|
246
262
|
* GET /api/boxes the boxes, online or not
|
|
247
|
-
* POST /api/boxes/code {conversation, name?} -> {code, minutes}
|
|
263
|
+
* POST /api/boxes/code {conversation, name?, origin?} -> {code, minutes, key?, link?, qr?}
|
|
248
264
|
* POST /api/boxes/<id>/rename {name}
|
|
249
|
-
* POST /api/boxes/<id>/move {conversation}
|
|
265
|
+
* POST /api/boxes/<id>/move {conversation}: one conversation at a time
|
|
266
|
+
* POST /api/boxes/<id>/place {place}: where it is (a home), shown with its name
|
|
250
267
|
* POST /api/boxes/<id>/revoke
|
|
251
268
|
* POST /api/boxes/<id>/volume {level 0-100}
|
|
252
269
|
* POST /api/boxes/<id>/wifi-scan -> {networks}
|
|
@@ -254,7 +271,7 @@ export class Boxes {
|
|
|
254
271
|
* POST /api/boxes/<id>/alert {text?}
|
|
255
272
|
* POST /api/boxes/<id>/reboot
|
|
256
273
|
*/
|
|
257
|
-
export async function handleBoxes(request, response, boxes, originOk, headers = {}) {
|
|
274
|
+
export async function handleBoxes(request, response, boxes, originOk, headers = {}, qr = null) {
|
|
258
275
|
const { pathname } = new URL(request.url ?? '/', 'http://local');
|
|
259
276
|
const send = (status, body) => { response.writeHead(status, { ...headers, 'content-type': 'application/json; charset=utf-8' }).end(JSON.stringify(body)); return true; };
|
|
260
277
|
try {
|
|
@@ -264,7 +281,15 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
|
|
|
264
281
|
let text = '';
|
|
265
282
|
for await (const piece of request) { text += piece; if (text.length > 8192) return send(413, { error: 'Too long.' }); }
|
|
266
283
|
const body = text ? JSON.parse(text) : {};
|
|
267
|
-
if (pathname === '/api/boxes/code')
|
|
284
|
+
if (pathname === '/api/boxes/code') {
|
|
285
|
+
const made = boxes.code(String(body.conversation ?? ''), body.name);
|
|
286
|
+
/* With this page's address: the key, and a link (its QR code) that opens the box's page filled in. */
|
|
287
|
+
const origin = /^https?:\/\/[^/\s]+$/.test(String(body.origin ?? '')) ? String(body.origin) : '';
|
|
288
|
+
if (!origin) return send(201, made);
|
|
289
|
+
const key = setupKey(origin, String(body.name ?? '').trim().slice(0, NAME_MAX), made.code);
|
|
290
|
+
const link = `${SETUP_ADDRESS}?k=${key}`;
|
|
291
|
+
return send(201, { ...made, key, link, qr: qr ? await qr(link) : undefined });
|
|
292
|
+
}
|
|
268
293
|
const m = /^\/api\/boxes\/([0-9a-f-]{36})\/([a-z-]+)$/.exec(pathname);
|
|
269
294
|
if (!m) return false;
|
|
270
295
|
const [, id, what] = m;
|
|
@@ -272,6 +297,7 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
|
|
|
272
297
|
switch (what) {
|
|
273
298
|
case 'rename': boxes.rename(id, body.name); return send(200, { ok: true });
|
|
274
299
|
case 'move': boxes.move(id, String(body.conversation ?? '')); return send(200, { ok: true });
|
|
300
|
+
case 'place': boxes.place(id, body.place); return send(200, { ok: true });
|
|
275
301
|
case 'revoke': boxes.revoke(id); return send(200, { ok: true });
|
|
276
302
|
case 'volume': return answered(await boxes.command(id, { t: 'volume', level: Math.round(Number(body.level)) }));
|
|
277
303
|
case 'wifi-scan': { const r = await boxes.command(id, { t: 'wifi.scan' }); return send(200, { networks: Array.isArray(r.networks) ? r.networks : [] }); }
|
package/server/main.mjs
CHANGED
|
@@ -220,7 +220,7 @@ function serve(port, conversations, resources, { gate = () => 'local', originOk,
|
|
|
220
220
|
response.writeHead(403, { ...HEADERS, 'content-type': 'text/plain; charset=utf-8' }).end(REFUSED);
|
|
221
221
|
return;
|
|
222
222
|
}
|
|
223
|
-
if (boxes && pathname.startsWith('/api/boxes') && await handleBoxes(request, response, boxes, originOk, HEADERS)) return;
|
|
223
|
+
if (boxes && pathname.startsWith('/api/boxes') && await handleBoxes(request, response, boxes, originOk, HEADERS, (text) => QRCode.toString(text, { type: 'svg', margin: 1, errorCorrectionLevel: 'M' }))) return;
|
|
224
224
|
if (conversations && await handleApi(request, response, conversations, HEADERS, resources, originOk, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups)) return;
|
|
225
225
|
if (pathname === '/manifest.webmanifest' && request.method === 'GET') { sendManifest(response, request.url); return; }
|
|
226
226
|
const file = FILES[pathname];
|
|
@@ -468,7 +468,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
468
468
|
/* A conversation with a tool on a screen that is not its terminal: see talk.mjs. */
|
|
469
469
|
/* Voice boxes: what the tool says in their conversation is read aloud (boxes.mjs). */
|
|
470
470
|
let boxes;
|
|
471
|
-
const talk = new Talk({ spoke: (name, text) => { void boxes?.agentSaid(name, text); }, store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
471
|
+
const talk = new Talk({ spoke: (name, text, to) => { void boxes?.agentSaid(name, text, to); }, store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
472
472
|
...(rereadAfterMs === undefined ? {} : { rereadAfterMs }),
|
|
473
473
|
/* A line typed down the terminal already open when there is one, and
|
|
474
474
|
what is already known of a machine used instead of asking (talk.mjs). */
|
|
@@ -599,13 +599,16 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
599
599
|
exists: (name) => all.list().some((c) => c.name === name),
|
|
600
600
|
hear: (wav) => voice.transcribe(wav),
|
|
601
601
|
/* Said as the person's own message, the room named (one speaker for now). */
|
|
602
|
-
say: (name, text,
|
|
602
|
+
say: (name, text, by) => talk.say(name, text, undefined, undefined, 'voice', { by }),
|
|
603
|
+
/* Each conversation's thread knows its boxes: their names, and the ids its agent answers. */
|
|
604
|
+
changed: () => { for (const c of all.list()) talk.speakers(c.name, boxes.speakersOf(c.name)); },
|
|
603
605
|
speak: (text) => speech.speak(text),
|
|
604
606
|
log: (line) => events.add({ kind: 'server', text: line }) });
|
|
605
607
|
const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, wifi, binders, meshcentral, tethers, accounts, groups, boxes, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
|
|
606
608
|
server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
|
|
607
609
|
let closing = false;
|
|
608
610
|
boxes.attach(server, WebSocketServer);
|
|
611
|
+
for (const c of all.list()) talk.speakers(c.name, boxes.speakersOf(c.name));
|
|
609
612
|
bridge = attachBridge(server, {
|
|
610
613
|
onRejoin: (name) => all.rejoin(name),
|
|
611
614
|
onTyped: (name, data) => { answerer.typed(name, data); talk.typed(name); all.touch(name); typingWatch.typed(name, data); },
|
package/server/talk.mjs
CHANGED
|
@@ -290,7 +290,7 @@ export class Talk {
|
|
|
290
290
|
if (event.type === 'person-reacted') { reacted(event); return; }
|
|
291
291
|
if (event.type === 'person-wrote') { this.#want(name); return; }
|
|
292
292
|
/* What the tool says or asks: a voice box of this conversation may read it aloud (boxes.mjs). */
|
|
293
|
-
if (event.type === 'agent-said' || event.type === 'agent-asked') this.#spoke(name, event.message?.text ?? '');
|
|
293
|
+
if (event.type === 'agent-said' || event.type === 'agent-asked') this.#spoke(name, event.message?.text ?? '', Array.isArray(event.message?.to) ? event.message.to : null);
|
|
294
294
|
const words = texts(this.#lastLang, this.settings().own);
|
|
295
295
|
if (event.type === 'agent-asked') this.#alert({ title: fill(words['alert-asks'], { name }), body: event.message.text ?? '', url: `/?c=${name}` });
|
|
296
296
|
if (event.type === 'agent-status' && event.message.state === 'waiting') this.#alert({ title: fill(words['alert-waits'], { name }), body: event.message.text ?? '', url: `/?c=${name}` });
|
|
@@ -444,6 +444,9 @@ export class Talk {
|
|
|
444
444
|
return { ...this.of(name), invited: text };
|
|
445
445
|
}
|
|
446
446
|
|
|
447
|
+
/* The voice boxes of a conversation, as Parley names them to its agent and its screen (#215). */
|
|
448
|
+
speakers(name, list) { try { this.#parley(name).setSpeakers(list); } catch { /* its folder is not there yet */ } }
|
|
449
|
+
|
|
447
450
|
async say(name, text, answers, files, via, extra) {
|
|
448
451
|
if (!this.of(name).on) throw new Refusal(409, 'Talking through the app is not turned on for this conversation.');
|
|
449
452
|
const given = files === undefined || files === null ? [] : files;
|
|
@@ -465,7 +468,7 @@ export class Talk {
|
|
|
465
468
|
never lose a message: on any trouble the text is sent as it came. */
|
|
466
469
|
let said = text ?? '';
|
|
467
470
|
if (this.#screen && said) { try { said = await this.#screen(name, said); } catch { said = text ?? ''; } }
|
|
468
|
-
try { this.#parley(name).say(said, answers, attached, { via: via === 'voice' ? 'voice' : undefined, ...(extra && typeof extra === 'object' ? { picked: extra.picked, replies: extra.replies, about: extra.about } : {}) }); } catch (error) { if (error instanceof RangeError) throw new Refusal(400, error.message); throw error; }
|
|
471
|
+
try { this.#parley(name).say(said, answers, attached, { via: via === 'voice' ? 'voice' : undefined, ...(extra && typeof extra === 'object' ? { picked: extra.picked, replies: extra.replies, about: extra.about, by: extra.by } : {}) }); } catch (error) { if (error instanceof RangeError) throw new Refusal(400, error.message); throw error; }
|
|
469
472
|
const told = await this.#wake(name);
|
|
470
473
|
return { ...this.of(name), told };
|
|
471
474
|
}
|
package/web/app.js
CHANGED
|
@@ -5269,6 +5269,8 @@
|
|
|
5269
5269
|
$('map-new-device').addEventListener('click', () => { void openCompose(accessFor ? [[`conversation:${accessFor}`, partsFor(accessFor)]] : []); });
|
|
5270
5270
|
/* Every device and what each was given, by device or by thing: a step over the map. */
|
|
5271
5271
|
$('map-all-devices').addEventListener('click', () => { void openAccessPage('devices'); });
|
|
5272
|
+
/* Voice boxes are on the page of all devices: opened there, at them. */
|
|
5273
|
+
$('map-voice-boxes').addEventListener('click', async () => { await openAccessPage('devices'); $('boxes')?.scrollIntoView({ block: 'start' }); });
|
|
5272
5274
|
$('share-manage-close').addEventListener('click', () => { if (!nav.close('sub')) void openAccessPage('map', { push: false }); });
|
|
5273
5275
|
$('nav-settings').addEventListener('click', () => { if (place !== 'settings') void openSettings(); });
|
|
5274
5276
|
$('access-close').addEventListener('click', () => leavePlace());
|
|
@@ -8799,12 +8801,15 @@
|
|
|
8799
8801
|
async function paintBoxes() {
|
|
8800
8802
|
const list = await getJson('/boxes', []);
|
|
8801
8803
|
const rows = $('box-list'); rows.replaceChildren();
|
|
8804
|
+
const places = el('datalist'); places.id = 'box-places';
|
|
8805
|
+
for (const p of [...new Set(list.map((b) => b.place).filter(Boolean))]) { const o = el('option'); o.value = p; places.append(o); }
|
|
8806
|
+
rows.append(places);
|
|
8802
8807
|
if (!list.length) rows.append(el('p', 'hint', 'No voice box yet.'));
|
|
8803
8808
|
for (const b of list) {
|
|
8804
8809
|
const card = el('div', 'device card box-card'); card.dataset.box = b.id;
|
|
8805
8810
|
const head = el('div', 'device-head');
|
|
8806
8811
|
const conv = conversations.find((c) => c.name === b.conversation);
|
|
8807
|
-
head.append(el('b', '', b.name), el('small', b.online ? '' : 'warn', `${b.online ? 'online' : 'offline'} · ${conv ? shownName(conv) : b.conversation}${b.firmware ? ` · firmware ${b.firmware}` : ''}${b.muted ? ' · muted' : ''}`));
|
|
8812
|
+
head.append(el('b', '', b.place ? `${b.name} \u00b7 ${b.place}` : b.name), el('small', b.online ? '' : 'warn', `${b.online ? 'online' : 'offline'} · ${conv ? shownName(conv) : b.conversation}${b.firmware ? ` · firmware ${b.firmware}` : ''}${b.muted ? ' · muted' : ''}`));
|
|
8808
8813
|
const rename = el('button', '', 'Rename'); rename.type = 'button';
|
|
8809
8814
|
rename.addEventListener('click', () => {
|
|
8810
8815
|
const field = el('input'); field.value = b.name; field.maxLength = 40; field.setAttribute('aria-label', 'Name of this voice box');
|
|
@@ -8816,16 +8821,27 @@
|
|
|
8816
8821
|
});
|
|
8817
8822
|
const remove = el('button', '', 'Remove'); remove.type = 'button';
|
|
8818
8823
|
remove.addEventListener('click', () => takeBack(remove, `Remove ${b.name}: its key stops working now, and it goes back to its setup`, () => post(`${API}/boxes/${b.id}/revoke`)));
|
|
8819
|
-
|
|
8824
|
+
/* Its conversation: where what it hears is said, and whose answers it speaks. Changed here at any time. */
|
|
8825
|
+
const where = el('select'); where.setAttribute('aria-label', `Conversation of ${b.name}`);
|
|
8826
|
+
for (const c of conversations) { const o = el('option', '', shownName(c)); o.value = c.name; where.append(o); }
|
|
8827
|
+
where.value = b.conversation;
|
|
8828
|
+
where.addEventListener('change', async () => { await post(`${API}/boxes/${b.id}/move`, { conversation: where.value }).catch(() => {}); await paintBoxes(); });
|
|
8829
|
+
const whereRow = el('label', 'box-where'); whereRow.append('Speaks in ', where);
|
|
8830
|
+
/* Where it is (a home): typed once, then offered for the next ones. */
|
|
8831
|
+
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}`);
|
|
8832
|
+
place.addEventListener('change', async () => { await post(`${API}/boxes/${b.id}/place`, { place: place.value.trim() }).catch(() => {}); await paintBoxes(); });
|
|
8833
|
+
const acts = el('div', 'action-row'); acts.append(whereRow, place, rename, remove);
|
|
8820
8834
|
card.append(head, acts);
|
|
8821
8835
|
rows.append(card);
|
|
8822
8836
|
}
|
|
8823
8837
|
}
|
|
8824
8838
|
$('box-new').addEventListener('click', () => {
|
|
8825
8839
|
const add = $('box-add'); add.hidden = !add.hidden;
|
|
8840
|
+
/* Which conversation it speaks in: chosen on purpose, never a silent default. */
|
|
8826
8841
|
const pick = $('box-conversation'); pick.replaceChildren();
|
|
8842
|
+
const none = el('option', '', 'Choose a conversation...'); none.value = ''; pick.append(none);
|
|
8827
8843
|
for (const c of conversations) { const o = el('option', '', shownName(c)); o.value = c.name; pick.append(o); }
|
|
8828
|
-
|
|
8844
|
+
pick.value = accessFor && conversations.some((c) => c.name === accessFor) ? accessFor : '';
|
|
8829
8845
|
$('box-ready').hidden = true;
|
|
8830
8846
|
});
|
|
8831
8847
|
$('box-key-copy').addEventListener('click', async () => {
|
|
@@ -8835,12 +8851,13 @@
|
|
|
8835
8851
|
setTimeout(() => { $('box-key-copy').textContent = 'Copy the key'; }, 2000);
|
|
8836
8852
|
});
|
|
8837
8853
|
$('box-code').addEventListener('click', async () => {
|
|
8854
|
+
if (!$('box-conversation').value) { $('box-conversation').focus(); $('box-code-minutes').textContent = 'Choose the conversation it speaks in first.'; $('box-ready').hidden = false; return; }
|
|
8838
8855
|
try {
|
|
8839
|
-
const r = await post(`${API}/boxes/code`, { conversation: $('box-conversation').value, name: $('box-room').value.trim() });
|
|
8856
|
+
const r = await post(`${API}/boxes/code`, { conversation: $('box-conversation').value, name: $('box-room').value.trim(), origin: location.origin });
|
|
8840
8857
|
$('box-code-shown').textContent = r.code; $('box-code-minutes').textContent = `valid ${r.minutes} minutes, once`;
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
$('box-
|
|
8858
|
+
$('box-key').textContent = r.key ?? '';
|
|
8859
|
+
$('box-link').href = r.link ?? '#';
|
|
8860
|
+
$('box-qr').innerHTML = r.qr ?? '';
|
|
8844
8861
|
$('box-ready').hidden = false;
|
|
8845
8862
|
} catch (error) { $('box-code-minutes').textContent = error.message; $('box-ready').hidden = false; }
|
|
8846
8863
|
});
|
package/web/index.html
CHANGED
|
@@ -379,6 +379,7 @@
|
|
|
379
379
|
</div>
|
|
380
380
|
<label class="lk-switch"><input type="checkbox" id="links-all"> All links at once</label>
|
|
381
381
|
<button type="button" id="map-all-devices" class="as-link">All devices</button>
|
|
382
|
+
<button type="button" id="map-voice-boxes" class="as-link">Voice boxes</button>
|
|
382
383
|
<button type="button" id="map-new-device">+ New device</button>
|
|
383
384
|
</div>
|
|
384
385
|
<!-- THE MAP (once "Who gets what"): every device, conversation and asset, and the rights between them (links.js). -->
|
|
@@ -462,10 +463,10 @@
|
|
|
462
463
|
<button type="button" id="box-code" class="primary">Get a code</button>
|
|
463
464
|
</div>
|
|
464
465
|
<div id="box-ready" hidden>
|
|
465
|
-
<p
|
|
466
|
-
<div class="row"><
|
|
467
|
-
<
|
|
468
|
-
<p class="hint">
|
|
466
|
+
<p class="hint">Phone on the box's Wi-Fi « Gambeli-… »: open this link, or scan the code. Its page opens filled in; choose your Wi-Fi. <span id="box-code-minutes"></span></p>
|
|
467
|
+
<div class="row box-setup"><div id="box-qr" class="box-qr"></div><a id="box-link" class="primary button-link" href="#">Open the box's page</a></div>
|
|
468
|
+
<div class="row"><code id="box-key" class="box-key"></code><button type="button" id="box-key-copy">Copy the key</button></div>
|
|
469
|
+
<p class="hint">Pairing code alone: <b id="box-code-shown"></b></p>
|
|
469
470
|
</div>
|
|
470
471
|
</div>
|
|
471
472
|
<div id="box-list"></div>
|
package/web/style.css
CHANGED
|
@@ -2071,3 +2071,7 @@ body.as-dragging #assets-rows .as-row { touch-action: none; }
|
|
|
2071
2071
|
.job-panel .tether-flash-extra { display: grid; gap: 8px; }
|
|
2072
2072
|
.job-panel .tether-flash-bad { color: var(--bad, #ff8a80); }
|
|
2073
2073
|
.box-key { overflow-wrap: anywhere; font-size: .8rem; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; user-select: all; flex: 1 1 260px; min-width: 0; }
|
|
2074
|
+
.box-setup { align-items: center; gap: 14px; flex-wrap: wrap; }
|
|
2075
|
+
.box-qr { width: 180px; max-width: 100%; background: #fff; border-radius: 8px; padding: 6px; }
|
|
2076
|
+
.box-qr svg { display: block; width: 100%; height: auto; }
|
|
2077
|
+
.button-link { display: inline-block; padding: 8px 12px; border-radius: 7px; background: var(--accent, #d4a64a); color: #111; font-weight: 600; text-decoration: none; }
|