Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/lib/node_modules/homebridge-camera-ui/server/services/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use-strict';
const logger = require('../../services/logger/logger.service.js');
const ping = require('ping');
class Ping {
getHost(videoConfig) {
let protocol = videoConfig.source.split('-i ')[1].split('://')[0] + '://';
let host = videoConfig.source.split(protocol)[1];
let port;
host = host.includes('@') ? host.split('@')[1].split('/')[0] : host.split('/')[0];
if (host.includes(':')) {
port = host.split(':')[1];
port = port.includes('/') ? port.split('/')[0] : port;
host = host.split(':')[0];
}
return {
protocol: protocol,
host: host,
port: port,
};
}
async status(videoConfig, timeout = 1) {
const cameraSource = videoConfig.source;
if (!cameraSource.split('-i ')[1]) {
return false;
}
logger.debug(`Incoming ping request for: ${cameraSource.split('-i ')[1]} - Timeout: ${timeout}s`, false, true);
//for local cameras eg "-i /dev/video0"
if (cameraSource.split('-i ')[1].startsWith('/')) {
return true;
}
const addresse = this.getHost(videoConfig);
const protocol = addresse.protocol;
const host = addresse.host;
const port = addresse.port;
logger.debug(`Pinging ${protocol}${host}${port ? ':' + port : ''}`, false, true);
const response = await ping.promise.probe(host, {
timeout: timeout || 1,
extra: ['-i', '2'],
});
let available = response && response.alive;
return available;
}
}
module.exports = new Ping();
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0639 ]-- |