@ray-js/lock-sdk 1.1.3-beta.4 → 1.1.3-beta.5
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/lib/unlock-method.js +34 -7
- package/package.json +1 -1
package/lib/unlock-method.js
CHANGED
|
@@ -225,12 +225,40 @@ const addUnlockMethodData = {
|
|
|
225
225
|
userId: "",
|
|
226
226
|
unlockDpId: 0,
|
|
227
227
|
timeout: 15000,
|
|
228
|
+
canEmitEvents: true,
|
|
229
|
+
pendingEvents: [],
|
|
230
|
+
releaseEmitTimer: 0,
|
|
231
|
+
};
|
|
232
|
+
const dispatchAddUnlockMethodEvent = (eventData) => {
|
|
233
|
+
if (emitter.hasListener(UNLOCK_METHOD_EVENT)) {
|
|
234
|
+
emitter.emit(UNLOCK_METHOD_EVENT, eventData);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
emitter.cache(UNLOCK_METHOD_EVENT, eventData);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
const emitAddUnlockMethodEvent = (eventData) => {
|
|
241
|
+
if (!addUnlockMethodData.canEmitEvents) {
|
|
242
|
+
addUnlockMethodData.pendingEvents.push(eventData);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
dispatchAddUnlockMethodEvent(eventData);
|
|
246
|
+
};
|
|
247
|
+
const releaseAddUnlockMethodEventsAfterStart = () => {
|
|
248
|
+
clearTimeout(addUnlockMethodData.releaseEmitTimer);
|
|
249
|
+
addUnlockMethodData.releaseEmitTimer = setTimeout(() => {
|
|
250
|
+
addUnlockMethodData.canEmitEvents = true;
|
|
251
|
+
const pendingEvents = addUnlockMethodData.pendingEvents.splice(0);
|
|
252
|
+
pendingEvents.forEach((eventData) => {
|
|
253
|
+
dispatchAddUnlockMethodEvent(eventData);
|
|
254
|
+
});
|
|
255
|
+
}, 0);
|
|
228
256
|
};
|
|
229
257
|
const handleAddTimeout = (timeout = 15000) => {
|
|
230
258
|
clearTimeout(addUnlockMethodData.timeoutId);
|
|
231
259
|
addUnlockMethodData.timeoutId = setTimeout(() => {
|
|
232
260
|
emitter.off(DPCHANGE, handleAddReport);
|
|
233
|
-
|
|
261
|
+
emitAddUnlockMethodEvent({
|
|
234
262
|
type: addUnlockMethodData.unlockMethodConfig.type,
|
|
235
263
|
stage: "fail",
|
|
236
264
|
lockUserId: addUnlockMethodData.lockUserId,
|
|
@@ -357,12 +385,7 @@ const handleAddReport = async (dps) => {
|
|
|
357
385
|
default:
|
|
358
386
|
}
|
|
359
387
|
if (eventData) {
|
|
360
|
-
|
|
361
|
-
emitter.emit(UNLOCK_METHOD_EVENT, eventData);
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
emitter.cache(UNLOCK_METHOD_EVENT, eventData);
|
|
365
|
-
}
|
|
388
|
+
emitAddUnlockMethodEvent(eventData);
|
|
366
389
|
}
|
|
367
390
|
}
|
|
368
391
|
};
|
|
@@ -372,6 +395,9 @@ const clearMonitoringAddReport = () => {
|
|
|
372
395
|
};
|
|
373
396
|
const monitoringAddReport = (option) => {
|
|
374
397
|
Object.assign(addUnlockMethodData, option);
|
|
398
|
+
clearTimeout(addUnlockMethodData.releaseEmitTimer);
|
|
399
|
+
addUnlockMethodData.canEmitEvents = false;
|
|
400
|
+
addUnlockMethodData.pendingEvents = [];
|
|
375
401
|
emitter.clearCache(UNLOCK_METHOD_EVENT);
|
|
376
402
|
emitter.off(DPCHANGE, handleAddReport);
|
|
377
403
|
emitter.on(DPCHANGE, handleAddReport);
|
|
@@ -430,6 +456,7 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
430
456
|
});
|
|
431
457
|
if (res.stage === 0) {
|
|
432
458
|
startAddReportMonitoring(res.total);
|
|
459
|
+
releaseAddUnlockMethodEventsAfterStart();
|
|
433
460
|
return { total: res.total };
|
|
434
461
|
}
|
|
435
462
|
if (res.stage === 0xfd) {
|