diff options
| author | pliablepixels <pliablepixels@gmail.com> | 2016-01-23 09:53:04 -0500 |
|---|---|---|
| committer | pliablepixels <pliablepixels@gmail.com> | 2016-01-23 09:53:04 -0500 |
| commit | 7e78751d1240c9649f7fdd93bb60ec11a18e0125 (patch) | |
| tree | 209f5b45806fbddf6c68071a726e637f85877caf /www/js/app.js | |
| parent | 5a80b2394a4bedd1212835c6dfb00fb0300893f1 (diff) | |
#147- undid auth approach -- causes problems with streaming images - we never get to success - screw it - lets see who complains
Former-commit-id: c1b7759465cf79b414c40aa241df011ffee85285
Diffstat (limited to 'www/js/app.js')
| -rw-r--r-- | www/js/app.js | 121 |
1 files changed, 92 insertions, 29 deletions
diff --git a/www/js/app.js b/www/js/app.js index d0e96838..619ae051 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -69,9 +69,64 @@ angular.module('zmApp', [ }) -//credit http://stackoverflow.com/questions/20997406/force-http-interceptor-in-dynamic-ngsrc-request + +//credit: http://stackoverflow.com/questions/34958575/intercepting-img-src-via-http-interceptor-as-well-as-not-lose-the-ability-to-kee .directive('httpSrc', [ - '$http', 'imageLoadingDataShare', function ($http, imageLoadingDataShare) { + '$http', 'imageLoadingDataShare', 'ZMDataModel', + function ($http, imageLoadingDataShare, ZMDataModel) { + var directive = { + link: postLink, + restrict: 'A' + }; + return directive; + + function postLink(scope, element, attrs) { + console.log ("HELLO NEW"); + var requestConfig = { + method: 'GET', + //url: attrs.httpSrc, + responseType: 'arraybuffer', + cache: 'true' + }; + + function base64Img(data) { + var arr = new Uint8Array(data); + var raw = ''; + var i, j, subArray, chunk = 5000; + for (i = 0, j = arr.length; i < j; i += chunk) { + subArray = arr.subarray(i, i + chunk); + raw += String.fromCharCode.apply(null, subArray); + } + return btoa(raw); + } + attrs.$observe('httpSrc', function (newValue) { + requestConfig.url = newValue; + console.log ("requestConfig is " + JSON.stringify(requestConfig)); + imageLoadingDataShare.set(1); + $http(requestConfig) + .success(function (data) { + console.log ("Inside HTTP after Calling " + requestConfig.url); + //console.log ("data got " + JSON.stringify(data)); + + + var b64 = base64Img(data); + attrs.$set('src', "data:image/jpeg;base64," + b64); + imageLoadingDataShare.set(0); + }); + }); + + } + } +]) + + + + + + +//credit http://stackoverflow.com/questions/20997406/force-http-interceptor-in-dynamic-ngsrc-request +.directive('httpSrcOld', [ + '$http', 'imageLoadingDataShare', 'ZMDataModel', function ($http, imageLoadingDataShare, ZMDataModel) { var directive = { link: link, restrict: 'A' @@ -79,34 +134,42 @@ angular.module('zmApp', [ return directive; function link(scope, element, attrs) { - var requestConfig = { - method: 'Get', - url: attrs.httpSrc, - responseType: 'arraybuffer', - cache: 'true' - }; - - imageLoadingDataShare.set(1); - $http(requestConfig) - .success(function(data) { - var arr = new Uint8Array(data); - - var raw = ''; - var i, j, subArray, chunk = 5000; - for (i = 0, j = arr.length; i < j; i += chunk) { - subArray = arr.subarray(i, i + chunk); - raw += String.fromCharCode.apply(null, subArray); - } + + console.log ("HELLO OLD"); + + var requestConfig = { + method: 'Get', + url: attrs.httpSrcOld, + responseType: 'arraybuffer', + cache: 'true' + }; + + console.log ("Calling " + requestConfig.url); + imageLoadingDataShare.set(1); + $http(requestConfig) + .success(function(data) { + + console.log ("data got " + JSON.stringify(data)); + var arr = new Uint8Array(data); + + var raw = ''; + var i, j, subArray, chunk = 5000; + for (i = 0, j = arr.length; i < j; i += chunk) { + subArray = arr.subarray(i, i + chunk); + raw += String.fromCharCode.apply(null, subArray); + } - var b64 = btoa(raw); + var b64 = btoa(raw); - attrs.$set('src', "data:image/jpeg;base64," + b64); - imageLoadingDataShare.set(0); - }) - .error (function(data) { - attrs.$set('src', 'img/novideo.png'); - imageLoadingDataShare.set(0); - }); + attrs.$set('src', "data:image/jpeg;base64," + b64); + imageLoadingDataShare.set(0); + }) + .error (function(data) { + attrs.$set('src', 'img/novideo.png'); + imageLoadingDataShare.set(0); + ZMDataModel.zmDebug ("Inside http-src err"); + }); + } } @@ -308,7 +371,7 @@ angular.module('zmApp', [ // console.log ("Parsed data is " + JSON.stringify(components)); var credentials = btoa(components.userinfo); //var authorization = {'Authorization': 'Basic ' + credentials}; - config.headers.Authorization = 'Basic ' + credentials; + //config.headers.Authorization = 'Basic ' + credentials; // console.log ("Full headers: " + JSON.stringify(config.headers)); |
