telemersive-bus 0.6.17 → 0.6.19
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/lib/BusManager.js +18 -5
- package/lib/utils/Peer.js +1 -1
- package/lib/utils/getPublicIp.js +43 -0
- package/package.json +3 -4
package/lib/BusManager.js
CHANGED
|
@@ -16,6 +16,11 @@ const houseKeepingTimeOut = 1500;
|
|
|
16
16
|
const houseKeepingTimeOut_onRepeat = 1500;
|
|
17
17
|
const houseKeepingTimeOut_onPeerLeft= 1000;
|
|
18
18
|
const houseKeepingTimeOut_onPeerJoined = 5000;
|
|
19
|
+
// time to wait after sending DELETE requests to the switchboard before the room entry is
|
|
20
|
+
// removed from this.rooms. proxy processes need a moment to fully exit and release their
|
|
21
|
+
// OS ports — without this delay a room restart races against a still-dying proxy and fails
|
|
22
|
+
// to bind the same port.
|
|
23
|
+
const proxyShutdownSettleTime = 3000;
|
|
19
24
|
const ROOM_ID_MIN = 11;
|
|
20
25
|
const ROOM_ID_MAX = 50;
|
|
21
26
|
|
|
@@ -753,6 +758,9 @@ class BusManager {
|
|
|
753
758
|
console.error(` ...: ${err}. Interrupting process of stopping open stage control instance on port ${_roomId * 1000 + 900}.`);
|
|
754
759
|
}
|
|
755
760
|
console.log(` <- stopped all ports for room ${_roomName}`);
|
|
761
|
+
// wait for proxy processes to fully exit and release OS ports before allowing
|
|
762
|
+
// the room to be recreated. without this, a restart races against dying proxies.
|
|
763
|
+
await new Promise(resolve => setTimeout(resolve, proxyShutdownSettleTime));
|
|
756
764
|
delete this.rooms[_roomName];
|
|
757
765
|
console.log(` <- removed room ${_roomName}`);
|
|
758
766
|
}else {
|
|
@@ -771,9 +779,11 @@ class BusManager {
|
|
|
771
779
|
});
|
|
772
780
|
//let reply = JSON.parse(res["text"]);
|
|
773
781
|
} catch (err) {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
782
|
+
if (err.response?.text) {
|
|
783
|
+
let reply = JSON.parse(err.response["text"]);
|
|
784
|
+
throw new Error(reply["msg"]);
|
|
785
|
+
}
|
|
786
|
+
throw err;
|
|
777
787
|
}
|
|
778
788
|
}
|
|
779
789
|
|
|
@@ -786,8 +796,11 @@ class BusManager {
|
|
|
786
796
|
});
|
|
787
797
|
//let reply = JSON.parse(res["text"]);
|
|
788
798
|
} catch (err) {
|
|
789
|
-
|
|
790
|
-
|
|
799
|
+
if (err.response?.text) {
|
|
800
|
+
let reply = JSON.parse(err.response["text"]);
|
|
801
|
+
throw new Error(reply["msg"]);
|
|
802
|
+
}
|
|
803
|
+
throw err;
|
|
791
804
|
}
|
|
792
805
|
}
|
|
793
806
|
|
package/lib/utils/Peer.js
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
|
|
3
|
+
const SERVICES = [
|
|
4
|
+
'https://api.ipify.org',
|
|
5
|
+
'https://ipv4.icanhazip.com',
|
|
6
|
+
'https://api.seeip.org',
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
const IPV4_RE = /^(?:\d{1,3}\.){3}\d{1,3}$/;
|
|
10
|
+
|
|
11
|
+
function fetchText(url, timeoutMs) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const req = https.get(url, (res) => {
|
|
14
|
+
if (res.statusCode !== 200) {
|
|
15
|
+
res.resume();
|
|
16
|
+
reject(new Error(`HTTP ${res.statusCode} from ${url}`));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let data = '';
|
|
20
|
+
res.setEncoding('utf8');
|
|
21
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
22
|
+
res.on('end', () => resolve(data.trim()));
|
|
23
|
+
});
|
|
24
|
+
req.setTimeout(timeoutMs, () => req.destroy(new Error(`timeout ${url}`)));
|
|
25
|
+
req.on('error', reject);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function v4({ timeout = 5000 } = {}) {
|
|
30
|
+
let lastErr;
|
|
31
|
+
for (const url of SERVICES) {
|
|
32
|
+
try {
|
|
33
|
+
const ip = await fetchText(url, timeout);
|
|
34
|
+
if (IPV4_RE.test(ip)) return ip;
|
|
35
|
+
lastErr = new Error(`invalid IPv4 from ${url}: ${ip}`);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
lastErr = err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
throw lastErr || new Error('public IP lookup failed');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = { v4 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "telemersive-bus",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.19",
|
|
4
4
|
"description": "MQTT based data protocol to manage unlimited peers, connected by rooms, where all peers joined to a room can exchange private data. It provides a simple chat mechanism, latency pinging, publish-subscribe mechanism (based on mqtt) and a OSC-like data stream. ",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -9,14 +9,13 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"async-mqtt": "^2.6.1",
|
|
11
11
|
"crypto-js": "^4.0.0",
|
|
12
|
+
"get-internal-ip": "^3.0.0",
|
|
12
13
|
"internal-ip": "^6.2.0",
|
|
13
14
|
"mqtt": "^5.3.5",
|
|
14
15
|
"protobufjs": "^7.5.5",
|
|
15
|
-
"public-ip": "^4.0.2",
|
|
16
16
|
"sha1": "^1.1.1",
|
|
17
17
|
"short-uuid": "^4.1.0",
|
|
18
|
-
"superagent": "^6.1.0"
|
|
19
|
-
"get-internal-ip": "^3.0.0"
|
|
18
|
+
"superagent": "^6.1.0"
|
|
20
19
|
},
|
|
21
20
|
"scripts": {
|
|
22
21
|
"test": "echo \"Error: no test specified\" && exit 1"
|