mirror of
https://github.com/tsightler/ring-mqtt.git
synced 2025-09-26 21:01:12 +08:00
MQTT URL fixes
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@ ring-state.json
|
||||
ring-test.js
|
||||
config.dev.json
|
||||
ring-state.json
|
||||
config.dev.json.backup
|
||||
|
@@ -256,7 +256,7 @@ class Camera extends RingPolledDevice {
|
||||
this.data.ding.last_ding_time = lastDingDate ? utils.getISOTime(lastDingDate) : ''
|
||||
}
|
||||
|
||||
if (!await this.updateEventStreamUrl(true)) {
|
||||
if (!await this.updateEventStreamUrl()) {
|
||||
this.debug('Could not retrieve recording URL for event, assuming no Ring Protect subscription')
|
||||
delete this.entity.event_stream
|
||||
delete this.entity.event_select
|
||||
@@ -765,7 +765,10 @@ class Camera extends RingPolledDevice {
|
||||
const events = ((await this.device.getEvents({ limit: 10, kind })).events).filter(event => event.recording_status === 'ready')
|
||||
dingId = events[index].ding_id_str
|
||||
if (dingId !== this.data.stream.event.dingId) {
|
||||
this.debug(`New ${kind} event detected, updating the event recording URL`)
|
||||
if (this.data.stream.event.recordingUrlExpire) {
|
||||
// Only log after first update
|
||||
this.debug(`New ${kind} event detected, updating the event recording URL`)
|
||||
}
|
||||
recordingUrl = await this.device.getRecordingUrl(dingId)
|
||||
} else if (Math.floor(Date.now()/1000) - this.data.stream.event.recordingUrlExpire > 0) {
|
||||
this.debug(`Previous ${kind} event recording URL has expired, updating the event recording URL`)
|
||||
|
@@ -108,7 +108,7 @@ if [ "${RUNMODE}" = "addon" ]; then
|
||||
fi
|
||||
|
||||
case "$MQTTPORT" in
|
||||
8883) MQTTURLPREFIX='mqtts://' ;;
|
||||
8883|8884) MQTTURLPREFIX='mqtts://' ;;
|
||||
*) MQTTURLPREFIX='mqtt://' ;;
|
||||
esac
|
||||
|
||||
|
@@ -24,7 +24,7 @@ class Config {
|
||||
this.loadConfigFile()
|
||||
if (!process.env.MQTTURL) {
|
||||
this.data.port = process.env.MQTTPORT
|
||||
if ((this.data.port === '8883' || this.data.port === "8884") && process.env.MQTTHOST === 'core-mosquitto') {
|
||||
if ((this.data.port == 8883 || this.data.port == 8884) && process.env.MQTTHOST === 'core-mosquitto') {
|
||||
// For MQTTS use hostname must match name in host certificate
|
||||
this.data.host = process.env.HAHOSTNAME
|
||||
} else {
|
||||
@@ -32,7 +32,7 @@ class Config {
|
||||
}
|
||||
this.data.mqtt_user = process.env.MQTTUSER
|
||||
this.data.mqtt_pass = process.env.MQTTPASSWORD
|
||||
this.data.mqtt_url = `${this.data.port === '8883' ? 'mqtts:' : 'mqtt:'}//${this.data.mqtt_user}:${this.data.mqtt_pass}@${this.data.host}:${this.data.port}`
|
||||
this.data.mqtt_url = `${(this.data.port == 8883 || this.data.port == 8884) ? 'mqtts:' : 'mqtt:'}//${this.data.mqtt_user}:${this.data.mqtt_pass}@${this.data.host}:${this.data.port}`
|
||||
} else {
|
||||
this.data.mqtt_url = process.env.MQTTURL
|
||||
}
|
||||
@@ -60,7 +60,8 @@ class Config {
|
||||
|
||||
// Export MQTTURL environment variable even if only using config file (standalone install)
|
||||
// This is needed for start_stream.sh to be able to connect to MQTT broker
|
||||
debug(`Using MQTT URL: ${this.data.mqtt_url.split('://').replace(/:.*@/, '<hidden>').join('://')}`)
|
||||
let mqttLogUrl = this.data.mqtt_url.split('://')
|
||||
debug(`Using MQTT URL: ${mqttLogUrl[0]}://${mqttLogUrl[1].replace(/:.*@/, ':<hidden>@')}`)
|
||||
process.env.MQTTURL = this.data.mqtt_url
|
||||
}
|
||||
|
||||
@@ -104,11 +105,16 @@ class Config {
|
||||
|
||||
migrateToMqttUrl() {
|
||||
debug ('Migrating legacy MQTT config options to use mqtt_url ...')
|
||||
this.data.mqtt_url = `${this.data.port = '8883' ? 'mqtts:' : 'mqtt:'}//${this.data.mqtt_user}:${this.data.mqtt_pass}@${this.data.host}:${this.data.port}`
|
||||
const mqttUrlPrefix = (this.data.port == 8883 || this.data.port == 8884) ? 'mqtts://' : 'mqtt://'
|
||||
let mqttUrl = `${mqttUrlPrefix}${this.data.host}:${this.data.port}`
|
||||
if (this.data.mqtt_user && this.data.mqtt_pass) {
|
||||
mqttUrl = `${mqttUrlPrefix}${this.data.mqtt_user}:${this.data.mqtt_pass}@${this.data.host}:${this.data.port}`
|
||||
}
|
||||
delete this.data.host
|
||||
delete this.data.port
|
||||
delete this.data.mqtt_user
|
||||
delete this.data.mqtt_pass
|
||||
this.data = {mqtt_url: mqttUrl, ...this.data}
|
||||
this.updateConfig()
|
||||
}
|
||||
|
||||
|
@@ -33,4 +33,6 @@ else
|
||||
exit 1;; \
|
||||
esac
|
||||
curl -L -s "https://github.com/aler9/rtsp-simple-server/releases/download/v0.18.0/rtsp-simple-server_v0.18.0_linux_${RSSARCH}.tar.gz" | tar zxf - -C /usr/local/bin rtsp-simple-server
|
||||
|
||||
cp -a "/app/ring-mqtt-${BRANCH}/init/s6/services.d/ring-mqtt/run" /etc/services.d/ring-mqtt/.
|
||||
fi
|
Reference in New Issue
Block a user