sharerare 0.1.0 → 0.1.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/cli/sharerare.js +27 -4
- package/package.json +1 -1
package/cli/sharerare.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// public/js/mesh.js), so files travel directly between devices. Nothing is
|
|
5
5
|
// uploaded.
|
|
6
6
|
|
|
7
|
+
import { execFileSync } from 'node:child_process';
|
|
7
8
|
import fs from 'node:fs';
|
|
8
9
|
import os from 'node:os';
|
|
9
10
|
import path from 'node:path';
|
|
@@ -132,7 +133,22 @@ if (opt.pair && !['send', 'note'].includes(command)) fail('--pair works with sen
|
|
|
132
133
|
if (opt.hidden && !code && !opt.pair) fail('--hidden needs --code or --pair, otherwise no device could find this one.', 2);
|
|
133
134
|
if (zipName !== null && command !== 'get') fail('--zip works with get.', 2);
|
|
134
135
|
const waitMs = Math.max(2, Number(opt.wait) || 15) * 1000;
|
|
135
|
-
const myName = (opt.name ||
|
|
136
|
+
const myName = (opt.name || defaultName()).slice(0, 40);
|
|
137
|
+
|
|
138
|
+
// The name people know this computer by, plus "Terminal" so it can be told
|
|
139
|
+
// apart from a browser tab on the same machine. The host name alone can be an
|
|
140
|
+
// IP address (macOS sets it from the network when none is configured).
|
|
141
|
+
function defaultName() {
|
|
142
|
+
let name = '';
|
|
143
|
+
try {
|
|
144
|
+
if (process.platform === 'darwin') name = execFileSync('scutil', ['--get', 'ComputerName'], { encoding: 'utf8', timeout: 1500, stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
145
|
+
else if (process.platform === 'win32') name = process.env.COMPUTERNAME || '';
|
|
146
|
+
} catch {}
|
|
147
|
+
if (!name) name = os.hostname().replace(/\.(local|lan|home)$/i, '');
|
|
148
|
+
const looksLikeAddress = /^[\d.]+$|^[0-9a-f:]+$/i.test(name) || /^localhost$/i.test(name);
|
|
149
|
+
if (!name || looksLikeAddress) name = { darwin: 'Mac', win32: 'Windows PC', linux: 'Linux' }[process.platform] || 'Computer';
|
|
150
|
+
return `${name.slice(0, 28)} · Terminal`;
|
|
151
|
+
}
|
|
136
152
|
const myCode = opt.pair ? randomCode() : null;
|
|
137
153
|
|
|
138
154
|
// ---------- the mesh ----------
|
|
@@ -440,19 +456,26 @@ async function share() {
|
|
|
440
456
|
// Listen before joining: on a fast local network a link can be up before
|
|
441
457
|
// start() returns.
|
|
442
458
|
const known = new Map(); // peer id -> last state we printed
|
|
459
|
+
const names = new Map(); // peer id -> name, kept for the "left" line
|
|
443
460
|
mesh.addEventListener('peers', () => {
|
|
444
461
|
for (const peer of mesh.peers.values()) {
|
|
445
462
|
const state = peer.state === 'connected' && !peer.hello ? 'connecting' : peer.state;
|
|
446
463
|
const shown = `${state}:${peer.route || ''}`;
|
|
447
464
|
if (known.get(peer.id) === shown) continue;
|
|
448
465
|
known.set(peer.id, shown);
|
|
449
|
-
if (state === 'connected')
|
|
450
|
-
|
|
466
|
+
if (state === 'connected') {
|
|
467
|
+
names.set(peer.id, peerName(peer));
|
|
468
|
+
logLink(`● ${peerName(peer)} linked${peer.route === 'internet' ? ' over the internet' : ''}`);
|
|
469
|
+
} else if (state === 'unreachable' && (peer.linked || mesh.paired(peer))) {
|
|
470
|
+
logLink(`○ can't reach ${peer.hello ? peerName(peer) : 'a paired device'} directly right now (asleep, or on another network?)`);
|
|
471
|
+
}
|
|
451
472
|
}
|
|
452
473
|
for (const [id, shown] of known) {
|
|
453
474
|
if (mesh.peers.has(id)) continue;
|
|
454
475
|
known.delete(id);
|
|
455
|
-
|
|
476
|
+
// Phones drop the link whenever the browser goes to the background or
|
|
477
|
+
// the page is opened again; it comes back by itself.
|
|
478
|
+
if (shown.startsWith('connected')) logLink(`○ ${names.get(id) || 'a device'} left (closed, reloaded or in the background)`);
|
|
456
479
|
}
|
|
457
480
|
});
|
|
458
481
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sharerare",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Send files between devices on the same network, from the terminal. Direct, device to device: the files never touch a server. Works with the Sharerare web app.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"file-sharing",
|