podasync-ws-only 2.9.0-snapshot.3 → 2.9.0-snapshot.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.
|
@@ -100,8 +100,8 @@
|
|
|
100
100
|
// }
|
|
101
101
|
|
|
102
102
|
const reconnOnClose = {
|
|
103
|
-
value:
|
|
104
|
-
oldValue:
|
|
103
|
+
value: false,
|
|
104
|
+
oldValue: null,
|
|
105
105
|
get() {
|
|
106
106
|
return reconnOnClose.value;
|
|
107
107
|
},
|
|
@@ -194,10 +194,10 @@
|
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
196
|
socket.on('close', function (event) {
|
|
197
|
-
console.log("on.close", reconnOnClose.get(), reconnOnClose.getOld());
|
|
198
197
|
isSocketOpen = false;
|
|
199
198
|
isDeviceRegister = false;
|
|
200
199
|
oldPeerId = peerId;
|
|
200
|
+
socketState = socketStateType.CLOSED;
|
|
201
201
|
|
|
202
202
|
// socketState = socketStateType.CLOSED;
|
|
203
203
|
//
|
|
@@ -220,7 +220,6 @@
|
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
logLevel.debug && console.debug("[Async][async.js] on socket close, retryStep:", retryStep.get());
|
|
223
|
-
socketState = socketStateType.CLOSED;
|
|
224
223
|
fireEvent('stateChange', {
|
|
225
224
|
socketState: socketState,
|
|
226
225
|
timeUntilReconnect: 1000 * retryStep.get(),
|
|
@@ -780,7 +779,7 @@
|
|
|
780
779
|
|
|
781
780
|
// let tmpReconnectOnClose = reconnectOnClose;
|
|
782
781
|
// reconnectOnClose = false;
|
|
783
|
-
reconnOnClose.setOld(reconnOnClose.get());
|
|
782
|
+
if (reconnOnClose.getOld() == null) reconnOnClose.setOld(reconnOnClose.get());
|
|
784
783
|
reconnOnClose.set(false);
|
|
785
784
|
retryStep.set(0);
|
|
786
785
|
if (protocol === "websocket") socket.connect();else if (protocol == "webrtc") webRTCClass.connect();
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
config.timeoutIds.third = setTimeout(() => {
|
|
55
55
|
logLevel.debug && console.debug("[Async][Socket.js] Force closing socket.");
|
|
56
56
|
onCloseHandler(null);
|
|
57
|
-
socket.close();
|
|
57
|
+
if (socket) socket.close();
|
|
58
58
|
}, 2000);
|
|
59
59
|
}, 2000);
|
|
60
60
|
}, 8000);
|
|
@@ -77,7 +77,6 @@
|
|
|
77
77
|
},
|
|
78
78
|
connect = function () {
|
|
79
79
|
try {
|
|
80
|
-
console.log("socket.connect()");
|
|
81
80
|
if (socket && socket.readyState == 1) {
|
|
82
81
|
return;
|
|
83
82
|
}
|
|
@@ -205,7 +204,7 @@
|
|
|
205
204
|
};
|
|
206
205
|
this.close = function () {
|
|
207
206
|
logLevel.debug && console.debug("[Async][Socket.js] Closing socket by call to this.close");
|
|
208
|
-
socket.close();
|
|
207
|
+
if (socket) socket.close();
|
|
209
208
|
onCloseHandler(null);
|
|
210
209
|
socketWatchTimeout && clearTimeout(socketWatchTimeout);
|
|
211
210
|
};
|
|
@@ -239,9 +239,11 @@ let dataChannelCallbacks = {
|
|
|
239
239
|
},
|
|
240
240
|
onmessage: function (event) {
|
|
241
241
|
variables.pingController.resetPingLoop();
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
decompressResponse(event.data).then(result => {
|
|
243
|
+
var messageData = JSON.parse(result);
|
|
244
|
+
console.log("[Async][WebRTC] Receive ", result);
|
|
245
|
+
eventCallback["message"](messageData);
|
|
246
|
+
});
|
|
245
247
|
},
|
|
246
248
|
onerror: function (error) {
|
|
247
249
|
logLevel.debug && console.debug("[Async][Socket.js] dataChannel.onerror happened. EventData:", event);
|
|
@@ -425,4 +427,57 @@ let publicized = {
|
|
|
425
427
|
resetVariables();
|
|
426
428
|
}
|
|
427
429
|
};
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Decompress results
|
|
433
|
+
*/
|
|
434
|
+
function decompress(byteArray, encoding) {
|
|
435
|
+
const cs = new DecompressionStream(encoding);
|
|
436
|
+
const writer = cs.writable.getWriter();
|
|
437
|
+
writer.write(byteArray);
|
|
438
|
+
writer.close();
|
|
439
|
+
return new Response(cs.readable).arrayBuffer().then(function (arrayBuffer) {
|
|
440
|
+
return new TextDecoder().decode(arrayBuffer);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
async function decompressResponse(compressedData) {
|
|
444
|
+
return await decompress(_base64UrlToArrayBuffer(compressedData), 'gzip');
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
//utility
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Array buffer to base64Url string
|
|
451
|
+
* - arrBuff->byte[]->biStr->b64->b64u
|
|
452
|
+
* @param arrayBuffer
|
|
453
|
+
* @returns {string}
|
|
454
|
+
* @private
|
|
455
|
+
*/
|
|
456
|
+
function _arrayBufferToBase64Url(arrayBuffer) {
|
|
457
|
+
console.log('base64Url from array buffer:', arrayBuffer);
|
|
458
|
+
let base64Url = window.btoa(String.fromCodePoint(...new Uint8Array(arrayBuffer)));
|
|
459
|
+
base64Url = base64Url.replaceAll('+', '-');
|
|
460
|
+
base64Url = base64Url.replaceAll('/', '_');
|
|
461
|
+
console.log('base64Url:', base64Url);
|
|
462
|
+
return base64Url;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Base64Url string to array buffer
|
|
467
|
+
* - b64u->b64->biStr->byte[]->arrBuff
|
|
468
|
+
* @param base64Url
|
|
469
|
+
* @returns {ArrayBufferLike}
|
|
470
|
+
* @private
|
|
471
|
+
*/
|
|
472
|
+
function _base64UrlToArrayBuffer(base64) {
|
|
473
|
+
console.log('array buffer from base64Url:', base64);
|
|
474
|
+
const binaryString = window.atob(base64);
|
|
475
|
+
const length = binaryString.length;
|
|
476
|
+
const bytes = new Uint8Array(length);
|
|
477
|
+
for (let i = 0; i < length; i++) {
|
|
478
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
479
|
+
}
|
|
480
|
+
console.log('array buffer:', bytes.buffer);
|
|
481
|
+
return bytes.buffer;
|
|
482
|
+
}
|
|
428
483
|
module.exports = WebRTCClass;
|
package/package.json
CHANGED
package/src/network/async.js
CHANGED
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
// }
|
|
107
107
|
|
|
108
108
|
const reconnOnClose = {
|
|
109
|
-
value:
|
|
110
|
-
oldValue:
|
|
109
|
+
value: false,
|
|
110
|
+
oldValue: null,
|
|
111
111
|
get() {
|
|
112
112
|
return reconnOnClose.value;
|
|
113
113
|
},
|
|
@@ -213,6 +213,7 @@
|
|
|
213
213
|
isSocketOpen = false;
|
|
214
214
|
isDeviceRegister = false;
|
|
215
215
|
oldPeerId = peerId;
|
|
216
|
+
socketState = socketStateType.CLOSED;
|
|
216
217
|
|
|
217
218
|
// socketState = socketStateType.CLOSED;
|
|
218
219
|
//
|
|
@@ -239,7 +240,6 @@
|
|
|
239
240
|
|
|
240
241
|
logLevel.debug && console.debug("[Async][async.js] on socket close, retryStep:", retryStep.get());
|
|
241
242
|
|
|
242
|
-
socketState = socketStateType.CLOSED;
|
|
243
243
|
fireEvent('stateChange', {
|
|
244
244
|
socketState: socketState,
|
|
245
245
|
timeUntilReconnect: 1000 * retryStep.get(),
|
|
@@ -907,7 +907,9 @@
|
|
|
907
907
|
|
|
908
908
|
// let tmpReconnectOnClose = reconnectOnClose;
|
|
909
909
|
// reconnectOnClose = false;
|
|
910
|
-
|
|
910
|
+
if(reconnOnClose.getOld() == null)
|
|
911
|
+
reconnOnClose.setOld(reconnOnClose.get());
|
|
912
|
+
|
|
911
913
|
reconnOnClose.set(false);
|
|
912
914
|
retryStep.set(0);
|
|
913
915
|
|
package/src/network/socket.js
CHANGED
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
config.timeoutIds.third = setTimeout(()=>{
|
|
57
57
|
logLevel.debug && console.debug("[Async][Socket.js] Force closing socket.");
|
|
58
58
|
onCloseHandler(null);
|
|
59
|
-
socket
|
|
59
|
+
if(socket)
|
|
60
|
+
socket.close();
|
|
60
61
|
}, 2000);
|
|
61
62
|
}, 2000);
|
|
62
63
|
}, 8000);
|
|
@@ -224,7 +225,8 @@
|
|
|
224
225
|
|
|
225
226
|
this.close = function() {
|
|
226
227
|
logLevel.debug && console.debug("[Async][Socket.js] Closing socket by call to this.close");
|
|
227
|
-
socket
|
|
228
|
+
if(socket)
|
|
229
|
+
socket.close();
|
|
228
230
|
onCloseHandler(null);
|
|
229
231
|
socketWatchTimeout && clearTimeout(socketWatchTimeout);
|
|
230
232
|
}
|
package/src/network/webrtc.js
CHANGED
|
@@ -255,11 +255,12 @@ let dataChannelCallbacks = {
|
|
|
255
255
|
},
|
|
256
256
|
|
|
257
257
|
onmessage: function (event) {
|
|
258
|
-
|
|
259
258
|
variables.pingController.resetPingLoop();
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
259
|
+
decompressResponse(event.data).then(result => {
|
|
260
|
+
var messageData = JSON.parse(result);
|
|
261
|
+
console.log("[Async][WebRTC] Receive ", result);
|
|
262
|
+
eventCallback["message"](messageData);
|
|
263
|
+
});
|
|
263
264
|
},
|
|
264
265
|
|
|
265
266
|
onerror: function (error) {
|
|
@@ -471,4 +472,72 @@ let publicized = {
|
|
|
471
472
|
}
|
|
472
473
|
};
|
|
473
474
|
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Decompress results
|
|
478
|
+
*/
|
|
479
|
+
function decompress(byteArray, encoding) {
|
|
480
|
+
const cs = new DecompressionStream(encoding);
|
|
481
|
+
const writer = cs.writable.getWriter();
|
|
482
|
+
writer.write(byteArray);
|
|
483
|
+
writer.close();
|
|
484
|
+
return new Response(cs.readable).arrayBuffer().then(function (arrayBuffer) {
|
|
485
|
+
return new TextDecoder().decode(arrayBuffer);
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
async function decompressResponse(compressedData){
|
|
490
|
+
return await decompress(_base64UrlToArrayBuffer(compressedData), 'gzip');
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
//utility
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Array buffer to base64Url string
|
|
497
|
+
* - arrBuff->byte[]->biStr->b64->b64u
|
|
498
|
+
* @param arrayBuffer
|
|
499
|
+
* @returns {string}
|
|
500
|
+
* @private
|
|
501
|
+
*/
|
|
502
|
+
function _arrayBufferToBase64Url(arrayBuffer) {
|
|
503
|
+
console.log('base64Url from array buffer:', arrayBuffer);
|
|
504
|
+
|
|
505
|
+
let base64Url = window.btoa(String.fromCodePoint(...new Uint8Array(arrayBuffer)));
|
|
506
|
+
base64Url = base64Url.replaceAll('+', '-');
|
|
507
|
+
base64Url = base64Url.replaceAll('/', '_');
|
|
508
|
+
|
|
509
|
+
console.log('base64Url:', base64Url);
|
|
510
|
+
return base64Url;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Base64Url string to array buffer
|
|
515
|
+
* - b64u->b64->biStr->byte[]->arrBuff
|
|
516
|
+
* @param base64Url
|
|
517
|
+
* @returns {ArrayBufferLike}
|
|
518
|
+
* @private
|
|
519
|
+
*/
|
|
520
|
+
function _base64UrlToArrayBuffer(base64) {
|
|
521
|
+
console.log('array buffer from base64Url:', base64);
|
|
522
|
+
const binaryString = window.atob(base64);
|
|
523
|
+
const length = binaryString.length;
|
|
524
|
+
const bytes = new Uint8Array(length);
|
|
525
|
+
for (let i = 0; i < length; i++) {
|
|
526
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
527
|
+
}
|
|
528
|
+
console.log('array buffer:', bytes.buffer);
|
|
529
|
+
return bytes.buffer;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
474
543
|
module.exports = WebRTCClass;
|