mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-06-24 21:25:23 +00:00
Fixing hostname detection on Raspberry PI
This commit is contained in:
parent
849988634d
commit
fcf13b1fe5
1 changed files with 28 additions and 3 deletions
|
@ -1,9 +1,11 @@
|
|||
import mdns = require('mdns-js');
|
||||
import mdns from 'mdns-js';
|
||||
const cp = require('child_process');
|
||||
const os = require('os');
|
||||
|
||||
export class DiscoveryService {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private serviceTcp: any;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private serviceWs: any;
|
||||
|
||||
private static getComputerName() {
|
||||
|
@ -12,8 +14,31 @@ export class DiscoveryService {
|
|||
return process.env.COMPUTERNAME;
|
||||
case "darwin":
|
||||
return cp.execSync("scutil --get ComputerName").toString().trim();
|
||||
case "linux":
|
||||
return os.hostname();
|
||||
case "linux": {
|
||||
let hostname: string;
|
||||
|
||||
// Some distro's don't work with `os.hostname()`, but work with `hostnamectl` and vice versa...
|
||||
try {
|
||||
hostname = os.hostname();
|
||||
}
|
||||
catch (err) {
|
||||
console.warn('Error fetching hostname, trying different method...');
|
||||
console.warn(err);
|
||||
|
||||
try {
|
||||
hostname = cp.execSync("hostnamectl hostname").toString().trim();
|
||||
}
|
||||
catch (err2) {
|
||||
console.warn('Error fetching hostname again, using generic name...');
|
||||
console.warn(err2);
|
||||
|
||||
hostname = 'linux device';
|
||||
}
|
||||
}
|
||||
|
||||
return hostname;
|
||||
}
|
||||
|
||||
default:
|
||||
return os.hostname();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue