1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
// Controller for the montage view
/* jshint -W041 */
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console */
angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', '$rootScope', 'ZMDataModel', 'message', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', function ($scope, $rootScope, ZMDataModel, message, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http) {
var timestamp = new Date().getUTCMilliseconds();
$scope.togglePTZ = function () {
$scope.showPTZ = !$scope.showPTZ;
};
$scope.radialMenuOptions = {
content: '',
background: '#2F4F4F',
isOpen: false,
toggleOnClick: false,
button: {
cssClass: "fa fa-arrows-alt",
},
items: [
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'Down');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'DownLeft');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'Left');
}
},
{
content: 'D',
empty: true,
onclick: function () {
console.log('About');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'UpLeft');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'Up');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'UpRight');
}
},
{
content: 'H',
empty: true,
onclick: function () {
console.log('About');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'Right');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'DownRight');
}
},
{
content: 'K',
empty: true,
onclick: function () {
console.log('About');
}
},
]
};
function controlPTZ(monitorId, cmd) {
// curl -X POST "http://arjunrc.ddns.net:9898/zm/index.php" -d "view=request&request=control&user=admin&passwd=indiglo&id=4&control=moveConLeft"
//curl -X POST "http://server.com/zm/index.php?view=request" -d "request=control&user=admin&passwd=xx&id=4&control=moveConLeft"
console.log("Command value " + cmd + " with MID=" + monitorId);
if (ZMDataModel.isSimulated()) {
var str = "simulation mode. no action taken";
$ionicLoading.show({
template: str,
noBackdrop: true,
duration: 3000
});
return;
}
$ionicLoading.hide();
$ionicLoading.show({
template: "please wait...",
noBackdrop: true,
duration: 15000,
});
var loginData = ZMDataModel.getLogin();
/* $http({
method:'POST',
url:loginData.url + '/index.php',
headers:{
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" +
encodeURIComponent(obj[p]));
var foo = str.join("&");
console.log("****RETURNING " + foo);
return foo;
},
data: {
username:loginData.username,
password:loginData.password,
action:"login",
view:"console"
}
})
.success (function(data,status,header,config)
{*/
$ionicLoading.hide();
$ionicLoading.show({
template: "Sending PTZ..",
noBackdrop: true,
duration: 15000,
});
// console.log ("ANGULAR VERSION: "+JSON.stringify(angular.version));
// console.log('Set-Cookie'+ header('Set-Cookie')); //
var req = $http({
method: 'POST',
/*timeout: 15000,*/
url: loginData.url + '/index.php',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" +
encodeURIComponent(obj[p]));
var foo = str.join("&");
console.log("****RETURNING " + foo);
return foo;
},
data: {
view: "request",
request: "control",
id: monitorId,
//connkey: $scope.connKey,
control: "moveCon" + cmd,
xge: "30",
yge: "30",
//user: loginData.username,
//pass: loginData.password
}
});
req.success(function (resp) {
$ionicLoading.hide();
console.log("SUCCESS: " + JSON.stringify(resp));
// $ionicLoading.hide();
});
req.error(function (resp) {
$ionicLoading.hide();
console.log("ERROR: " + JSON.stringify(resp));
});
//});
}
// same logic as EventCtrl.js
$scope.finishedLoadingImage = function () {
console.log("***Monitor image FINISHED Loading***");
$ionicLoading.hide();
/* $ionicLoading.show({
template: "loading, please wait...",
noBackdrop: true,
});*/
};
$scope.openModal = function (mid, controllable) {
console.log("Open Monitor Modal");
$scope.monitorId = mid;
$scope.LoginData = ZMDataModel.getLogin();
$scope.rand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111;
// This is a modal to show the monitor footage
$ionicModal.fromTemplateUrl('templates/monitors-modal.html', {
scope: $scope,
animation: 'slide-in-up'
})
.then(function (modal) {
$scope.modal = modal;
$ionicLoading.show({
template: "please wait...",
noBackdrop: true,
duration: 15000
});
$scope.isControllable = controllable;
$scope.showPTZ = false;
$scope.modal.show();
});
};
$scope.closeModal = function () {
console.log("Close & Destroy Monitor Modal");
$scope.modal.remove();
};
// In Android, the app runs full steam while in background mode
// while in iOS it gets suspended unless you ask for specific resources
// So while this view, we DON'T want Android to keep sending 1 second
// refreshes to the server for images we are not seeing!
function onPause() {
console.log("*** Moving to Background ***"); // Handle the pause event
console.log("*** CANCELLING INTERVAL ****");
$interval.cancel(intervalHandle);
}
document.addEventListener("pause", onPause, false);
// I was facing a lot of problems with Chrome/crosswalk getting stuck with
// pending HTTP requests after a while. There is a problem with chrome handling
// multiple streams of always open HTTP get's (image streaming). This problem
// does not arise when the image is streamed for a single monitor - just multiple
// To work around this I am taking a single snapshot of ZMS and have implemented a timer
// to reload the snapshot every 1 second. Seems to work reliably even thought its a higer
// load. Will it bonk with many monitors? Who knows. I have tried with 5 and 1280x960@32bpp
this.loadNotifications = function () {
// randomval is appended to img src, so after each interval the image reloads
$scope.randomval = (new Date()).getTime();
//console.log ("**** NOTIFICATION with rand="+$scope.randomval+"*****");
};
var intervalHandle = $interval(function () {
this.loadNotifications();
}.bind(this), 1000);
this.loadNotifications();
$scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
};
$scope.$on('$destroy', function () {
console.log("*** CANCELLING INTERVAL ****");
$interval.cancel(intervalHandle);
});
$scope.$on('$ionicView.loaded', function () {
console.log("**VIEW ** Montage Ctrl Loaded");
});
$scope.$on('$ionicView.enter', function () {
console.log("**VIEW ** Montage Ctrl Entered");
});
$scope.$on('$ionicView.leave', function () {
console.log("**VIEW ** Montage Ctrl Left");
});
$scope.$on('$ionicView.unloaded', function () {
console.log("**VIEW ** Montage Ctrl Unloaded");
});
$scope.isSimulated = function () {
return ZMDataModel.isSimulated();
};
$scope.LoginData = ZMDataModel.getLogin();
$scope.monLimit = $scope.LoginData.maxMontage;
console.log("********* Inside Montage Ctrl, MAX LIMIT=" + $scope.monLimit);
// slider is tied to the view slider for montage
//Remember not to use a variable. I'm using an object
// so it's passed as a reference - otherwise it makes
// a copy and the value never changes
$scope.slider = {};
$scope.slider.monsize = ZMDataModel.getMontageSize();
$scope.$on('$ionicView.afterEnter', function () {
// This rand is really used to reload the monitor image in img-src so it is not cached
// I am making sure the image in montage view is always fresh
// I don't think I am using this anymore FIXME: check and delete if needed
$rootScope.rand = Math.floor((Math.random() * 100000) + 1);
});
// we are monitoring the slider for movement here
// make sure this is an object - so its passed by reference from the template to the controller!
$scope.$watch('slider.monsize', function () {
console.log('Slider has changed');
ZMDataModel.setMontageSize($scope.slider.monsize);
console.log("Rootscope Montage is " + ZMDataModel.getMontageSize() + " and slider montage is " + $scope.slider.monsize);
});
$scope.monitors = [];
console.log("Inside MontageCtrl waiting for monitors to load...");
$scope.monitors = message;
console.log("I have received the monitors inside Montage and there are " + $scope.monitors.length);
$scope.doRefresh = function () {
console.log("***Pull to Refresh");
$scope.monitors = [];
var refresh = ZMDataModel.getMonitors(1);
refresh.then(function (data) {
$scope.monitors = data;
$scope.$broadcast('scroll.refreshComplete');
});
};
}]);
|