podasync-ws-only 2.9.0-snapshot.4 → 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.
- package/dist/node/network/webrtc.js +58 -3
- package/package.json +1 -1
- package/src/network/webrtc.js +73 -4
|
@@ -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/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;
|