Release 4.8.1

This commit is contained in:
tsightler
2021-09-08 22:18:39 -04:00
parent b0670ba665
commit 2b0d43f66c
5 changed files with 49 additions and 19 deletions

View File

@@ -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 && \ ln -s /usr/lib/bashio/bashio /usr/bin/bashio && \
chmod +x /app/ring-mqtt/scripts/*.sh && \ chmod +x /app/ring-mqtt/scripts/*.sh && \
mkdir /data && \ mkdir /data && \
chmod 777 /data /app && \ chmod 777 /data /app /run && \
cd /app/ring-mqtt && \ cd /app/ring-mqtt && \
chmod +x ring-mqtt.js && \ chmod +x ring-mqtt.js && \
npm install && \ npm install && \

View File

@@ -56,7 +56,11 @@ class Camera extends RingPolledDevice {
active: false, active: false,
expires: 0 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, lightState: null,
sirenState: null, sirenState: null,
@@ -187,14 +191,27 @@ class Camera extends RingPolledDevice {
this.data.ding.last_ding_time = lastDingDate ? utils.getISOTime(lastDingDate) : '' 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 // 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) 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://${this.config.livestream_user}:${this.config.livestream_pass}@${streamSourceUrlBase}:8554/${this.deviceId}_live`
: `rtsp://${await utils.getHostFqdn()}:8554/${this.deviceId}_live`, : `rtsp://${streamSourceUrlBase}: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`
} }
// Publish camera capabilities and state and subscribe to events // Publish camera capabilities and state and subscribe to events
@@ -517,7 +534,7 @@ class Camera extends RingPolledDevice {
'-skip_frame', '-skip_frame',
'nokey', 'nokey',
'-i', '-i',
this.data.stream.rtspLocalUrl, this.data.stream.rtspPublishUrl,
'-f', '-f',
'image2pipe', 'image2pipe',
'-s', '-s',
@@ -535,7 +552,7 @@ class Camera extends RingPolledDevice {
// keep it running when there are no other RTSP readers. // keep it running when there are no other RTSP readers.
ffmpegProcess = spawn(pathToFfmpeg, [ ffmpegProcess = spawn(pathToFfmpeg, [
'-i', '-i',
this.data.stream.rtspLocalUrl, this.data.stream.rtspPublishUrl,
'-map', '-map',
'0:a:0', '0:a:0',
'-c:a', '-c:a',
@@ -628,7 +645,7 @@ class Camera extends RingPolledDevice {
'copy', 'copy',
'-f', '-f',
'rtsp', 'rtsp',
this.data.stream.rtspLocalUrl this.data.stream.rtspPublishUrl
] ]
}) })

View File

@@ -34,6 +34,10 @@ git --version
echo "-------------------------------------------------------" echo "-------------------------------------------------------"
if [ "${RUNMODE}" = "addon" ]; then 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 # Setup the MQTT environment options based on addon configuration settings
export MQTTHOST=$(bashio::config "mqtt_host") export MQTTHOST=$(bashio::config "mqtt_host")
export MQTTPORT=$(bashio::config "mqtt_port") export MQTTPORT=$(bashio::config "mqtt_port")

View File

@@ -1,4 +1,7 @@
const fs = require('fs') const fs = require('fs')
const dns = require('dns')
const os = require('os')
const { promisify } = require('util')
class Utils class Utils
{ {
@@ -30,19 +33,24 @@ class Utils
} }
async getHostFqdn() { async getHostFqdn() {
const dns = require('dns')
const os = require('os')
const { promisify } = require('util')
const pLookup = promisify(dns.lookup)
const pLookupService = promisify(dns.lookupService) const pLookupService = promisify(dns.lookupService)
try { try {
return (await pLookupService((await pLookup(os.hostname())).address, 0)).hostname return await pLookupService(await this.getHostIp(), 0).hostname
} catch { } catch {
console.log('Failed to resolve FQDN, using os.hostname() instead') console.log('Failed to resolve FQDN, using os.hostname() instead')
return os.hostname() 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() module.exports = new Utils()

View File

@@ -336,7 +336,7 @@ async function processLocations(mqttClient, ringClient) {
// Process received MQTT command // Process received MQTT command
async function processMqttMessage(topic, message, mqttClient, ringClient) { async function processMqttMessage(topic, message, mqttClient, ringClient) {
message = message.toString() 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) debug('Home Assistant state topic '+topic+' received message: '+message)
if (message == 'online') { if (message == 'online') {
// Republish devices and state if restart of HA is detected // 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 // Monitor configured/default Home Assistant status topic
mqttClient.subscribe(CONFIG.hass_topic) mqttClient.subscribe(CONFIG.hass_topic)
// Monitor legacy Home Assistant status topic // Monitor legacy Home Assistant status topics
mqttClient.subscribe('hass/status') mqttClient.subscribe('hass/status')
mqttClient.subscribe('hassio/status')
startMqtt(mqttClient, ringClient) startMqtt(mqttClient, ringClient)
} catch (error) { } catch (error) {
debug(error) debug(error)