Comparing version 0.0.69 to 0.0.70
54
index.js
@@ -6,2 +6,3 @@ import { Network } from '@capacitor/network' | ||
console.log('fwk-api CONSTRUCTOR') | ||
let srv | ||
@@ -11,2 +12,3 @@ const initSAF = localStorage.safList ?? '[]' | ||
let evt = new EventEmitter() | ||
let processingSAFFlag = false | ||
@@ -28,19 +30,6 @@ const api = { | ||
//srv.interceptors.request.use(req => { | ||
// console.log('interceptor request:' + req) | ||
// return req | ||
//}) | ||
//srv.interceptors.response.use(res => { | ||
// console.log('interceptor response: ' + res) | ||
// return res.data | ||
//}, | ||
// error => { | ||
// const { config } = error | ||
// console.log('Error FWK-API!!!! :' + error) | ||
// } | ||
//) | ||
Network.addListener('networkStatusChange', async (netSt) => { | ||
console.log('fwk-api => Network status changed: ' + netSt) | ||
const status = netSt.connectionType | ||
if ((status === 'wifi' || status === 'cellular' || !status) && (safList.length > 0)) { | ||
if ((status === 'wifi' || status === 'cellular' || !status) && (safList.length > 0) && (!processingSAFFlag)) { | ||
processSAF() | ||
@@ -50,10 +39,11 @@ } | ||
App.addListener('appStateChange', ({ isActive }) => { | ||
console.log('fwk-qpi => App state changed. Is active? ' + isActive) | ||
if (isActive && safList.length > 0) | ||
console.log('fwk-api => App state changed. Is active? ' + isActive) | ||
if (isActive && (safList.length > 0) && (!processingSAFFlag)) | ||
processSAF() | ||
}) | ||
if (safList.length > 0) { | ||
console.log('fwk-api => init fwkApi validation SAF', safList.length) | ||
const netRes = await Network.getStatus() //'wifi' | 'cellular' | 'none' | 'unknown' | ||
const status = netRes.connectionType | ||
if (status === 'wifi' || status === 'cellular' || !status) | ||
if ((status === 'wifi' || status === 'cellular' || !status) && (!processingSAFFlag)) | ||
processSAF() | ||
@@ -63,2 +53,17 @@ else | ||
} | ||
//srv.interceptors.request.use(req => { | ||
// console.log('interceptor request:' + req) | ||
// return req | ||
//}) | ||
//srv.interceptors.response.use(res => { | ||
// console.log('interceptor response: ' + res) | ||
// return res.data | ||
//}, | ||
// error => { | ||
// const { config } = error | ||
// console.log('Error FWK-API!!!! :' + error) | ||
// } | ||
//) | ||
}, | ||
@@ -138,12 +143,19 @@ async setHeaders (headers) { | ||
async function processSAF () { | ||
localStorage.processingSAFFlag = true | ||
console.log('fwk-api => safList:' + JSON.stringify(safList)) | ||
console.time('processSAF') | ||
for (const elem of safList) { | ||
await api.callSrv(elem.method, elem.path, elem.params) | ||
while (safList.length > 0) { | ||
try { | ||
const { method, path, params } = safList[0] | ||
await api.callSrv(method, path, params) | ||
saflist.shift() | ||
localStorage.safList = JSON.stringify(safList) | ||
} catch (error) { | ||
console.log('error proccesing saf:', error) | ||
} | ||
} | ||
safList = [] | ||
localStorage.safList = JSON.stringify(safList) | ||
console.timeEnd('processSAF') | ||
evt.emit('onSAFCompleted') | ||
evt.emit('onNewPendingTask', safList.length) | ||
localStorage.processingSAFFlag = false | ||
} | ||
@@ -150,0 +162,0 @@ function queueSAF (obj) { |
{ | ||
"name": "fwk-api", | ||
"version": "0.0.69", | ||
"version": "0.0.70", | ||
"description": "Framework with api services access(only javascript)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
5894
152