podasync-ws-only 2.9.0-snapshot.21 → 2.9.0-snapshot.23

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.
@@ -112,7 +112,8 @@ function Async(params) {
112
112
  onStartWithRetryStepGreaterThanZero = params.onStartWithRetryStepGreaterThanZero,
113
113
  asyncLogCallback = typeof params.asyncLogCallback == "function" ? params.asyncLogCallback : null,
114
114
  msgLogCallback = typeof params.msgLogCallback == "function" ? params.msgLogCallback : null,
115
- onDeviceId = typeof params.onDeviceId == "function" ? params.onDeviceId : null;
115
+ onDeviceId = typeof params.onDeviceId == "function" ? params.onDeviceId : null,
116
+ isConnecting = false;
116
117
  var reconnOnClose = {
117
118
  value: false,
118
119
  oldValue: null,
@@ -160,14 +161,14 @@ function Async(params) {
160
161
  window.addEventListener('online', function () {
161
162
  asyncLogCallback && asyncLogCallback("async", "window.online", "");
162
163
  if (!isSocketOpen) {
163
- alert('window.online reconnectSocket()');
164
+ // alert('window.online reconnectSocket()');
164
165
  currentModuleInstance.reconnectSocket();
165
166
  }
166
167
  });
167
168
  window.addEventListener('offline', function () {
168
169
  asyncLogCallback && asyncLogCallback("async", "window.offline", "");
169
170
  if (isSocketOpen) {
170
- alert('window.offline, reconnectSocket()');
171
+ // alert('window.offline, reconnectSocket()');
171
172
  currentModuleInstance.reconnectSocket();
172
173
  }
173
174
  });
@@ -178,14 +179,7 @@ function Async(params) {
178
179
  serverRegister: false,
179
180
  peerId: peerId
180
181
  });
181
- switch (protocol) {
182
- case 'websocket':
183
- initSocket();
184
- break;
185
- case 'webrtc':
186
- initWebrtc();
187
- break;
188
- }
182
+ maybeReconnect();
189
183
  if (retryStep.get() < 64) {
190
184
  // retryStep += 3;
191
185
  retryStep.set(retryStep.get() + 3);
@@ -217,6 +211,7 @@ function Async(params) {
217
211
  msgLogCallback: msgLogCallback,
218
212
  asyncLogCallback: asyncLogCallback,
219
213
  onOpen: function onOpen() {
214
+ isConnecting = false;
220
215
  checkIfSocketHasOpennedTimeoutId && clearTimeout(checkIfSocketHasOpennedTimeoutId);
221
216
  socketReconnectRetryInterval && clearTimeout(socketReconnectRetryInterval);
222
217
  socketReconnectRetryInterval = null;
@@ -244,6 +239,7 @@ function Async(params) {
244
239
  isDeviceRegister = false;
245
240
  oldPeerId = peerId;
246
241
  socketState = socketStateType.CLOSED;
242
+ isConnecting = false;
247
243
 
248
244
  // socketState = socketStateType.CLOSED;
249
245
  //
@@ -281,7 +277,7 @@ function Async(params) {
281
277
  socket.destroy();
282
278
  socketReconnectRetryInterval = setTimeout(function () {
283
279
  if (isLoggedOut) return;
284
- initSocket();
280
+ maybeReconnect();
285
281
  }, 1000 * retryStep.get());
286
282
  if (retryStep.get() < 64) {
287
283
  // retryStep += 3;
@@ -335,6 +331,7 @@ function Async(params) {
335
331
  connectionOpenWaitTime: params.connectionOpenWaitTime,
336
332
  //timeout time to open
337
333
  onOpen: function onOpen(newDeviceId) {
334
+ isConnecting = false;
338
335
  checkIfSocketHasOpennedTimeoutId && clearTimeout(checkIfSocketHasOpennedTimeoutId);
339
336
  checkIfSocketHasOpennedTimeoutId = null;
340
337
  socketReconnectRetryInterval && clearTimeout(socketReconnectRetryInterval);
@@ -368,6 +365,7 @@ function Async(params) {
368
365
  isDeviceRegister = false;
369
366
  oldPeerId = peerId;
370
367
  socketState = socketStateType.CLOSED;
368
+ isConnecting = false;
371
369
  fireEvent('disconnect', event);
372
370
  if (reconnOnClose.get() || reconnOnClose.getOld()) {
373
371
  if (asyncLogging) {
@@ -395,7 +393,7 @@ function Async(params) {
395
393
  socketReconnectRetryInterval = setTimeout(function () {
396
394
  if (isLoggedOut) return;
397
395
  asyncLogCallback && asyncLogCallback("async", "closed.reconnect", "after");
398
- initWebrtc();
396
+ maybeReconnect();
399
397
  // webRTCClass.connect();
400
398
  }, 1000 * retryStep.get());
401
399
  if (retryStep.get() < 64) {
@@ -696,6 +694,19 @@ function Async(params) {
696
694
  // }
697
695
  };
698
696
 
697
+ function maybeReconnect() {
698
+ if (isConnecting) return;
699
+ isConnecting = true;
700
+ switch (protocol) {
701
+ case 'websocket':
702
+ initSocket();
703
+ break;
704
+ case 'webrtc':
705
+ initWebrtc();
706
+ break;
707
+ }
708
+ }
709
+
699
710
  /*******************************************************
700
711
  * P U B L I C M E T H O D S *
701
712
  *******************************************************/
@@ -845,6 +856,7 @@ function Async(params) {
845
856
  };
846
857
  var reconnectSocketTimeout;
847
858
  this.reconnectSocket = function () {
859
+ if (isConnecting) return;
848
860
  isSocketOpen = false;
849
861
  isDeviceRegister = false;
850
862
  oldPeerId = peerId;
@@ -874,7 +886,7 @@ function Async(params) {
874
886
  serverRegister: false,
875
887
  peerId: peerId
876
888
  });
877
- if (protocol == "websocket") initSocket();else if (protocol == "webrtc") initWebrtc();
889
+ maybeReconnect();
878
890
  if (retryStep.get() < 64) {
879
891
  // retryStep += 3;
880
892
  retryStep.set(3);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podasync-ws-only",
3
- "version": "2.9.0-snapshot.21",
3
+ "version": "2.9.0-snapshot.23",
4
4
  "description": "Fanap's POD Async service (DIRANA) - Websocket only",
5
5
  "main": "./dist/node/network/async.js",
6
6
  "scripts": {
@@ -107,7 +107,8 @@ function Async(params) {
107
107
  onStartWithRetryStepGreaterThanZero = params.onStartWithRetryStepGreaterThanZero,
108
108
  asyncLogCallback = typeof params.asyncLogCallback == "function" ? params.asyncLogCallback : null,
109
109
  msgLogCallback = typeof params.msgLogCallback == "function" ? params.msgLogCallback : null,
110
- onDeviceId = typeof params.onDeviceId == "function" ? params.onDeviceId : null;
110
+ onDeviceId = typeof params.onDeviceId == "function" ? params.onDeviceId : null,
111
+ isConnecting = false;
111
112
 
112
113
  const reconnOnClose = {
113
114
  value: false,
@@ -160,14 +161,14 @@ function Async(params) {
160
161
  window.addEventListener('online', () => {
161
162
  asyncLogCallback && asyncLogCallback("async", "window.online", "");
162
163
  if(!isSocketOpen){
163
- alert('window.online reconnectSocket()');
164
+ // alert('window.online reconnectSocket()');
164
165
  currentModuleInstance.reconnectSocket();
165
166
  }
166
167
  });
167
168
  window.addEventListener('offline', () => {
168
169
  asyncLogCallback && asyncLogCallback("async", "window.offline", "");
169
170
  if(isSocketOpen) {
170
- alert('window.offline, reconnectSocket()');
171
+ // alert('window.offline, reconnectSocket()');
171
172
  currentModuleInstance.reconnectSocket();
172
173
  }
173
174
  });
@@ -180,14 +181,7 @@ function Async(params) {
180
181
  peerId: peerId
181
182
  })
182
183
 
183
- switch (protocol) {
184
- case 'websocket':
185
- initSocket();
186
- break;
187
- case 'webrtc':
188
- initWebrtc();
189
- break;
190
- }
184
+ maybeReconnect();
191
185
 
192
186
  if (retryStep.get() < 64) {
193
187
  // retryStep += 3;
@@ -195,7 +189,6 @@ function Async(params) {
195
189
  }
196
190
  }, 1000 * retryStep.get());
197
191
  },
198
-
199
192
  asyncLogger = function (type, msg) {
200
193
  Utility.asyncLogger({
201
194
  protocol: protocol,
@@ -222,6 +215,8 @@ function Async(params) {
222
215
  msgLogCallback,
223
216
  asyncLogCallback,
224
217
  onOpen: function () {
218
+ isConnecting = false;
219
+
225
220
  checkIfSocketHasOpennedTimeoutId && clearTimeout(checkIfSocketHasOpennedTimeoutId);
226
221
  socketReconnectRetryInterval && clearTimeout(socketReconnectRetryInterval);
227
222
  socketReconnectRetryInterval = null;
@@ -252,6 +247,7 @@ function Async(params) {
252
247
  isDeviceRegister = false;
253
248
  oldPeerId = peerId;
254
249
  socketState = socketStateType.CLOSED;
250
+ isConnecting = false;
255
251
 
256
252
  // socketState = socketStateType.CLOSED;
257
253
  //
@@ -295,7 +291,7 @@ function Async(params) {
295
291
  if (isLoggedOut)
296
292
  return;
297
293
 
298
- initSocket();
294
+ maybeReconnect();
299
295
  }, 1000 * retryStep.get());
300
296
 
301
297
  if (retryStep.get() < 64) {
@@ -350,6 +346,7 @@ function Async(params) {
350
346
  asyncLogCallback,
351
347
  connectionOpenWaitTime: params.connectionOpenWaitTime, //timeout time to open
352
348
  onOpen: function (newDeviceId) {
349
+ isConnecting = false;
353
350
  checkIfSocketHasOpennedTimeoutId && clearTimeout(checkIfSocketHasOpennedTimeoutId);
354
351
  checkIfSocketHasOpennedTimeoutId = null
355
352
  socketReconnectRetryInterval && clearTimeout(socketReconnectRetryInterval);
@@ -385,6 +382,7 @@ function Async(params) {
385
382
  isDeviceRegister = false;
386
383
  oldPeerId = peerId;
387
384
  socketState = socketStateType.CLOSED;
385
+ isConnecting = false;
388
386
 
389
387
  fireEvent('disconnect', event);
390
388
 
@@ -418,7 +416,7 @@ function Async(params) {
418
416
  if (isLoggedOut)
419
417
  return;
420
418
  asyncLogCallback && asyncLogCallback("async", "closed.reconnect", "after");
421
- initWebrtc()
419
+ maybeReconnect();
422
420
  // webRTCClass.connect();
423
421
  }, 1000 * retryStep.get());
424
422
 
@@ -758,6 +756,22 @@ function Async(params) {
758
756
  // }
759
757
  };
760
758
 
759
+ function maybeReconnect() {
760
+ if(isConnecting)
761
+ return;
762
+
763
+ isConnecting = true;
764
+
765
+ switch (protocol) {
766
+ case 'websocket':
767
+ initSocket();
768
+ break;
769
+ case 'webrtc':
770
+ initWebrtc();
771
+ break;
772
+ }
773
+ }
774
+
761
775
  /*******************************************************
762
776
  * P U B L I C M E T H O D S *
763
777
  *******************************************************/
@@ -935,6 +949,9 @@ function Async(params) {
935
949
 
936
950
  let reconnectSocketTimeout;
937
951
  this.reconnectSocket = function () {
952
+ if(isConnecting)
953
+ return;
954
+
938
955
  isSocketOpen = false;
939
956
  isDeviceRegister = false;
940
957
  oldPeerId = peerId;
@@ -976,10 +993,7 @@ function Async(params) {
976
993
  peerId: peerId
977
994
  })
978
995
 
979
- if(protocol == "websocket")
980
- initSocket();
981
- else if(protocol == "webrtc")
982
- initWebrtc();
996
+ maybeReconnect();
983
997
 
984
998
  if (retryStep.get() < 64) {
985
999
  // retryStep += 3;