Skip to content

Commit

Permalink
Implemented auth key into the app so each image refresh in Montage an…
Browse files Browse the repository at this point in the history
…d Monitor view does not hit the ZM DB and generate a million records. Solves the log pings of https://github.com/pliablepixels/zmNinja/issues/26
  • Loading branch information
pliablepixels committed Aug 28, 2015
1 parent 4328d96 commit 7da9e23
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 12 deletions.
52 changes: 52 additions & 0 deletions www/js/DataModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,56 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion
{
displayBanner (mytype, mytext, myinterval, mytimer);
},

//-----------------------------------------------------------------------------
// Grabs the computed auth key for streaming
// FIXME: Currently a hack - does a screen parse - convert to API based support
//-----------------------------------------------------------------------------

getAuthKey: function ()
{
var d=$q.defer();
// Skipping monitor number as I only need an auth key
// so no need to generate an image
var myurl =loginData.url+"/index.php?view=watch";
console.log ("Getting auth from " + myurl);
$http.get (myurl)
.then (function (success) {
// console.log ("**** RESULT IS " + JSON.stringify(success));
// Look for auth=
var auth = success.data.match ("auth=(.*?)&");
if (auth && (auth[1] != null))
{
zmLog ("DataModel: Extracted a stream authentication key of: " + auth[1]);
d.resolve("&auth="+auth[1]);
}
else
{
zmLog ("DataModel: Did not find a stream auth key, looking for user=");
auth = success.data.match ("user=(.*?)&");
if (auth && (auth[1] != null))
{
zmLog ("DataModel: Found simple stream auth mode (user=)");
d.resolve("&user="+loginData.username+"&pass="+loginData.password);
}
else
{
zmLog ("Data Model: Did not find any stream mode of auth");
d.resolve("");
}
return (d.promise);
}

},
function (error) {
zmLog ("DataModel: Error resolving auth key " + JSON.stringify(error));
d.resolve ("");
return (d.promise);
});
return (d.promise);

},

