Skip to content

Commit

Permalink
#951 add forced mjpeg support on per monitor basis
Browse files Browse the repository at this point in the history
  • Loading branch information
pliablepixels committed Jun 3, 2020
1 parent 87c1e58 commit 32d0711
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 78 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,5 @@
<plugin name="cordova-plugin-whitelist" spec="^1.3.4" />
<plugin name="cordova-plugin-media-pp-fork" spec="^1.0.2-dev" />
<engine name="android" spec="^8.0.0" />
<engine name="ios" spec="^5.1.1" />
<engine name="ios" spec="^4.5.5" />
</widget>
24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,45 @@
"cordova-plugin-inappbrowser": {},
"cordova-plugin-app-version": {},
"cordova-plugin-statusbar-pp-fork": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-media-pp-fork": {}
}
},
"dependencies": {
"async": "^3.2.0",
"clivas": "^0.2.0",
"cordova-android": "^8.0.0",
"cordova-custom-config": "^5.1.0",
"cordova-ios": "^5.1.1",
"cordova-ios": "^4.5.5",
"cordova-library-helper-pp-fork": "^1.0.1",
"cordova-plugin-add-swift-support": "1.7.2",
"cordova-plugin-add-swift-support": "^1.7.2",
"cordova-plugin-advanced-http": "git+https://github.com/silkimen/cordova-plugin-advanced-http.git",
"cordova-plugin-advanced-websocket": "^1.1.5",
"cordova-plugin-android-fingerprint-auth": "^1.5.0",
"cordova-plugin-android-permissions": "1.0.2",
"cordova-plugin-app-version": "0.1.9",
"cordova-plugin-android-permissions": "^1.0.2",
"cordova-plugin-app-version": "^0.1.9",
"cordova-plugin-cloud-settings": "^1.0.4",
"cordova-plugin-customurlscheme": "^4.4.0",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-file": "6.0.2",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-file-transfer": "^1.7.1",
"cordova-plugin-globalization": "^1.11.0",
"cordova-plugin-ignore-lint-translation": "0.0.1",
"cordova-plugin-inappbrowser": "git+https://github.com/apache/cordova-plugin-inappbrowser.git",
"cordova-plugin-insomnia": "^4.3.0",
"cordova-plugin-ionic-keyboard": "2.2.0",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-media-pp-fork": "^1.0.2-dev",
"cordova-plugin-multi-window": "0.0.3",
"cordova-plugin-network-information": "^2.0.2",
"cordova-plugin-photo-library": "git+https://github.com/pliablepixels/cordova-plugin-photo-library.git",
"cordova-plugin-pin-dialog": "^0.1.3",
"cordova-plugin-splashscreen": "git+https://github.com/prageeth/cordova-plugin-splashscreen.git",
"cordova-plugin-statusbar-pp-fork": "^2.4.4-dev",
"cordova-plugin-touch-id": "3.4.0",
"cordova-plugin-touch-id": "^3.4.0",
"cordova-plugin-whitelist": "^1.3.4",
"cordova-plugin-x-socialsharing": "5.6.4",
"cordova-plugin-x-socialsharing": "^5.6.4",
"cordova-sqlite-storage": "^1.5.3",
"cordova-support-google-services": "1.3.2",
"cordova-support-google-services": "^1.3.2",
"deep-equal": "^2.0.3",
"define-properties": "^1.1.3",
"dialog": "^0.3.1",
Expand All @@ -111,16 +113,18 @@
"is-arguments": "^1.0.4",
"is-date-object": "^1.0.2",
"is-regex": "^1.0.5",
"jshint": "^2.11.1",
"json-file": "^0.1.0",
"jsonfile": "^6.0.1",
"keypress": "^0.2.1",
"menu": "^0.2.5",
"minimist": "^1.2.5",
"mkdirp": "^1.0.4",
"node-sass": "^4.14.1",
"object-is": "^1.1.2",
"object-keys": "^1.1.1",
"phonegap-plugin-multidex": "^1.0.0",
"phonegap-plugin-push": "2.3.0",
"phonegap-plugin-push": "^2.3.0",
"regexp.prototype.flags": "^1.3.0"
},
"devDependencies": {
Expand Down
15 changes: 14 additions & 1 deletion www/js/EventModalCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ angular.module('zmApp.controllers').controller('EventModalCtrl', ['$scope', '$ro
var playState = 'play';
var isSeeking = false;
$scope.useFilters = true;



var broadcastHandles = [];
Expand Down Expand Up @@ -2136,7 +2137,19 @@ angular.module('zmApp.controllers').controller('EventModalCtrl', ['$scope', '$ro
}


$scope.defaultVideo = event.Event.DefaultVideo;


var ld = NVR.getLogin();
if (ld.monitorSpecific[event.Event.MonitorId] &&
ld.monitorSpecific[event.Event.MonitorId].forceMjpeg) {
NVR.debug ('Monitor:'+event.Event.MonitorId+' has forced MJPEG playback');
$scope.defaultVideo ='';
} else {

$scope.defaultVideo = event.Event.DefaultVideo;
}



$scope.connKey = (Math.floor((Math.random() * 999999) + 1)).toString();

Expand Down
192 changes: 130 additions & 62 deletions www/js/MonitorCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,33 @@ angular.module('zmApp.controllers')
// This function takes care of changing monitor parameters
// For now, I've only limited it to enable/disable and change monitor mode
// and changing monitor function
// if it's 'All' then rest are empty
//-----------------------------------------------------------------------
$scope.changeConfig = function (monitorName, monitorId, enabled, func) {
$scope.changeConfig = function (monitorName, monitorId, enabled, func, mon_forceMjpeg) {
var checked = false;
var i;



$scope.forceMjpeg = {
value:false
};

if (!mon_forceMjpeg) $scope.forceMjpeg.value = true; // true if all monitors passed
var monitorsIds = [];
if (monitorName == 'All') {
monitorName = $translate.instant('kAll');
// in all monitors, lets keep enabled on
enabled = '1';
for (var i = 0; i < $scope.monitors.length; i++) {

for (i = 0; i < $scope.monitors.length; i++) {
// console.log ("HUH "+$scope.monitors[i].Monitor.forceMjpeg);
monitorsIds[i] = $scope.monitors[i].Monitor.Id;
if (!$scope.monitors[i].Monitor.forceMjpeg) $scope.forceMjpeg.value = false; // if any is unset, global is unset
}
} else {
monitorsIds[0] = monitorId;
$scope.forceMjpeg.value = mon_forceMjpeg;
}

//console.log("called with " + monitorId + ":" + enabled + ":" + func);
Expand Down Expand Up @@ -133,11 +146,24 @@ angular.module('zmApp.controllers')
mypromises: []
};


var oldValues = {
myfunc: func,
myenabled: checked,
forceMjpeg: $scope.forceMjpeg.value
};

//console.log (JSON.stringify($scope.monfunc));
$rootScope.zmPopup = $ionicPopup.show({
scope: $scope,
cssClass:'widepopup',
template: '<ion-toggle ng-model="monfunc.myenabled" toggle-class="toggle-calm">'+$translate.instant('kMotionEnabled')+'</ion-toggle><div class="item item-divider" style="background:#666666;color:white;">'+$translate.instant('kChangeMode')+'</div><ion-radio-fix ng-repeat="item in monFunctions" ng-value="item.value" ng-model="monfunc.myfunc"> {{item.text}} </ion-radio-fix>',
template: '<ion-toggle ng-model="monfunc.myenabled" toggle-class="toggle-calm">'
+$translate.instant('kMotionEnabled')+'</ion-toggle>'
+'<ion-toggle ng-model="forceMjpeg.value" toggle-class="toggle-calm">'
+$translate.instant('kForceMjpeg')+'</ion-toggle>'+
'<div class="item item-divider" style="background:#666666;color:white;">'
+$translate.instant('kChangeMode')
+'</div><ion-radio-fix ng-repeat="item in monFunctions" ng-value="item.value" ng-model="monfunc.myfunc"> {{item.text}} </ion-radio-fix>',

title: $translate.instant('kChangeSettingsFor') + ' ' + monitorName,

Expand All @@ -154,66 +180,93 @@ angular.module('zmApp.controllers')
var loginData = NVR.getLogin();

$scope.monfunc.mymonitorsIds.forEach(function (item, index) {
var apiMon = loginData.apiurl + "/monitors/" + item + ".json?"+$rootScope.authSession;
NVR.debug("MonitorCtrl: URLs for changeConfig save:" + apiMon);

var data = {};
if ($scope.monfunc.myfunc) data['Monitor[Function]'] = $scope.monfunc.myfunc;
if (isEnabled) data['Monitor[Enabled]'] = isEnabled;

$ionicLoading.show({
template: $translate.instant('kApplyingChanges') + "...",
noBackdrop: true,
duration: zm.largeHttpTimeout,
});

var httpPromise = $http({
url: apiMon,
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': '*/*',
},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" +
encodeURIComponent(obj[p]));
var foo = str.join("&");
NVR.debug("MonitorCtrl: parmeters constructed: " + foo);
return foo;
},
data: data

})
.then(function () {
NVR.debug("MonitorCtrl: Not restarting ZM - Make sure you have the patch installed in MonitorsController.php or this won't work");
},
function (data, status, headers, config) {
NVR.debug("MonitorCtrl: Error changing monitor " + JSON.stringify(data));
$scope.monfunc.myfailedIds.push(item);
});
if (!loginData.monitorSpecific[item]) loginData.monitorSpecific[item] = {};
loginData.monitorSpecific[item].forceMjpeg = $scope.forceMjpeg.value;

$scope.monfunc.mypromises.push(httpPromise);
});
for (var m=0; m < $scope.monitors.length; m++) {
if ($scope.monitors[m].Monitor.Id == item) {
$scope.monitors[m].Monitor.forceMjpeg = $scope.forceMjpeg.value;
break;
}
}

$q.all($scope.monfunc.mypromises).then(function (e) {
$ionicLoading.hide();
// if there's a failed ID, an error has occurred
if ($scope.monfunc.myfailedIds.length != 0) {


if (oldValues.myfunc != $scope.monfunc.myfunc || oldValues.myenabled != isEnabled) {
// lets do HTTP requests only if stuff changes
var apiMon = loginData.apiurl + "/monitors/" + item + ".json?"+$rootScope.authSession;
NVR.debug("MonitorCtrl: URLs for changeConfig save:" + apiMon);

var data = {};
if ($scope.monfunc.myfunc) data['Monitor[Function]'] = $scope.monfunc.myfunc;
if (isEnabled) data['Monitor[Enabled]'] = isEnabled;

$ionicLoading.show({
template: $translate.instant('kErrorChangingMonitors') + ". Monitor IDs : " + $scope.monfunc.myfailedIds.toString(),
template: $translate.instant('kApplyingChanges') + "...",
noBackdrop: true,
duration: 3000,
duration: zm.largeHttpTimeout,
});
} else {

doRefresh();


var httpPromise = $http({
url: apiMon,
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': '*/*',
},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" +
encodeURIComponent(obj[p]));
var foo = str.join("&");
NVR.debug("MonitorCtrl: parmeters constructed: " + foo);
return foo;
},
data: data

})
.then(function () {
NVR.debug("MonitorCtrl: Not restarting ZM - Make sure you have the patch installed in MonitorsController.php or this won't work");
},
function (data, status, headers, config) {
NVR.debug("MonitorCtrl: Error changing monitor " + JSON.stringify(data));
$scope.monfunc.myfailedIds.push(item);
});

$scope.monfunc.mypromises.push(httpPromise);

} else {
NVR.debug ('Not invoing HTTP requests and no functional state changes detected');
}


}); //foreach

NVR.debug ('Updating forcedMjpeg status');
NVR.setLogin(loginData);

if ($scope.monfunc.mypromises.length) {
$q.all($scope.monfunc.mypromises).then(function (e) {
$ionicLoading.hide();
// if there's a failed ID, an error has occurred
if ($scope.monfunc.myfailedIds.length != 0) {
$ionicLoading.show({
template: $translate.instant('kErrorChangingMonitors') + ". Monitor IDs : " + $scope.monfunc.myfailedIds.toString(),
noBackdrop: true,
duration: 3000,
});
} else {

}
})
.catch (noop);
doRefresh();


}
})
.catch (noop);

}

}

},
Expand All @@ -232,6 +285,17 @@ angular.module('zmApp.controllers')
// console.log("**VIEW ** Monitor Ctrl Loaded");
});


