react-native-mosquito-transport 0.0.55 → 0.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/helpers/utils.js +19 -7
- package/src/index.js +4 -4
- package/src/products/auth/accessor.js +3 -3
package/package.json
CHANGED
package/src/helpers/utils.js
CHANGED
|
@@ -155,17 +155,27 @@ export const awaitStore = () => new Promise(resolve => {
|
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
export const checkAreYouOk = (projectUrl) => {
|
|
159
|
-
if (!Scoped.AreYouOkPromise[projectUrl]) {
|
|
158
|
+
export const checkAreYouOk = (projectUrl, refresh) => {
|
|
159
|
+
if (!Scoped.AreYouOkPromise[projectUrl] || refresh) {
|
|
160
160
|
Scoped.IS_CONNECTED[projectUrl] = undefined;
|
|
161
161
|
ServerReachableListener.dispatchPersist(projectUrl, undefined);
|
|
162
162
|
|
|
163
|
+
const thatState = AppState.currentState;
|
|
164
|
+
|
|
163
165
|
const promise = fetch(engine_api._areYouOk(projectUrl), { credentials: 'omit' })
|
|
164
166
|
.then(async r => (await r.json()).status === 'yes')
|
|
165
167
|
.catch(() => false)
|
|
166
168
|
.then(async connected => {
|
|
167
|
-
Scoped.
|
|
168
|
-
|
|
169
|
+
const thatPromise = Scoped.AreYouOkPromise[projectUrl];
|
|
170
|
+
if (thatPromise !== promise) {
|
|
171
|
+
if (thatPromise) return thatPromise;
|
|
172
|
+
return Scoped.IS_CONNECTED[projectUrl];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (thatState === AppState.currentState) {
|
|
176
|
+
Scoped.IS_CONNECTED[projectUrl] = connected;
|
|
177
|
+
ServerReachableListener.dispatchPersist(projectUrl, connected);
|
|
178
|
+
}
|
|
169
179
|
|
|
170
180
|
delete Scoped.AreYouOkPromise[projectUrl];
|
|
171
181
|
return connected;
|
|
@@ -180,8 +190,10 @@ export const checkAreYouOk = (projectUrl) => {
|
|
|
180
190
|
export const listenReachableServer = (callback, projectUrl) => {
|
|
181
191
|
let lastValue;
|
|
182
192
|
return ServerReachableListener.listenToPersist(projectUrl, t => {
|
|
183
|
-
if (typeof t === 'boolean' && t !== lastValue)
|
|
184
|
-
|
|
193
|
+
if (typeof t === 'boolean' && t !== lastValue) {
|
|
194
|
+
callback?.(t);
|
|
195
|
+
lastValue = t;
|
|
196
|
+
}
|
|
185
197
|
});
|
|
186
198
|
};
|
|
187
199
|
|
|
@@ -208,7 +220,7 @@ export const awaitReachableServer = (projectUrl, pauseForRetry) =>
|
|
|
208
220
|
}
|
|
209
221
|
|
|
210
222
|
if (pauseForRetry) {
|
|
211
|
-
setTimeout(check, Number.isInteger(pauseForRetry) ? pauseForRetry :
|
|
223
|
+
setTimeout(check, Number.isInteger(pauseForRetry) ? pauseForRetry : 500);
|
|
212
224
|
} else check();
|
|
213
225
|
});
|
|
214
226
|
|
package/src/index.js
CHANGED
|
@@ -89,10 +89,10 @@ class RNMT {
|
|
|
89
89
|
});
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
-
const manualCheckConnection = () => {
|
|
92
|
+
const manualCheckConnection = (refresh) => {
|
|
93
93
|
const ref = ++connectionIte;
|
|
94
94
|
|
|
95
|
-
checkAreYouOk(projectUrl).then(ok => {
|
|
95
|
+
checkAreYouOk(projectUrl, refresh).then(ok => {
|
|
96
96
|
if (ref !== connectionIte) return;
|
|
97
97
|
if (ok) {
|
|
98
98
|
onConnect();
|
|
@@ -111,11 +111,11 @@ class RNMT {
|
|
|
111
111
|
|
|
112
112
|
socket.on('connect', onConnect);
|
|
113
113
|
socket.on('disconnect', () => {
|
|
114
|
-
manualCheckConnection();
|
|
114
|
+
manualCheckConnection(true);
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
AppState.addEventListener('change', s => {
|
|
118
|
-
manualCheckConnection();
|
|
118
|
+
if (s === 'active') manualCheckConnection();
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
const updateMountedToken = () => {
|
|
@@ -168,7 +168,7 @@ export const getEmulatedLinks = (projectUrl) =>
|
|
|
168
168
|
.filter(([_, v]) => v === projectUrl)
|
|
169
169
|
.map(v => v[0]);
|
|
170
170
|
|
|
171
|
-
const refreshToken = (builder, remainRetries =
|
|
171
|
+
const refreshToken = (builder, remainRetries = 3) =>
|
|
172
172
|
new Promise(async (resolve, reject) => {
|
|
173
173
|
const { projectUrl, serverE2E_PublicKey, uglify, extraHeaders } = builder;
|
|
174
174
|
|
|
@@ -206,7 +206,7 @@ const refreshToken = (builder, remainRetries = 1, isForceRefresh) =>
|
|
|
206
206
|
Scoped.AuthJWTToken[v] = f.result.token;
|
|
207
207
|
|
|
208
208
|
triggerAuthToken(v, isInit);
|
|
209
|
-
if (
|
|
209
|
+
if (isInit) Scoped.InitiatedForcedToken[v] = true;
|
|
210
210
|
});
|
|
211
211
|
updateCacheStore(['AuthStore']);
|
|
212
212
|
initTokenRefresher({ config: builder });
|
|
@@ -222,7 +222,7 @@ const refreshToken = (builder, remainRetries = 1, isForceRefresh) =>
|
|
|
222
222
|
console.error(`refreshToken retry limit exceeded err:`, e);
|
|
223
223
|
} else {
|
|
224
224
|
awaitReachableServer(projectUrl, true).then(() => {
|
|
225
|
-
refreshToken(builder, remainRetries - 1
|
|
225
|
+
refreshToken(builder, remainRetries - 1).then(resolve, reject);
|
|
226
226
|
});
|
|
227
227
|
}
|
|
228
228
|
}
|