diff options
| author | PliablePixels <pliablepixels@gmail.com> | 2015-08-28 11:52:59 -0400 |
|---|---|---|
| committer | PliablePixels <pliablepixels@gmail.com> | 2015-08-28 11:52:59 -0400 |
| commit | b9f387782bf9ea222d52eac954f1bddad8131391 (patch) | |
| tree | 94e349c9e2ff709237e32adf0cc9f25632391874 /www/js/DataModel.js | |
| parent | 4332c99d924cd00b6a6e5f1b306db8da58b2ab59 (diff) | |
Implemented auth key into the app so each image refresh in Montage and 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
Diffstat (limited to 'www/js/DataModel.js')
| -rw-r--r-- | www/js/DataModel.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js index 44992a3f..48a09b52 100644 --- a/www/js/DataModel.js +++ b/www/js/DataModel.js @@ -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 //----------------------------------------------------------------------------- @@ -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) { @@ -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 |