$scope.changeForceMjpeg = function (mid, value) {
NVR.debug ("change forceMjpeg for mid:"+mid+" to "+value);
var ld = NVR.getLogin();
if (!ld.monitorSpecific[mid]) ld.monitorSpecific[mid] = {};
ld.monitorSpecific[mid].forceMjpeg = value;
console.log ("UPDATE array:"+JSON.stringify(ld.monitorSpecific));
NVR.setLogin(ld);

};

//-------------------------------------------------------------------------
// Lets make sure we set screen dim properly as we enter
// The problem is we enter other states before we leave previous states
Expand Down Expand Up @@ -309,11 +373,7 @@ angular.module('zmApp.controllers')

});

$scope.$on('$ionicView.leave', function () {
// console.log("**VIEW ** Monitor Ctrl Left, force removing modal");
if ($scope.modal) $scope.modal.remove();
});


$scope.$on('$ionicView.unloaded', function () {
// console.log("**VIEW ** Monitor Ctrl Unloaded");
});
Expand Down Expand Up @@ -414,6 +474,14 @@ angular.module('zmApp.controllers')

if (!$scope.monitors.length) {
$scope.monitorLoadStatus = $translate.instant ('kNoMonitors');
} else {
var mid;
for (var i=0; i < $scope.monitors.length; i++) {
mid = $scope.monitors[i].Monitor.Id;
$scope.monitors[i].Monitor.forceMjpeg = (ld.monitorSpecific[mid] && ld.monitorSpecific[mid].forceMjpeg) ? true:false;
// console.log ('********** Monitor :'+mid+" MJPEG="+$scope.monitors[i].Monitor.forceMjpeg );

}
}

if (!$scope.monitors[0].Monitor_Status ) {
Expand Down
7 changes: 6 additions & 1 deletion www/js/NVR.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ angular.module('zmApp.controllers')
'montageHideFooter': false,
'httpCordovaNoEncode': false,
'currentZMGroupNames': [],
'unsupported': {}
'unsupported': {},
'monitorSpecific': {}


};
Expand Down Expand Up @@ -1762,6 +1763,10 @@ angular.module('zmApp.controllers')
if (typeof loginData.unsupported == 'undefined') {
loginData.unsupported = {};
}

if (typeof loginData.monitorSpecific == 'undefined') {
loginData.monitorSpecific = {};
}



Expand Down
1 change: 1 addition & 0 deletions www/lang/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"kFootage" :"Footage",
"kForceAlarmConfirm" :"Are you sure you want to force an alarm for Monitor:",
"kForcingAlarm" :"forcing alarm",
"kForceMjpeg" :"force MJPEG event playback",
"kFrame" :"frame",
"kFrameUpdate" :"Frame update",
"kFrames" :"frames",
Expand Down
Loading

0 comments on commit 32d0711

Please sign in to comment.