Skip to content

Commit

Permalink
fixed bug which caused the cam urls not to be fetched if more than on…
Browse files Browse the repository at this point in the history
…e cam is connected to an ds
  • Loading branch information
Tom-Hirschberger committed Apr 16, 2020
1 parent 3cc91c3 commit 246cf5f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
11 changes: 11 additions & 0 deletions MMM-SynologySurveillance.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,15 @@ Module.register('MMM-SynologySurveillance', {
socketNotificationReceived: function (notification, payload) {
if(notification === "DS_STREAM_INFO"){
console.log("Got new Stream info of ds with id: "+payload.dsIdx)
console.log(JSON.stringify(payload, null, 2))
if(typeof this.dsStreamInfo[payload.dsIdx] !== "undefined") {
var updated = false
for(var curKey in Object.keys(this.dsStreamInfo[payload.dsIdx])){
if(this.dsStreamInfo[payload.dsIdx][curKey] !== payload.camStreams[curKey]){
this.dsStreamInfo[payload.dsIdx] = payload.camStreams
this.updateDom(this.config.animationSpeed)
console.log("URL of cam: "+curKey+" changed. Updating view!")
updated = true
break
}
}
Expand All @@ -296,10 +300,17 @@ Module.register('MMM-SynologySurveillance', {
if(this.dsStreamInfo[payload.dsIdx][curKey] !== payload.camStreams[curKey]){
this.dsStreamInfo[payload.dsIdx] = payload.camStreams
this.updateDom(this.config.animationSpeed)
console.log("URL of cam: "+curKey+" changed. Updating view!")
updated = true
break
}
}

if(!updated){
console.log("No url changed. Update skipped!")
}
} else {
console.log("Did not have any url information of ds with id: "+payload.dsIdx+". Updating view!")
this.dsStreamInfo[payload.dsIdx] = payload.camStreams
this.updateDom(this.config.animationSpeed)
}
Expand Down
33 changes: 16 additions & 17 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ module.exports = NodeHelper.create({
validCamNames[curDs.cams[i].name] = i
}

var innerCallback = function(syno, curDsIdx, idsNeeded, idNameMap){
syno.ss.getLiveViewPathCamera({'idList':idsNeeded}, function(liveViewError,liveViewData){
var innerCallback = function(syno, curDsIdx, idString, idNameMap){
// console.log("Quering for urls of cams: "+idString)
syno.ss.getLiveViewPathCamera({'idList':idString}, function(liveViewError,liveViewData){
// console.log("curDsIdx: "+JSON.stringify(curDsIdx))
// console.log("isNeeded: "+JSON.stringify(idsNeeded))
// console.log("idNameMap: "+JSON.stringify(idNameMap))
if(typeof liveViewData !== "undefined"){
// console.log("Got url info of DS with id: "+curDsIdx)
// console.log(JSON.stringify(liveViewData,null,2))
for(var curResIdx in liveViewData){
var curCamId = liveViewData[curResIdx]["id"]
var curCamName = idNameMap[curCamId]
Expand All @@ -64,31 +67,27 @@ module.exports = NodeHelper.create({
}

var outerCallback = function(syno, curDsIdx, validCamNames){
console.log("ValidCamNames of idx: "+curDsIdx+" :"+JSON.stringify(validCamNames))
console.log("Updating information of DS with idx: "+curDsIdx)
// console.log("ValidCamNames of idx: "+curDsIdx+" :"+JSON.stringify(validCamNames))
syno.ss.listCameras(function(error,data){
if(typeof data !== "undefined"){
idNameMap = {}
var cameras = data["cameras"]
var notFirst = false
var idString = ""
for (var key in cameras){
idNameMap[cameras[key]["id"]] = cameras[key]["newName"]
var idsNeeded = []
if(typeof validCamNames[cameras[key]["newName"]] !== "undefined"){
idsNeeded.push(cameras[key]["id"])
}
}

var notFirst = false
var idString = ""
for(var curId in idsNeeded){
if(notFirst){
idString+=","
if(notFirst){
idString+=","
}

idString+=cameras[key]["id"]
notFirst = true;
}

idString+=curId
notFirst = true;
}

innerCallback(syno, curDsIdx, idsNeeded, idNameMap)
innerCallback(syno, curDsIdx, idString, idNameMap)
}
})
}
Expand Down

0 comments on commit 246cf5f

Please sign in to comment.