@ray-js/lock-sdk 1.1.3-beta.5 → 1.1.3-beta.6

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.
@@ -228,7 +228,9 @@ const addUnlockMethodData = {
228
228
  canEmitEvents: true,
229
229
  pendingEvents: [],
230
230
  releaseEmitTimer: 0,
231
+ eventSessionId: 0,
231
232
  };
233
+ const ADD_UNLOCK_METHOD_EVENT_RELEASE_DELAY = 16;
232
234
  const dispatchAddUnlockMethodEvent = (eventData) => {
233
235
  if (emitter.hasListener(UNLOCK_METHOD_EVENT)) {
234
236
  emitter.emit(UNLOCK_METHOD_EVENT, eventData);
@@ -244,14 +246,22 @@ const emitAddUnlockMethodEvent = (eventData) => {
244
246
  }
245
247
  dispatchAddUnlockMethodEvent(eventData);
246
248
  };
247
- const releaseAddUnlockMethodEventsAfterStart = () => {
249
+ const releaseAddUnlockMethodEventsAfterStart = (eventSessionId) => {
248
250
  clearTimeout(addUnlockMethodData.releaseEmitTimer);
249
251
  addUnlockMethodData.releaseEmitTimer = setTimeout(() => {
250
- addUnlockMethodData.canEmitEvents = true;
251
- const pendingEvents = addUnlockMethodData.pendingEvents.splice(0);
252
- pendingEvents.forEach((eventData) => {
253
- dispatchAddUnlockMethodEvent(eventData);
254
- });
252
+ if (addUnlockMethodData.eventSessionId !== eventSessionId) {
253
+ return;
254
+ }
255
+ addUnlockMethodData.releaseEmitTimer = setTimeout(() => {
256
+ if (addUnlockMethodData.eventSessionId !== eventSessionId) {
257
+ return;
258
+ }
259
+ addUnlockMethodData.canEmitEvents = true;
260
+ const pendingEvents = addUnlockMethodData.pendingEvents.splice(0);
261
+ pendingEvents.forEach((eventData) => {
262
+ dispatchAddUnlockMethodEvent(eventData);
263
+ });
264
+ }, ADD_UNLOCK_METHOD_EVENT_RELEASE_DELAY);
255
265
  }, 0);
256
266
  };
257
267
  const handleAddTimeout = (timeout = 15000) => {
@@ -398,21 +408,24 @@ const monitoringAddReport = (option) => {
398
408
  clearTimeout(addUnlockMethodData.releaseEmitTimer);
399
409
  addUnlockMethodData.canEmitEvents = false;
400
410
  addUnlockMethodData.pendingEvents = [];
411
+ addUnlockMethodData.eventSessionId += 1;
401
412
  emitter.clearCache(UNLOCK_METHOD_EVENT);
402
413
  emitter.off(DPCHANGE, handleAddReport);
403
414
  emitter.on(DPCHANGE, handleAddReport);
404
415
  handleAddTimeout(option.timeout);
416
+ return addUnlockMethodData.eventSessionId;
405
417
  };
406
418
  export const startAddUnlockMethod = async (params) => {
407
419
  const { unlockMethodConfig, lockUserId, dpData, sn, addDpCode, addDpMap, addDpReportMap, dpId, } = await getUnlockMethodBase(params.type, params.userId);
408
420
  isCancelAddUnlockMethod = false;
409
421
  let addReportMonitoringStarted = false;
422
+ let addReportMonitoringSessionId = 0;
410
423
  const startAddReportMonitoring = (total) => {
411
424
  if (addReportMonitoringStarted) {
412
- return;
425
+ return addReportMonitoringSessionId;
413
426
  }
414
427
  addReportMonitoringStarted = true;
415
- monitoringAddReport({
428
+ addReportMonitoringSessionId = monitoringAddReport({
416
429
  timeout: params.timeout,
417
430
  unlockMethodConfig,
418
431
  total,
@@ -423,6 +436,7 @@ export const startAddUnlockMethod = async (params) => {
423
436
  userId: params.userId,
424
437
  unlockDpId: dpId,
425
438
  });
439
+ return addReportMonitoringSessionId;
426
440
  };
427
441
  const res = await publishDps({
428
442
  [addDpCode]: dpUtils.format(dpData, addDpMap),
@@ -455,8 +469,8 @@ export const startAddUnlockMethod = async (params) => {
455
469
  },
456
470
  });
457
471
  if (res.stage === 0) {
458
- startAddReportMonitoring(res.total);
459
- releaseAddUnlockMethodEventsAfterStart();
472
+ const eventSessionId = startAddReportMonitoring(res.total);
473
+ releaseAddUnlockMethodEventsAfterStart(eventSessionId);
460
474
  return { total: res.total };
461
475
  }
462
476
  if (res.stage === 0xfd) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lock-sdk",
3
- "version": "1.1.3-beta.5",
3
+ "version": "1.1.3-beta.6",
4
4
  "files": [
5
5
  "lib",
6
6
  "LICENSE.md"