//-----------------------------------------------------------------------------
// This function returns the numdigits for padding capture images
//-----------------------------------------------------------------------------
Expand All @@ -298,6 +348,7 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion
zmLog ("ZM_EVENT_IMAGE_DIGITS is " + data.config.Value);
configParams.ZM_EVENT_IMAGE_DIGITS = data.config.Value;
d.resolve(configParams.ZM_EVENT_IMAGE_DIGITS);
return (d.promise);

})
.error (function(err) {
Expand All @@ -306,6 +357,7 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion
// FIXME: take a plunge and keep it at 5?
configParams.ZM_EVENT_IMAGE_DIGITS = 5;
d.resolve(configParams.ZM_EVENT_IMAGE_DIGITS);
return (d.promise);
});
}
else
Expand Down
28 changes: 28 additions & 0 deletions www/js/ModalCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ angular.module('zmApp.controllers').controller('ModalCtrl', ['$scope', '$rootSco
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);

$rootScope.authSession = "undefined";
$ionicLoading.show({
template: 'negotiating stream authentication...',
animation: 'fade-in',
showBackdrop: true,
duration: zm.loadingTimeout,
maxWidth: 300,
showDelay: 0
});
var ld = ZMDataModel.getLogin();
ZMDataModel.getAuthKey()
.then(function(success)
{
$ionicLoading.hide();
$rootScope.authSession = success;
ZMDataModel.zmLog ("Modal: Stream authentication construction: " + $rootScope.authSession);

},
function (error)
{

$ionicLoading.hide();
console.log (error);
//$rootScope.authSession="";
ZMDataModel.zmLog ("Modal: Error returned Stream authentication construction. Retaining old value of: " + $rootScope.authSession);
});



$scope.radialMenuOptions = {
content: '',
Expand Down
32 changes: 32 additions & 0 deletions www/js/MontageCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,38 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', '
$scope.LoginData = ZMDataModel.getLogin();
$scope.monLimit = $scope.LoginData.maxMontage;
console.log("********* Inside Montage Ctrl, MAX LIMIT=" + $scope.monLimit);


$rootScope.authSession = "undefined";
$ionicLoading.show({
template: 'negotiating stream authentication...',
animation: 'fade-in',
showBackdrop: true,
duration: zm.loadingTimeout,
maxWidth: 300,
showDelay: 0
});


var ld = ZMDataModel.getLogin();
ZMDataModel.getAuthKey()
.then(function(success)
{
$ionicLoading.hide();
console.log (success);
$rootScope.authSession =success;
ZMDataModel.zmLog ("Stream authentication construction: " +
$rootScope.authSession);

},
function (error)
{

$ionicLoading.hide();
console.log (error);
//$rootScope.authSession="";
ZMDataModel.zmLog ("Modal: Error returned Stream authentication construction. Retaining old value of: " + $rootScope.authSession);
});


// I was facing a lot of problems with Chrome/crosswalk getting stuck with
Expand Down
20 changes: 20 additions & 0 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,26 @@ angular.module('zmApp', [

d.reject("Login Error");
}

// Now go ahead and re-get auth key
$rootScope.authSession="undefined";
var ld = ZMDataModel.getLogin();
ZMDataModel.getAuthKey()
.then(function(success)
{

console.log (success);
$rootScope.authSession = success;
ZMDataModel.zmLog ("Stream authentication construction: " +
$rootScope.authSession);

},
function (error)
{
console.log (error);
//$rootScope.authSession="";
ZMDataModel.zmLog ("Modal: Error returned Stream authentication construction. Retaining old value of: " + $rootScope.authSession);
});


return (d.promise);
Expand Down
15 changes: 10 additions & 5 deletions www/templates/monitors-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
<!-- android needs this 100vh - otherwise max- does not work -->

<div style="height: 100vh;" class="main">

<img imageonload="finishedLoadingImage()"
image-spinner-loader="lines"
image-spinner-src="{{LoginData.streamingurl}}/cgi-bin/nph-zms?mode=single&monitor={{monitorId}}&maxfps={{LoginData.maxFPS}}&user={{LoginData.username}}&pass={{LoginData.password}}&rand={{$root.modalRand}}" ng-class="{'zm-image-fit':imageFit==true, 'zm-image-crop':imageFit==false}" on-swipe-left="onSwipeLeft(monitorId,-1)" on-swipe-right="onSwipeRight(monitorId,1)" />
<div ng-if="$root.authSession!='undefined'">
<img imageonload="finishedLoadingImage()"
image-spinner-loader="lines"
image-spinner-src="{{LoginData.streamingurl}}/cgi-bin/nph-zms?mode=single&monitor={{monitorId}}&maxfps={{LoginData.maxFPS}}{{$root.authSession}}&rand={{$root.modalRand}}" ng-class="{'zm-image-fit':imageFit==true, 'zm-image-crop':imageFit==false}" on-swipe-left="onSwipeLeft(monitorId,-1)" on-swipe-right="onSwipeRight(monitorId,1)" />
</div>
<div ng-if="$root.authSession=='undefined'">
<img id="img-$index" ng-src="img/pausevideo.png" style="display:block;"
width="{{((devWidth)/(7-monitorSize[$index]))}}px;"/>
</div>
</div>
</ion-scroll>

<!--url: {{LoginData.streamingurl}}/cgi-bin/nph-zms?mode=single&amp;monitor={{monitorId}}&amp;maxfps={{LoginData.maxFPS}}&amp;{{$root.authSession}}&amp;rand={{$root.modalRand}}-->
</ion-content>


Expand Down
22 changes: 15 additions & 7 deletions www/templates/montage.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,23 @@
<!-- moving to single so I can rely on rand for reloads -->

<div ng-if="!isModalActive">
<img id="img-$index" image-spinner-src="{{LoginData.streamingurl}}/cgi-bin/nph-zms?mode=single&monitor={{monitor.Monitor.Id}}&maxfps={{LoginData.maxFPS}}&scale=50&user={{LoginData.username}}&pass={{LoginData.password}}&rand={{$root.rand}}" width="{{((devWidth)/(7-monitorSize[$index]))}}px;"
ng-click="openModal(monitor.Monitor.Id, monitor.Monitor.Controllable, monitor.Monitor.ControlId)"
on-hold="onHold($index)"
on-release="onRelease($index)"
style="display:block;" image-spinner-loader="lines"

/>

<div ng-if="$root.authSession!='undefined'">
<img id="img-$index" image-spinner-src="{{LoginData.streamingurl}}/cgi-bin/nph-zms?mode=single&monitor={{monitor.Monitor.Id}}&maxfps={{LoginData.maxFPS}}&scale=50{{$root.authSession}}&rand={{$root.rand}}" width="{{((devWidth)/(7-monitorSize[$index]))}}px;"
ng-click="openModal(monitor.Monitor.Id, monitor.Monitor.Controllable, monitor.Monitor.ControlId)"
on-hold="onHold($index)"
on-release="onRelease($index)"
style="display:block;" image-spinner-loader="lines"

/>
</div>
<div ng-if="!$root.authSession=='undefined'">
<img id="img-$index" ng-src="img/pausevideo.png" style="display:block;"
width="{{((devWidth)/(7-monitorSize[$index]))}}px;"/>
</div>
</div>

<!--url: {{LoginData.streamingurl}}/cgi-bin/nph-zms?mode=single&amp;monitor={{monitor.Monitor.Id}}&amp;maxfps={{LoginData.maxFPS}}&amp;scale=50&amp;{{$root.authSession}}&amp;rand={{$root.rand}}-->
<div ng-if="isModalActive">
<img id="img-$index" ng-src="img/pausevideo.png" style="display:block;" width="{{((devWidth)/(7-monitorSize[$index]))}}px;"/>
</div>
Expand Down

0 comments on commit 7da9e23

Please sign in to comment.