mirror of
https://github.com/tsightler/ring-mqtt.git
synced 2025-09-26 21:01:12 +08:00
Minor logging updates
This commit is contained in:
@@ -6,6 +6,7 @@ const net = require('net');
|
||||
const getPort = require('get-port')
|
||||
const pathToFfmpeg = require('ffmpeg-for-homebridge')
|
||||
const { spawn } = require('child_process')
|
||||
const { Worker } = require('worker_threads')
|
||||
const rss = require('../lib/rtsp-simple-server')
|
||||
|
||||
class Camera extends RingPolledDevice {
|
||||
@@ -650,6 +651,7 @@ class Camera extends RingPolledDevice {
|
||||
}
|
||||
|
||||
async startLiveStream() {
|
||||
new Worker('./lib/livestream.js', this.device);
|
||||
// Start and publish stream to rtsp-simple-server
|
||||
this.debug('Establishing connection to live stream')
|
||||
try {
|
||||
@@ -669,7 +671,7 @@ class Camera extends RingPolledDevice {
|
||||
],
|
||||
video: [
|
||||
'-map', '0:v:0',
|
||||
'-c:v', 'copy',
|
||||
'-vcodec', 'copy',
|
||||
],
|
||||
output: [
|
||||
'-f', 'rtsp',
|
||||
|
@@ -6,6 +6,7 @@ Standard installation is possible, however, this method is not regularly tested
|
||||
- NodeJS version must be at least 14.17.0 (latest LTS is recommended)
|
||||
- [rtsp-simple-server](https://github.com/aler9/rtsp-simple-server) v0.17.4 or later must be installed and available in the system path.
|
||||
- The mosquitto clients package (mosquitto_sub/mosquitto_pub) must be available in the system path
|
||||
- The jq package must be installed. This is usually available via the OS package manager (Ubuntu: "sudo apt install jq").
|
||||
|
||||
#### Perform Install
|
||||
Once the pre-requisites have been met simply clone this project from Github into a directory of your choice (the included systemd unit file below assumes /opt but can be easily modified):
|
||||
|
@@ -4,6 +4,10 @@ const utils = require('./utils')
|
||||
const ring = require('./ring')
|
||||
|
||||
class ExitHandler {
|
||||
constructor() {
|
||||
this.init()
|
||||
}
|
||||
|
||||
init() {
|
||||
// Setup Exit Handlers
|
||||
process.on('exit', this.processExit.bind(null, 0))
|
||||
|
3
lib/livestream.js
Normal file
3
lib/livestream.js
Normal file
@@ -0,0 +1,3 @@
|
||||
const { workerData, parentPort } = require('worker_threads')
|
||||
|
||||
console.log(workerData)
|
@@ -33,7 +33,7 @@ class State {
|
||||
}
|
||||
} catch {
|
||||
debug(err.message)
|
||||
debug('Saved state file exist but could not be parsed!')
|
||||
debug(colors.red('Saved state file exist but could not be parsed!'))
|
||||
await this.initStateData()
|
||||
}
|
||||
} else {
|
||||
@@ -44,11 +44,11 @@ class State {
|
||||
async initStateData() {
|
||||
this.data.systemId = (createHash('sha256').update(randomBytes(32)).digest('hex'))
|
||||
if (process.env.RUNMODE === 'standard' && this.config.data.hasOwnProperty('ring_token') && this.config.data.ring_token) {
|
||||
debug(colors.brightYellow('State file '+this.file+' not found, creating new state file using existing ring_token from config file.'))
|
||||
debug(colors.yellow('State file '+this.file+' not found, creating new state file using existing ring_token from config file.'))
|
||||
this.updateToken(this.config.data.ring_token, true)
|
||||
await this.config.updateConfig()
|
||||
} else {
|
||||
debug(colors.brightYellow('State file '+this.file+' not found. No saved state data available.'))
|
||||
debug(colors.yellow('State file '+this.file+' not found. No saved state data available.'))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class State {
|
||||
await writeFileAtomic(this.file, JSON.stringify(this.data, null, 2))
|
||||
debug('Successfully saved updated refresh token in state file: '+this.file)
|
||||
} catch (err) {
|
||||
debug('Failed to save updated refresh token in state file: '+this.file)
|
||||
debug(colors.red('Failed to save updated refresh token in state file: '+this.file))
|
||||
debug(err.message)
|
||||
}
|
||||
}
|
||||
|
@@ -38,11 +38,7 @@ class TokenApp {
|
||||
let restClient
|
||||
|
||||
this.listener = this.app.listen(55123, () => {
|
||||
if (process.env.RUNMODE === 'addon') {
|
||||
debug('Access the Web UI via the "Open Web UI" button from the addon "Info" tab')
|
||||
} else {
|
||||
debug('Access the Web UI at http://<host_ip_address>:55123/ to generate an authentication token.')
|
||||
}
|
||||
debug('Succesfully started the token generator web UI')
|
||||
})
|
||||
|
||||
this.app.use(bodyParser.urlencoded({ extended: false }))
|
||||
|
16
ring-mqtt.js
16
ring-mqtt.js
@@ -12,7 +12,6 @@ const tokenApp = require('./lib/tokenapp')
|
||||
// Main code loop
|
||||
const main = async(generatedToken) => {
|
||||
if (!state.valid) {
|
||||
await exitHandler.init()
|
||||
await state.init(config)
|
||||
}
|
||||
|
||||
@@ -20,21 +19,24 @@ const main = async(generatedToken) => {
|
||||
if (state.data.ring_token || generatedToken) {
|
||||
// Wait for the network to be online and then attempt to connect to the Ring API using the token
|
||||
while (!(await isOnline())) {
|
||||
debug(colors.brightYellow('Network is offline, waiting 10 seconds to check again...'))
|
||||
debug(colors.yellow('Network is offline, waiting 10 seconds to check again...'))
|
||||
await utils.sleep(10)
|
||||
}
|
||||
|
||||
if (!await ring.init(state, generatedToken)) {
|
||||
debug(colors.brightRed('Failed to connect to Ring API using saved token, generate a new token using the Web UI'))
|
||||
debug(colors.brightRed('or wait 60 seconds to automatically retry authentication using the existing token'))
|
||||
debug(colors.red('Failed to connect to Ring API using saved token, generate a new token using the Web UI'))
|
||||
debug(colors.red('or wait 60 seconds to automatically retry authentication using the existing token'))
|
||||
tokenApp.start()
|
||||
await utils.sleep(60)
|
||||
main()
|
||||
}
|
||||
} else {
|
||||
// If a refresh token was not found, start Web UI for token generator
|
||||
debug(colors.brightRed('No refresh token was found in state file, generate a token using the Web UI'))
|
||||
tokenApp.start()
|
||||
if (process.env.RUNMODE === 'addon') {
|
||||
debug(colors.red('No refresh token was found in state file, generate a token using the addon Web UI'))
|
||||
} else {
|
||||
tokenApp.start()
|
||||
debug(colors.red('No refresh token we found in the state file, use the Web UI at http://<host_ip_address>:55123/ to generate a token.'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user