telemersive-bus 0.6.18 → 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/utils/Peer.js CHANGED
@@ -1,4 +1,4 @@
1
- const publicIp = require('public-ip');
1
+ const publicIp = require('./getPublicIp');
2
2
  const internalIp = require('internal-ip');
3
3
  const getInternalIP = require("get-internal-ip");
4
4
  const sha1 = require("sha1");
@@ -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.18",
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"