mirror of
https://github.com/tsightler/ring-mqtt.git
synced 2025-10-25 09:40:26 +08:00
Release 4.8.1
This commit is contained in:
@@ -46,7 +46,7 @@ RUN apk add --no-cache tar git libcrypto1.1 libssl1.1 musl-utils musl bash curl
|
||||
ln -s /usr/lib/bashio/bashio /usr/bin/bashio && \
|
||||
chmod +x /app/ring-mqtt/scripts/*.sh && \
|
||||
mkdir /data && \
|
||||
chmod 777 /data /app && \
|
||||
chmod 777 /data /app /run && \
|
||||
cd /app/ring-mqtt && \
|
||||
chmod +x ring-mqtt.js && \
|
||||
npm install && \
|
||||
|
||||
@@ -56,7 +56,11 @@ class Camera extends RingPolledDevice {
|
||||
active: false,
|
||||
expires: 0
|
||||
},
|
||||
sipSession: null
|
||||
sipSession: null,
|
||||
rtspPublishUrl: (this.config.livestream_user && this.config.livestream_pass)
|
||||
? `rtsp://${this.config.livestream_user}:${this.config.livestream_pass}@localhost:8554/${this.deviceId}_live`
|
||||
: `rtsp://localhost:8554/${this.deviceId}_live`
|
||||
|
||||
},
|
||||
lightState: null,
|
||||
sirenState: null,
|
||||
@@ -187,14 +191,27 @@ class Camera extends RingPolledDevice {
|
||||
this.data.ding.last_ding_time = lastDingDate ? utils.getISOTime(lastDingDate) : ''
|
||||
}
|
||||
|
||||
let stillImageUrlBase = 'localhost'
|
||||
let streamSourceUrlBase
|
||||
if (process.env.RUNMODE === 'addon') {
|
||||
// For the addon we get some values populated from the startup script
|
||||
// that queries the HA API via bashio
|
||||
stillImageUrlBase = process.env.HAHOSTNAME
|
||||
streamSourceUrlBase = process.env.ADDONHOSTNAME
|
||||
} else if (process.env.RUNMODE === 'docker') {
|
||||
// For docker we don't have any API to query so we just use the IP of the docker container
|
||||
// since it probably doesn't have a DNS entry
|
||||
streamSourceUrlBase = await utils.getHostIp()
|
||||
} else {
|
||||
// For the stadalone install we try to get the host FQDN
|
||||
streamSourceUrlBase = await utils.getHostFqdn()
|
||||
}
|
||||
|
||||
// Set some helper attributes for streaming
|
||||
this.data.stream.stillImageURL = `http://localhost:8123{{ states.camera.${this.device.name.toLowerCase().replace(" ","_")}_snapshot.attributes.entity_picture }}`,
|
||||
this.data.stream.stillImageURL = `https://${stillImageUrlBase}:8123{{ states.camera.${this.device.name.toLowerCase().replace(" ","_")}_snapshot.attributes.entity_picture }}`,
|
||||
this.data.stream.streamSource = (this.config.livestream_user && this.config.livestream_pass)
|
||||
? `rtsp://${this.config.livestream_user}:${this.config.livestream_pass}@${await utils.getHostFqdn()}:8554/${this.deviceId}_live`
|
||||
: `rtsp://${await utils.getHostFqdn()}:8554/${this.deviceId}_live`,
|
||||
this.data.stream.rtspLocalUrl = (this.config.livestream_user && this.config.livestream_pass)
|
||||
? `rtsp://${this.config.livestream_user}:${this.config.livestream_pass}@localhost:8554/${this.deviceId}_live`
|
||||
: `rtsp://localhost:8554/${this.deviceId}_live`
|
||||
? `rtsp://${this.config.livestream_user}:${this.config.livestream_pass}@${streamSourceUrlBase}:8554/${this.deviceId}_live`
|
||||
: `rtsp://${streamSourceUrlBase}:8554/${this.deviceId}_live`
|
||||
}
|
||||
|
||||
// Publish camera capabilities and state and subscribe to events
|
||||
@@ -517,7 +534,7 @@ class Camera extends RingPolledDevice {
|
||||
'-skip_frame',
|
||||
'nokey',
|
||||
'-i',
|
||||
this.data.stream.rtspLocalUrl,
|
||||
this.data.stream.rtspPublishUrl,
|
||||
'-f',
|
||||
'image2pipe',
|
||||
'-s',
|
||||
@@ -535,7 +552,7 @@ class Camera extends RingPolledDevice {
|
||||
// keep it running when there are no other RTSP readers.
|
||||
ffmpegProcess = spawn(pathToFfmpeg, [
|
||||
'-i',
|
||||
this.data.stream.rtspLocalUrl,
|
||||
this.data.stream.rtspPublishUrl,
|
||||
'-map',
|
||||
'0:a:0',
|
||||
'-c:a',
|
||||
@@ -628,7 +645,7 @@ class Camera extends RingPolledDevice {
|
||||
'copy',
|
||||
'-f',
|
||||
'rtsp',
|
||||
this.data.stream.rtspLocalUrl
|
||||
this.data.stream.rtspPublishUrl
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@ git --version
|
||||
echo "-------------------------------------------------------"
|
||||
|
||||
if [ "${RUNMODE}" = "addon" ]; then
|
||||
# Export a few helper variables for building the Streaming and Still Image URLs
|
||||
export HAHOSTNAME=$(bashio::info.hostname)
|
||||
export ADDONHOSTNAME=$HOSTNAME
|
||||
|
||||
# Setup the MQTT environment options based on addon configuration settings
|
||||
export MQTTHOST=$(bashio::config "mqtt_host")
|
||||
export MQTTPORT=$(bashio::config "mqtt_port")
|
||||
|
||||
20
lib/utils.js
20
lib/utils.js
@@ -1,4 +1,7 @@
|
||||
const fs = require('fs')
|
||||
const dns = require('dns')
|
||||
const os = require('os')
|
||||
const { promisify } = require('util')
|
||||
|
||||
class Utils
|
||||
{
|
||||
@@ -30,19 +33,24 @@ class Utils
|
||||
}
|
||||
|
||||
async getHostFqdn() {
|
||||
const dns = require('dns')
|
||||
const os = require('os')
|
||||
const { promisify } = require('util')
|
||||
const pLookup = promisify(dns.lookup)
|
||||
const pLookupService = promisify(dns.lookupService)
|
||||
|
||||
try {
|
||||
return (await pLookupService((await pLookup(os.hostname())).address, 0)).hostname
|
||||
return await pLookupService(await this.getHostIp(), 0).hostname
|
||||
} catch {
|
||||
console.log('Failed to resolve FQDN, using os.hostname() instead')
|
||||
return os.hostname()
|
||||
}
|
||||
}
|
||||
|
||||
async getHostIp() {
|
||||
const pLookup = promisify(dns.lookup)
|
||||
try {
|
||||
return await pLookup(os.hostname()).address
|
||||
} catch {
|
||||
console.log('Failed to resolve hostname IP address, returning localhost instead')
|
||||
return 'localhost'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Utils()
|
||||
|
||||
@@ -336,7 +336,7 @@ async function processLocations(mqttClient, ringClient) {
|
||||
// Process received MQTT command
|
||||
async function processMqttMessage(topic, message, mqttClient, ringClient) {
|
||||
message = message.toString()
|
||||
if (topic === CONFIG.hass_topic || topic === 'hass/status') {
|
||||
if (topic === CONFIG.hass_topic || topic === 'hass/status' || topic === 'hassio/status') {
|
||||
debug('Home Assistant state topic '+topic+' received message: '+message)
|
||||
if (message == 'online') {
|
||||
// Republish devices and state if restart of HA is detected
|
||||
@@ -646,8 +646,9 @@ const main = async(generatedToken) => {
|
||||
}
|
||||
// Monitor configured/default Home Assistant status topic
|
||||
mqttClient.subscribe(CONFIG.hass_topic)
|
||||
// Monitor legacy Home Assistant status topic
|
||||
// Monitor legacy Home Assistant status topics
|
||||
mqttClient.subscribe('hass/status')
|
||||
mqttClient.subscribe('hassio/status')
|
||||
startMqtt(mqttClient, ringClient)
|
||||
} catch (error) {
|
||||
debug(error)
|
||||
|
||||
Reference in New Issue
Block a user