mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-06-24 21:25:23 +00:00
Receivers: Reworked network interface UI
This commit is contained in:
parent
ed89b61cab
commit
28a617daa7
15 changed files with 491 additions and 246 deletions
|
@ -5,6 +5,7 @@ import * as url from 'url';
|
|||
import { AddressInfo } from 'modules/ws';
|
||||
import { v4 as uuidv4 } from 'modules/uuid';
|
||||
import { Main } from 'src/Main';
|
||||
import si from 'modules/systeminformation';
|
||||
|
||||
export class NetworkService {
|
||||
static key: string = null;
|
||||
|
@ -12,6 +13,8 @@ export class NetworkService {
|
|||
static proxyServer: http.Server;
|
||||
static proxyServerAddress: AddressInfo;
|
||||
static proxiedFiles: Map<string, { url: string, headers: { [key: string]: string } }> = new Map();
|
||||
static networkStateChangeListenerTimeout = 2500;
|
||||
private static networkStateChangeListenerInterfaces = [];
|
||||
|
||||
private static setupProxyServer(): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
|
@ -104,21 +107,54 @@ export class NetworkService {
|
|||
return proxiedUrl;
|
||||
}
|
||||
|
||||
static getAllIPv4Addresses() {
|
||||
const interfaces = os.networkInterfaces();
|
||||
const ipv4Addresses: string[] = [];
|
||||
static async networkStateChangeListener(forceUpdate: boolean, networkChangedCb: (networkInfo: any) => void) {
|
||||
const queriedInterfaces: si.Systeminformation.NetworkInterfacesData[] = await new Promise<si.Systeminformation.NetworkInterfacesData[]>((resolve, reject) => {
|
||||
si.networkInterfaces((data) => {
|
||||
// console.log(data);
|
||||
|
||||
for (const interfaceName in interfaces) {
|
||||
const addresses = interfaces[interfaceName];
|
||||
if (!addresses) continue;
|
||||
if (Array.isArray(data)) {
|
||||
resolve(data);
|
||||
}
|
||||
else {
|
||||
resolve([data]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
for (const addressInfo of addresses) {
|
||||
if (addressInfo.family === 'IPv4' && !addressInfo.internal) {
|
||||
ipv4Addresses.push(addressInfo.address);
|
||||
const wifiConnections: si.Systeminformation.WifiConnectionData[] = await new Promise<si.Systeminformation.WifiConnectionData[]>((resolve, reject) => {
|
||||
si.wifiConnections((data) => {
|
||||
// console.log(data);
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
resolve(data);
|
||||
}
|
||||
else {
|
||||
resolve([data]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const interfaces = [];
|
||||
for (const iface of queriedInterfaces) {
|
||||
if (iface.ip4 !== '' && !iface.internal && !iface.virtual) {
|
||||
const isWireless = wifiConnections.some(e => {
|
||||
if (e.iface === iface.iface) {
|
||||
interfaces.push({ type: 'wireless', name: e.ssid, address: iface.ip4, signalLevel: e.quality });
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (!isWireless) {
|
||||
interfaces.push({ type: 'wired', name: iface.ifaceName, address: iface.ip4 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ipv4Addresses;
|
||||
if (forceUpdate || (JSON.stringify(interfaces) !== JSON.stringify(NetworkService.networkStateChangeListenerInterfaces))) {
|
||||
NetworkService.networkStateChangeListenerInterfaces = interfaces;
|
||||
networkChangedCb(interfaces);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue