matterbridge 2.1.6-dev.5 → 2.1.6-dev.7

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.
@@ -0,0 +1,143 @@
1
+ import os from 'node:os';
2
+ import { AnsiLogger, idn, rs } from '../logger/export.js';
3
+ export function getIpv4InterfaceAddress() {
4
+ let ipv4Address;
5
+ const networkInterfaces = os.networkInterfaces();
6
+ for (const interfaceDetails of Object.values(networkInterfaces)) {
7
+ if (!interfaceDetails) {
8
+ break;
9
+ }
10
+ for (const detail of interfaceDetails) {
11
+ if (detail.family === 'IPv4' && !detail.internal && ipv4Address === undefined) {
12
+ ipv4Address = detail.address;
13
+ }
14
+ }
15
+ if (ipv4Address !== undefined) {
16
+ break;
17
+ }
18
+ }
19
+ return ipv4Address;
20
+ }
21
+ export function getIpv6InterfaceAddress() {
22
+ let ipv6Address;
23
+ const networkInterfaces = os.networkInterfaces();
24
+ for (const interfaceDetails of Object.values(networkInterfaces)) {
25
+ if (!interfaceDetails) {
26
+ break;
27
+ }
28
+ for (const detail of interfaceDetails) {
29
+ if (detail.family === 'IPv6' && !detail.internal && ipv6Address === undefined) {
30
+ ipv6Address = detail.address;
31
+ }
32
+ }
33
+ if (ipv6Address !== undefined) {
34
+ break;
35
+ }
36
+ }
37
+ return ipv6Address;
38
+ }
39
+ export function getMacAddress() {
40
+ let macAddress;
41
+ const networkInterfaces = os.networkInterfaces();
42
+ for (const interfaceDetails of Object.values(networkInterfaces)) {
43
+ if (!interfaceDetails) {
44
+ break;
45
+ }
46
+ for (const detail of interfaceDetails) {
47
+ if (detail.family === 'IPv6' && !detail.internal && macAddress === undefined) {
48
+ macAddress = detail.mac;
49
+ }
50
+ }
51
+ if (macAddress !== undefined) {
52
+ break;
53
+ }
54
+ }
55
+ return macAddress;
56
+ }
57
+ export function logInterfaces(debug = true) {
58
+ const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
59
+ log.logLevel = "info";
60
+ log.logName = 'LogInterfaces';
61
+ let ipv6Address;
62
+ const networkInterfaces = os.networkInterfaces();
63
+ if (debug)
64
+ log.info('Available Network Interfaces:');
65
+ for (const [interfaceName, networkInterface] of Object.entries(networkInterfaces)) {
66
+ if (!networkInterface)
67
+ break;
68
+ if (debug)
69
+ log.info(`Interface: ${idn}${interfaceName}${rs}`);
70
+ for (const detail of networkInterface) {
71
+ if (debug)
72
+ log.info('Details:', detail);
73
+ }
74
+ }
75
+ return ipv6Address;
76
+ }
77
+ export async function resolveHostname(hostname, family = 4) {
78
+ const dns = await import('node:dns');
79
+ try {
80
+ const addresses = await dns.promises.lookup(hostname.toLowerCase(), { family });
81
+ return addresses.address;
82
+ }
83
+ catch (error) {
84
+ return null;
85
+ }
86
+ }
87
+ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 5000) {
88
+ const https = await import('https');
89
+ return new Promise((resolve, reject) => {
90
+ const url = `https://registry.npmjs.org/${packageName}`;
91
+ const controller = new AbortController();
92
+ const timeoutId = setTimeout(() => {
93
+ controller.abort();
94
+ reject(new Error(`Request timed out after ${timeout / 1000} seconds`));
95
+ }, timeout);
96
+ const req = https.get(url, { signal: controller.signal }, (res) => {
97
+ let data = '';
98
+ if (res.statusCode !== 200) {
99
+ clearTimeout(timeoutId);
100
+ res.resume();
101
+ req.destroy();
102
+ reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
103
+ return;
104
+ }
105
+ res.on('data', (chunk) => {
106
+ data += chunk;
107
+ });
108
+ res.on('end', () => {
109
+ clearTimeout(timeoutId);
110
+ try {
111
+ const jsonData = JSON.parse(data);
112
+ const version = jsonData['dist-tags']?.[tag];
113
+ if (version) {
114
+ resolve(version);
115
+ }
116
+ else {
117
+ reject(new Error(`Tag "${tag}" not found for package "${packageName}"`));
118
+ }
119
+ }
120
+ catch (error) {
121
+ reject(new Error(`Failed to parse response JSON: ${error instanceof Error ? error.message : error}`));
122
+ }
123
+ });
124
+ });
125
+ req.on('error', (error) => {
126
+ clearTimeout(timeoutId);
127
+ reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
128
+ });
129
+ });
130
+ }
131
+ export async function getGlobalNodeModules() {
132
+ const { exec } = await import('node:child_process');
133
+ return new Promise((resolve, reject) => {
134
+ exec('npm root -g', (error, stdout) => {
135
+ if (error) {
136
+ reject(error);
137
+ }
138
+ else {
139
+ resolve(stdout.trim());
140
+ }
141
+ });
142
+ });
143
+ }
@@ -0,0 +1,57 @@
1
+ import { AnsiLogger } from '../logger/export.js';
2
+ const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
3
+ export async function waiter(name, check, exitWithReject = false, resolveTimeout = 5000, resolveInterval = 500, debug = false) {
4
+ log.logLevel = "debug";
5
+ log.logName = 'Waiter';
6
+ if (debug)
7
+ log.debug(`Waiter "${name}" started...`);
8
+ return new Promise((resolve, reject) => {
9
+ const timeoutId = setTimeout(() => {
10
+ if (debug)
11
+ log.debug(`Waiter "${name}" finished for timeout...`);
12
+ clearTimeout(timeoutId);
13
+ clearInterval(intervalId);
14
+ if (exitWithReject)
15
+ reject(new Error(`Waiter "${name}" finished due to timeout`));
16
+ else
17
+ resolve(false);
18
+ }, resolveTimeout);
19
+ const intervalId = setInterval(() => {
20
+ if (check()) {
21
+ if (debug)
22
+ log.debug(`Waiter "${name}" finished for true condition...`);
23
+ clearTimeout(timeoutId);
24
+ clearInterval(intervalId);
25
+ resolve(true);
26
+ }
27
+ }, resolveInterval);
28
+ });
29
+ }
30
+ export async function wait(timeout = 1000, name, debug = false) {
31
+ log.logLevel = "debug";
32
+ log.logName = 'Wait';
33
+ if (debug)
34
+ log.debug(`Wait "${name}" started...`);
35
+ return new Promise((resolve, reject) => {
36
+ const timeoutId = setTimeout(() => {
37
+ if (debug)
38
+ log.debug(`Wait "${name}" finished...`);
39
+ clearTimeout(timeoutId);
40
+ resolve();
41
+ }, timeout);
42
+ });
43
+ }
44
+ export function withTimeout(promise, ms) {
45
+ return new Promise((resolve, reject) => {
46
+ const timer = setTimeout(() => reject(new Error('Operation timed out')), ms);
47
+ promise
48
+ .then((result) => {
49
+ clearTimeout(timer);
50
+ resolve(result);
51
+ })
52
+ .catch((error) => {
53
+ clearTimeout(timer);
54
+ reject(error);
55
+ });
56
+ });
57
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "./static/css/main.cf25d33e.css",
4
- "main.js": "./static/js/main.be75f5a3.js",
4
+ "main.js": "./static/js/main.82e3eb54.js",
5
5
  "static/js/453.abd36b29.chunk.js": "./static/js/453.abd36b29.chunk.js",
6
6
  "static/media/roboto-latin-700-normal.woff2": "./static/media/roboto-latin-700-normal.4535474e1cf8598695ad.woff2",
7
7
  "static/media/roboto-latin-500-normal.woff2": "./static/media/roboto-latin-500-normal.7077203b1982951ecf76.woff2",
@@ -61,11 +61,11 @@
61
61
  "static/media/roboto-greek-ext-400-normal.woff": "./static/media/roboto-greek-ext-400-normal.16eb83b4a3b1ea994243.woff",
62
62
  "index.html": "./index.html",
63
63
  "main.cf25d33e.css.map": "./static/css/main.cf25d33e.css.map",
64
- "main.be75f5a3.js.map": "./static/js/main.be75f5a3.js.map",
64
+ "main.82e3eb54.js.map": "./static/js/main.82e3eb54.js.map",
65
65
  "453.abd36b29.chunk.js.map": "./static/js/453.abd36b29.chunk.js.map"
66
66
  },
67
67
  "entrypoints": [
68
68
  "static/css/main.cf25d33e.css",
69
- "static/js/main.be75f5a3.js"
69
+ "static/js/main.82e3eb54.js"
70
70
  ]
71
71
  }
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.be75f5a3.js"></script><link href="./static/css/main.cf25d33e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.82e3eb54.js"></script><link href="./static/css/main.cf25d33e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>