nio-cat 0.3.3 → 0.3.5
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/bin/nio.js +5 -2
- package/package.json +1 -1
- package/src/config.js +1 -0
- package/src/server.js +1 -0
- package/web/app/app.js +13 -3
package/bin/nio.js
CHANGED
|
@@ -76,8 +76,10 @@ function canOpenBrowser() {
|
|
|
76
76
|
|
|
77
77
|
function openDashboard() {
|
|
78
78
|
const local = `http://127.0.0.1:${cfg.port}`;
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
// Per defecte s'obre l'app en línia (sempre al dia), ja connectada a aquest ordinador. Amb --local, la còpia que porta nio.
|
|
80
|
+
const online = !flags.local;
|
|
81
|
+
const link = pairLink(online ? flags.app || cfg.app : local, local, cfg.token);
|
|
82
|
+
if (canOpenBrowser() && openUrl(link)) console.log(` ${c.dim('Panell:')} ${online ? (flags.app || cfg.app) + '/app' : local} ${c.dim('(obert al navegador; --no-open per evitar-ho' + (online ? '; --local per fer servir la còpia d\'aquest ordinador' : '') + ')')}`);
|
|
81
83
|
else console.log(` ${c.dim('Panell:')} ${link}`);
|
|
82
84
|
}
|
|
83
85
|
|
|
@@ -288,6 +290,7 @@ async function start() {
|
|
|
288
290
|
--no-tunnel Només des d'aquest ordinador
|
|
289
291
|
--port <n> Port local (7717 si no dius res)
|
|
290
292
|
--no-open No obris el panell al navegador d'aquest ordinador
|
|
293
|
+
--local Obre la còpia del panell d'aquest ordinador (si el navegador bloqueja nio.cat, p. ex. Safari)
|
|
291
294
|
--open Obre al navegador la pàgina del codi QR
|
|
292
295
|
nio pair Mostra el codi QR una altra vegada
|
|
293
296
|
|
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -37,6 +37,7 @@ function load() {
|
|
|
37
37
|
}
|
|
38
38
|
cfg = { ...DEFAULTS, ...cfg };
|
|
39
39
|
if (!cfg.token) cfg.token = crypto.randomBytes(24).toString('base64url');
|
|
40
|
+
if (!cfg.id) cfg.id = crypto.randomBytes(8).toString('hex'); // identifica aquest ordinador, sigui quina sigui l'adreça
|
|
40
41
|
if (!cfg.vapid) cfg.vapid = makeVapid();
|
|
41
42
|
save(cfg);
|
|
42
43
|
return cfg;
|
package/src/server.js
CHANGED
|
@@ -169,6 +169,7 @@ function createServer({ cfg, hub, getPublicUrl, getApp }) {
|
|
|
169
169
|
agents: await detectAll(cfg, url.searchParams.has('refresh')),
|
|
170
170
|
roots: cfg.roots,
|
|
171
171
|
vapidKey: cfg.vapid.publicKey,
|
|
172
|
+
id: cfg.id,
|
|
172
173
|
};
|
|
173
174
|
}
|
|
174
175
|
if (p === '/api/projects' && method === 'GET') return listProjects(cfg);
|
package/web/app/app.js
CHANGED
|
@@ -125,7 +125,7 @@ async function connect() {
|
|
|
125
125
|
if (res.status === 401) throw Object.assign(new Error('La clau no és vàlida. Torna a connectar amb el codi QR.'), { fatal: true });
|
|
126
126
|
if (!res.ok || !res.body) throw new Error(`Error ${res.status}`);
|
|
127
127
|
state.connected = true; state.lastError = null; retry = 0;
|
|
128
|
-
renameMachine(state.info.host); syncServiceWorker(); render(); brainsForBoard();
|
|
128
|
+
renameMachine(state.info.host, state.info.id); syncServiceWorker(); render(); brainsForBoard();
|
|
129
129
|
const reader = res.body.getReader(), dec = new TextDecoder(); let buf = '';
|
|
130
130
|
for (;;) {
|
|
131
131
|
const { value, done } = await reader.read(); if (done) break;
|
|
@@ -140,13 +140,23 @@ async function connect() {
|
|
|
140
140
|
} catch (e) {
|
|
141
141
|
if (ctrl.signal.aborted) return;
|
|
142
142
|
state.connected = false;
|
|
143
|
-
state.lastError = e.message === 'Failed to fetch' || e.name === 'TypeError' ? 'No arribo a l’ordinador' : e.message;
|
|
143
|
+
state.lastError = e.message === 'Failed to fetch' || e.name === 'TypeError' ? (location.protocol === 'https:' && /^http:\/\/(127\.0\.0\.1|localhost)/.test(m.url) ? 'El navegador no deixa que aquesta web parli amb aquest ordinador. Prova Chrome, o engega nio amb --local.' : 'No arribo a l’ordinador') : e.message;
|
|
144
144
|
render();
|
|
145
145
|
if (e.fatal) return;
|
|
146
146
|
setTimeout(() => machine() && !ctrl.signal.aborted && connect(), Math.min(15000, 1000 * 2 ** retry++));
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
|
|
149
|
+
// Posa nom i identificador a l'ordinador actiu i fusiona els duplicats (el mateix ordinador desat amb dues adreces: wifi i 127.0.0.1).
|
|
150
|
+
function renameMachine(host, id) {
|
|
151
|
+
let ms = store.machines; const cur = ms[store.active]; if (!cur) return;
|
|
152
|
+
if (host) cur.name = host;
|
|
153
|
+
if (id) {
|
|
154
|
+
cur.id = id;
|
|
155
|
+
const keep = cur.url, list = ms.filter((m) => m === cur || m.id !== id);
|
|
156
|
+
if (list.length !== ms.length) { ms = list; store.active = ms.findIndex((m) => m.url === keep); }
|
|
157
|
+
}
|
|
158
|
+
store.machines = ms;
|
|
159
|
+
}
|
|
150
160
|
|
|
151
161
|
function handle(msg) {
|
|
152
162
|
const r = state.route;
|