Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #25

Merged
merged 7 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 95 additions & 59 deletions MMM-SynologySurveillance.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ Module.register("MMM-SynologySurveillance", {
imgDecodeCheckInterval: -1,
minimumTimeBetweenRefreshs: 10000,
restoreBigAfterProfileChange: true,
moduleIsDisplayedInEveryProfile: false
},

suspend: function () {
const self = this
self.visible = false
},

resume: function () {
const self = this
self.visible = true

if (self.config.updateDomOnShow){
self.updateDom(self.config.animationSpeed)
}
if (self.config.updateDomOnShow){
self.updateDom(self.config.animationSpeed)
}
},

getStyles: function() {
Expand All @@ -68,7 +67,13 @@ Module.register("MMM-SynologySurveillance", {
self.currentProfile = ""
self.currentProfilePattern = new RegExp(".*")
self.bigIdxPerProfile = {}

self.allModulesStarted = false
if (typeof self.data.classes !== "undefined"){
self.allModulesClasses = self.data.classes.split(" ")
} else {
self.allModulesClasses = null
}

if (self.config.order !== null) {
let nameDsCamIdxMap = {}
for (let curDsIdx = 0; curDsIdx < self.config.ds.length; curDsIdx++) {
Expand Down Expand Up @@ -418,49 +423,78 @@ Module.register("MMM-SynologySurveillance", {
getNextCamId: function (curId, type = 1) {
const self = this
let nextCamId = curId
if (type === 1) {
//get the next cam id (current + 1)
nextCamId = curId + 1
for (let i = 0; i < self.order.length; i++) {
if (nextCamId >= self.order.length) {
nextCamId = 0
}
let curDsIdx = self.order[nextCamId][0]
let curCamId = self.order[nextCamId][1]
if (typeof self.config.ds[curDsIdx].cams[curCamId].profiles === "undefined" ||
self.currentProfilePattern.test(self.config.ds[curDsIdx].cams[curCamId].profiles)
){
return nextCamId
}
nextCamId = nextCamId + 1
}
} else if (type === -1) {
//get the previous cam id (current - 1)
nextCamId = curId - 1
for (let i = 0; i < self.order.length; i++) {
if (nextCamId < 0) {
nextCamId = self.order.length - 1
if (self.config.moduleIsDisplayedInEveryProfile || ((self.allModulesClasses != null) && ((self.currentProfile !== "") && (self.allModulesClasses.includes(self.currentProfile))))) {
if (self.config.debug) {
console.log(self.name+": Either the moduleIsDisplayedInEveryProfile is set to true or this module is currently displayed. Checking for the current big cam index and recalcualte it if needed.")
}
if (type === 1) {
//get the next cam id (current + 1)
nextCamId = curId + 1
for (let i = 0; i < self.order.length; i++) {
if (nextCamId >= self.order.length) {
nextCamId = 0
}
let curDsIdx = self.order[nextCamId][0]
let curCamId = self.order[nextCamId][1]
if (typeof self.config.ds[curDsIdx].cams[curCamId].profiles === "undefined" ||
self.currentProfilePattern.test(self.config.ds[curDsIdx].cams[curCamId].profiles)
){
return nextCamId
}
nextCamId = nextCamId + 1
}
let curDsIdx = self.order[nextCamId][0]
let curCamId = self.order[nextCamId][1]
if (typeof self.config.ds[curDsIdx].cams[curCamId].profiles === "undefined" ||
self.currentProfilePattern.test(self.config.ds[curDsIdx].cams[curCamId].profiles)
) {
return nextCamId
} else if (type === -1) {
//get the previous cam id (current - 1)
nextCamId = curId - 1
for (let i = 0; i < self.order.length; i++) {
if (nextCamId < 0) {
nextCamId = self.order.length - 1
}
let curDsIdx = self.order[nextCamId][0]
let curCamId = self.order[nextCamId][1]
if (typeof self.config.ds[curDsIdx].cams[curCamId].profiles === "undefined" ||
self.currentProfilePattern.test(self.config.ds[curDsIdx].cams[curCamId].profiles)
) {
return nextCamId
}
nextCamId = nextCamId - 1
}
nextCamId = nextCamId - 1
}
} else if (type === 0) {
//keep the current cam if possible but call the function to find the next one if the profile does not match
let curDsIdx = self.order[curId][0]
let curCamId = self.order[curId][1]
} else if (type === 0) {
//keep the current cam if possible but call the function to find the next one if the profile does not match
if (curId < 0 || (curId >= self.order.length)){
curId = 0
if (self.config.debug){
console.log(self.name+": Reset big cam idx to 0 as it is either negative or to big")
}
}

if (typeof self.config.ds[curDsIdx].cams[curCamId].profiles === "undefined" ||
self.currentProfilePattern.test(self.config.ds[curDsIdx].cams[curCamId].profiles)
){
return curId
} else {
return self.getNextCamId(curId, 1)
if (typeof self.order[curId] !== "undefined"){
let curDsIdx = self.order[curId][0]
let curCamId = self.order[curId][1]

if (typeof self.config.ds[curDsIdx].cams[curCamId].profiles === "undefined" ||
self.currentProfilePattern.test(self.config.ds[curDsIdx].cams[curCamId].profiles)
){
if (self.config.debug){
console.log(self.name+": The cam id "+curId+" is valid for profile "+self.currentProfile+". Using it.")
}
return curId
} else {
if (self.config.debug){
console.log(self.name+": The cam id "+curId+" is NOT valid for profile "+self.currentProfile+". Trying to find a suitable one.")
}
return self.getNextCamId(curId, 1)
}
} else {
if (self.config.debug){
console.log(self.name+": The order info does not contain the index "+curId+". We try to find the next higher one. If this is not possible it will be resetted!")
}
return self.getNextCamId(curId, 1)
}
}
} else {
if (self.config.debug) {
console.log(self.name+": Either the this module is currently not displayed or no profiles are used. Using the current big cam idx: "+nextCamId)
}
}

Expand Down Expand Up @@ -574,19 +608,19 @@ Module.register("MMM-SynologySurveillance", {
self.currentProfile = payload.to
self.currentProfilePattern = new RegExp("\\b" + payload.to + "\\b")

if (typeof payload.from !== "undefined"){
if (self.config.restoreBigAfterProfileChange){
self.bigIdxPerProfile[payload.from] = self.curBigIdx
}

if(typeof self.bigIdxPerProfile[self.currentProfile] !== "undefined"){
self.curBigIdx = self.bigIdxPerProfile[self.currentProfile]
if (self.config.debug){
console.log(self.name+": restored big cam idx is: "+self.curBigIdx)
}
}
}


if (typeof payload.from !== "undefined"){
if (self.config.restoreBigAfterProfileChange){
self.bigIdxPerProfile[payload.from] = self.curBigIdx
}

if(typeof self.bigIdxPerProfile[self.currentProfile] !== "undefined"){
self.curBigIdx = self.bigIdxPerProfile[self.currentProfile]
if (self.config.debug){
console.log(self.name+": restored big cam idx is: "+self.curBigIdx)
}
}
}
self.curBigIdx = self.getNextCamId(self.curBigIdx, 0)
if (self.config.debug){
console.log(self.name+": after profile check the used big cam idx is: "+self.curBigIdx)
Expand All @@ -599,6 +633,8 @@ Module.register("MMM-SynologySurveillance", {
}
} else if (notification === "SYNO_INVALIDATE_URL"){
self.sendSocketNotification(notification, payload)
} else if (notification === "ALL_MODULES_STARTED"){
self.allModulesStarted = true
}
},

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ There is a example topic after the description of the different configuration pa
| imgDecodeCheckInterval | If set to a value greater 0 the module will check if the images can decoded in a interval of this value in seconds. If a image can not be decoded the URL will be refreshed. This is to avoid empty cam boxes. The value can be set for each cam indiviually, too. If both this and value for the camera is set the one of the camera is used. | Integer | -1 |
| minimumTimeBetweenRefreshs | It may happen that there are a lot of requests to refresh the URLs of the cams in a short time. This value prevents the requests to fire to quickly. The module waits at least this amount of milliseconds till it requests new URLs of the DiskStations again. | Integer | 10000 |
| restoreBigAfterProfileChange | If multiple profiles are used and not all cams are visiable in all profiles it may happen that the cam that is displayed big changes on a profile change. If this setting is set to true the module tries to restore the previous state if the user returns to a previously selected profile. | Boolean | true |
| moduleIsDisplayedInEveryProfile | Set this option to true if you use MMM-ProfileSwitcher and do have this module on the ignore list to make the calculation of the big cam index work! | Boolean | false |

### DiskStations

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MMM-SynologySurveillance",
"version": "0.2.2",
"version": "0.2.3",
"description": "A MaigcMirror² module which displays video streams of cameras either connected to a Synology Diskstation or which provide a mjpeg stream.",
"main": "MMM-SynologySurveillance.js",
"dependencies": {
Expand Down