mirror of
https://github.com/tsightler/ring-mqtt.git
synced 2025-10-16 22:00:38 +08:00
Release 5.1.0 (#537)
* Use MQTT for start-stream debug messages * Fix ANSI colors * Refactor event URL management * Fix subscription detection * Improve event URL expiry handling by parsing Amazon S3 expire time * Convert to ESM/replace colors with chalk * Force colors for chalk * Migrate to ESM * Fix stop of keepalive stream * Add transcoded event selections * Update event URL on raw/trancoded toggle * Switch to per-camera livecall threads * Customized WebRTC functions Mostly copied from ring-client-api with port to pure Javascript, removal of unneeded features and additional debugging modified for use as worker thread with ring-mqtt. Allows easier testing with updated Werift versions. * Add nightlight enable/disable * Include nightlight state as attribute * Only pro versions have nightlight * Tweak battery level reporting for dual battery cameras * Release 5.1.0
This commit is contained in:
44
lib/utils.js
44
lib/utils.js
@@ -1,20 +1,28 @@
|
||||
import config from './config.js'
|
||||
import dns from 'dns'
|
||||
import os from 'os'
|
||||
import fs from 'fs'
|
||||
import { promisify } from 'util'
|
||||
import { execSync } from 'child_process'
|
||||
import { EventEmitter } from 'events'
|
||||
import debugModule from 'debug'
|
||||
const debug = {
|
||||
mqtt: require('debug')('ring-mqtt'),
|
||||
attr: require('debug')('ring-attr'),
|
||||
disc: require('debug')('ring-disc')
|
||||
mqtt: debugModule('ring-mqtt'),
|
||||
attr: debugModule('ring-attr'),
|
||||
disc: debugModule('ring-disc'),
|
||||
rtsp: debugModule('ring-rtsp'),
|
||||
wrtc: debugModule('ring-wrtc')
|
||||
}
|
||||
const config = require('./config')
|
||||
const dns = require('dns')
|
||||
const os = require('os')
|
||||
const fs = require('fs')
|
||||
const execSync = require('child_process').execSync
|
||||
const { promisify } = require('util')
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
|
||||
class Utils {
|
||||
// Define a few helper variables for sharing
|
||||
event = new EventEmitter()
|
||||
config = config.data
|
||||
export default new class Utils {
|
||||
|
||||
constructor() {
|
||||
this.event = new EventEmitter()
|
||||
}
|
||||
|
||||
config() {
|
||||
return config.data
|
||||
}
|
||||
|
||||
// Sleep function (seconds)
|
||||
sleep(sec) {
|
||||
@@ -42,8 +50,8 @@ class Utils {
|
||||
}
|
||||
|
||||
async getHostIp() {
|
||||
const pLookup = promisify(dns.lookup)
|
||||
try {
|
||||
const pLookup = promisify(dns.lookup)
|
||||
return (await pLookup(os.hostname())).address
|
||||
} catch {
|
||||
console.log('Failed to resolve hostname IP address, returning localhost instead')
|
||||
@@ -74,10 +82,12 @@ class Utils {
|
||||
return detectedCores
|
||||
}
|
||||
|
||||
isNumeric(num) {
|
||||
return !isNaN(parseFloat(num)) && isFinite(num);
|
||||
}
|
||||
|
||||
debug(message, debugType) {
|
||||
debugType = debugType ? debugType : 'mqtt'
|
||||
debug[debugType](message)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Utils()
|
||||
|
Reference in New Issue
Block a user