X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-demo.git;a=blobdiff_plain;f=afb-client%2Fapp%2FFrontend%2Fetc%2FAppConfig.js;fp=afb-client%2Fapp%2FFrontend%2Fetc%2FAppConfig.js;h=5c9283ef882ae0db79635224d30116341a8e2741;hp=bd1aae093708930940353f0d45aedfe7348de1c6;hb=7b8fe1b305a36f925fc2757a2c126c88fb0a5137;hpb=35698424ab8973d91208df92471d18b1c901220e diff --git a/afb-client/app/Frontend/etc/AppConfig.js b/afb-client/app/Frontend/etc/AppConfig.js index bd1aae0..5c9283e 100644 --- a/afb-client/app/Frontend/etc/AppConfig.js +++ b/afb-client/app/Frontend/etc/AppConfig.js @@ -23,7 +23,7 @@ ping : '/api/token/check', initial : urlquery.token || '123456789', // typical dev initial token timeout : 3600, // timeout is updated client sessin context creation - pingrate: 60, // Ping rate to check if server is still alive + pingrate: 30, // Ping rate to check if server is still alive uuid : '', // uuid map with cookie or long term session access key token : '' // will be returned from authentication } @@ -33,16 +33,28 @@ }) // Factory is a singleton and share its context within all instances. - .factory('AppCall', function ($http, AppConfig) { + .factory('AppCall', function ($http, AppConfig, $log) { var myCalls = { - get : function(plugin, action, query, callback) { - if (!query.token) query.token = AppConfig.session.token; // add token to provided query - $http.get('/api/' + plugin + '/' + action , {params: query}).then (callback, callback); + get : function(plugin, action, query, cbresponse, cberror) { + if (!query.token) query.token = AppConfig.session.token; // add token to provided query + var handle= $http.get('/api/' + plugin + '/' + action , {params: query}).then (onsuccess, onerror); + + handle.onsuccess (function(data, errcode, headers, config) { + // if token was updated keep it within application cache + if (data.request.token) AppConfig.session.token = data.request.token; + if (data.request.uuid) AppConfig.session.uuid = data.request.uuid; + if (data.request.timeout) AppConfig.session.timeout = data.request.timeout; + + cbresponse(data, errcode, headers, config); + }); + + handle.onerror (function(data, errcode, headers, config) { + if (cberror) cberror(data, errcode, headers, config); + else cbresponse(data, errcode, headers, config); + }); } - }; return myCalls; }); - })(); \ No newline at end of file