@xapp/chat-widget 1.40.4 → 1.41.1
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/components/FailureMessage/FailureMessage.d.ts +2 -2
- package/dist/index.css +1 -1
- package/dist/index.es.js +738 -666
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +738 -666
- package/dist/index.js.map +1 -1
- package/dist/store/ChatState.d.ts +1 -0
- package/dist/utils/__tests__/configurableMessages.test.d.ts +1 -0
- package/dist/utils/checkSessionExpiration.d.ts +1 -0
- package/dist/utils/convertToSeconds.d.ts +4 -0
- package/package.json +15 -15
package/dist/index.js
CHANGED
|
@@ -53,7 +53,7 @@ function useConnectionInfo(env) {
|
|
|
53
53
|
return useServerConfig(env, nonce);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
/******************************************************************************
|
|
57
57
|
Copyright (c) Microsoft Corporation.
|
|
58
58
|
|
|
59
59
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -3044,8 +3044,10 @@ function getConfigurableMessages() {
|
|
|
3044
3044
|
function getConfigurableMessagesConfig(messages) {
|
|
3045
3045
|
var items = messages.items;
|
|
3046
3046
|
var config = [{ retry: 0, delay: 5, text: "" }];
|
|
3047
|
-
|
|
3048
|
-
|
|
3047
|
+
if (Array.isArray(items) && items.length > 0) {
|
|
3048
|
+
for (var i = 0; i < items.length; i++) {
|
|
3049
|
+
config.push({ retry: i + 1, delay: items[i].delay, text: items[i].text });
|
|
3050
|
+
}
|
|
3049
3051
|
}
|
|
3050
3052
|
return config;
|
|
3051
3053
|
}
|
|
@@ -3516,246 +3518,203 @@ var StentorLocalChat = /** @class */ (function () {
|
|
|
3516
3518
|
return StentorLocalChat;
|
|
3517
3519
|
}());
|
|
3518
3520
|
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
var parseuri = function parseuri(str) {
|
|
3533
|
-
var src = str,
|
|
3534
|
-
b = str.indexOf('['),
|
|
3535
|
-
e = str.indexOf(']');
|
|
3521
|
+
const PACKET_TYPES = Object.create(null); // no Map = no polyfill
|
|
3522
|
+
PACKET_TYPES["open"] = "0";
|
|
3523
|
+
PACKET_TYPES["close"] = "1";
|
|
3524
|
+
PACKET_TYPES["ping"] = "2";
|
|
3525
|
+
PACKET_TYPES["pong"] = "3";
|
|
3526
|
+
PACKET_TYPES["message"] = "4";
|
|
3527
|
+
PACKET_TYPES["upgrade"] = "5";
|
|
3528
|
+
PACKET_TYPES["noop"] = "6";
|
|
3529
|
+
const PACKET_TYPES_REVERSE = Object.create(null);
|
|
3530
|
+
Object.keys(PACKET_TYPES).forEach(key => {
|
|
3531
|
+
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
|
|
3532
|
+
});
|
|
3533
|
+
const ERROR_PACKET = { type: "error", data: "parser error" };
|
|
3536
3534
|
|
|
3537
|
-
|
|
3538
|
-
|
|
3535
|
+
const withNativeBlob$1 = typeof Blob === "function" ||
|
|
3536
|
+
(typeof Blob !== "undefined" &&
|
|
3537
|
+
Object.prototype.toString.call(Blob) === "[object BlobConstructor]");
|
|
3538
|
+
const withNativeArrayBuffer$2 = typeof ArrayBuffer === "function";
|
|
3539
|
+
// ArrayBuffer.isView method is not defined in IE10
|
|
3540
|
+
const isView$1 = obj => {
|
|
3541
|
+
return typeof ArrayBuffer.isView === "function"
|
|
3542
|
+
? ArrayBuffer.isView(obj)
|
|
3543
|
+
: obj && obj.buffer instanceof ArrayBuffer;
|
|
3544
|
+
};
|
|
3545
|
+
const encodePacket = ({ type, data }, supportsBinary, callback) => {
|
|
3546
|
+
if (withNativeBlob$1 && data instanceof Blob) {
|
|
3547
|
+
if (supportsBinary) {
|
|
3548
|
+
return callback(data);
|
|
3549
|
+
}
|
|
3550
|
+
else {
|
|
3551
|
+
return encodeBlobAsBase64(data, callback);
|
|
3552
|
+
}
|
|
3539
3553
|
}
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3554
|
+
else if (withNativeArrayBuffer$2 &&
|
|
3555
|
+
(data instanceof ArrayBuffer || isView$1(data))) {
|
|
3556
|
+
if (supportsBinary) {
|
|
3557
|
+
return callback(data);
|
|
3558
|
+
}
|
|
3559
|
+
else {
|
|
3560
|
+
return encodeBlobAsBase64(new Blob([data]), callback);
|
|
3561
|
+
}
|
|
3547
3562
|
}
|
|
3563
|
+
// plain string
|
|
3564
|
+
return callback(PACKET_TYPES[type] + (data || ""));
|
|
3565
|
+
};
|
|
3566
|
+
const encodeBlobAsBase64 = (data, callback) => {
|
|
3567
|
+
const fileReader = new FileReader();
|
|
3568
|
+
fileReader.onload = function () {
|
|
3569
|
+
const content = fileReader.result.split(",")[1];
|
|
3570
|
+
callback("b" + content);
|
|
3571
|
+
};
|
|
3572
|
+
return fileReader.readAsDataURL(data);
|
|
3573
|
+
};
|
|
3548
3574
|
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3575
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
3576
|
+
// Use a lookup table to find the index.
|
|
3577
|
+
const lookup$1 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
|
|
3578
|
+
for (let i = 0; i < chars.length; i++) {
|
|
3579
|
+
lookup$1[chars.charCodeAt(i)] = i;
|
|
3580
|
+
}
|
|
3581
|
+
const decode$1 = (base64) => {
|
|
3582
|
+
let bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
|
|
3583
|
+
if (base64[base64.length - 1] === '=') {
|
|
3584
|
+
bufferLength--;
|
|
3585
|
+
if (base64[base64.length - 2] === '=') {
|
|
3586
|
+
bufferLength--;
|
|
3587
|
+
}
|
|
3554
3588
|
}
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3589
|
+
const arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
|
|
3590
|
+
for (i = 0; i < len; i += 4) {
|
|
3591
|
+
encoded1 = lookup$1[base64.charCodeAt(i)];
|
|
3592
|
+
encoded2 = lookup$1[base64.charCodeAt(i + 1)];
|
|
3593
|
+
encoded3 = lookup$1[base64.charCodeAt(i + 2)];
|
|
3594
|
+
encoded4 = lookup$1[base64.charCodeAt(i + 3)];
|
|
3595
|
+
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
|
3596
|
+
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
3597
|
+
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
|
3598
|
+
}
|
|
3599
|
+
return arraybuffer;
|
|
3560
3600
|
};
|
|
3561
3601
|
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3602
|
+
const withNativeArrayBuffer$1 = typeof ArrayBuffer === "function";
|
|
3603
|
+
const decodePacket = (encodedPacket, binaryType) => {
|
|
3604
|
+
if (typeof encodedPacket !== "string") {
|
|
3605
|
+
return {
|
|
3606
|
+
type: "message",
|
|
3607
|
+
data: mapBinary(encodedPacket, binaryType)
|
|
3608
|
+
};
|
|
3568
3609
|
}
|
|
3569
|
-
|
|
3570
|
-
|
|
3610
|
+
const type = encodedPacket.charAt(0);
|
|
3611
|
+
if (type === "b") {
|
|
3612
|
+
return {
|
|
3613
|
+
type: "message",
|
|
3614
|
+
data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
|
|
3615
|
+
};
|
|
3571
3616
|
}
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
if ($1) {
|
|
3581
|
-
data[$1] = $2;
|
|
3617
|
+
const packetType = PACKET_TYPES_REVERSE[type];
|
|
3618
|
+
if (!packetType) {
|
|
3619
|
+
return ERROR_PACKET;
|
|
3620
|
+
}
|
|
3621
|
+
return encodedPacket.length > 1
|
|
3622
|
+
? {
|
|
3623
|
+
type: PACKET_TYPES_REVERSE[type],
|
|
3624
|
+
data: encodedPacket.substring(1)
|
|
3582
3625
|
}
|
|
3626
|
+
: {
|
|
3627
|
+
type: PACKET_TYPES_REVERSE[type]
|
|
3628
|
+
};
|
|
3629
|
+
};
|
|
3630
|
+
const decodeBase64Packet = (data, binaryType) => {
|
|
3631
|
+
if (withNativeArrayBuffer$1) {
|
|
3632
|
+
const decoded = decode$1(data);
|
|
3633
|
+
return mapBinary(decoded, binaryType);
|
|
3634
|
+
}
|
|
3635
|
+
else {
|
|
3636
|
+
return { base64: true, data }; // fallback for old browsers
|
|
3637
|
+
}
|
|
3638
|
+
};
|
|
3639
|
+
const mapBinary = (data, binaryType) => {
|
|
3640
|
+
switch (binaryType) {
|
|
3641
|
+
case "blob":
|
|
3642
|
+
return data instanceof ArrayBuffer ? new Blob([data]) : data;
|
|
3643
|
+
case "arraybuffer":
|
|
3644
|
+
default:
|
|
3645
|
+
return data; // assuming the data is already an ArrayBuffer
|
|
3646
|
+
}
|
|
3647
|
+
};
|
|
3648
|
+
|
|
3649
|
+
const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
|
|
3650
|
+
const encodePayload = (packets, callback) => {
|
|
3651
|
+
// some packets may be added to the array while encoding, so the initial length must be saved
|
|
3652
|
+
const length = packets.length;
|
|
3653
|
+
const encodedPackets = new Array(length);
|
|
3654
|
+
let count = 0;
|
|
3655
|
+
packets.forEach((packet, i) => {
|
|
3656
|
+
// force base64 encoding for binary packets
|
|
3657
|
+
encodePacket(packet, false, encodedPacket => {
|
|
3658
|
+
encodedPackets[i] = encodedPacket;
|
|
3659
|
+
if (++count === length) {
|
|
3660
|
+
callback(encodedPackets.join(SEPARATOR));
|
|
3661
|
+
}
|
|
3662
|
+
});
|
|
3583
3663
|
});
|
|
3664
|
+
};
|
|
3665
|
+
const decodePayload = (encodedPayload, binaryType) => {
|
|
3666
|
+
const encodedPackets = encodedPayload.split(SEPARATOR);
|
|
3667
|
+
const packets = [];
|
|
3668
|
+
for (let i = 0; i < encodedPackets.length; i++) {
|
|
3669
|
+
const decodedPacket = decodePacket(encodedPackets[i], binaryType);
|
|
3670
|
+
packets.push(decodedPacket);
|
|
3671
|
+
if (decodedPacket.type === "error") {
|
|
3672
|
+
break;
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
return packets;
|
|
3676
|
+
};
|
|
3677
|
+
const protocol$1 = 4;
|
|
3584
3678
|
|
|
3585
|
-
|
|
3586
|
-
|
|
3679
|
+
/**
|
|
3680
|
+
* Expose `Emitter`.
|
|
3681
|
+
*/
|
|
3682
|
+
|
|
3683
|
+
var Emitter_1 = Emitter;
|
|
3587
3684
|
|
|
3588
3685
|
/**
|
|
3589
|
-
*
|
|
3686
|
+
* Initialize a new `Emitter`.
|
|
3590
3687
|
*
|
|
3591
|
-
* @
|
|
3592
|
-
* @param path - the request path of the connection
|
|
3593
|
-
* @param loc - An object meant to mimic window.location.
|
|
3594
|
-
* Defaults to window.location.
|
|
3595
|
-
* @public
|
|
3688
|
+
* @api public
|
|
3596
3689
|
*/
|
|
3597
|
-
function url(uri, path = "", loc) {
|
|
3598
|
-
let obj = uri;
|
|
3599
|
-
// default to window.location
|
|
3600
|
-
loc = loc || (typeof location !== "undefined" && location);
|
|
3601
|
-
if (null == uri)
|
|
3602
|
-
uri = loc.protocol + "//" + loc.host;
|
|
3603
|
-
// relative path support
|
|
3604
|
-
if (typeof uri === "string") {
|
|
3605
|
-
if ("/" === uri.charAt(0)) {
|
|
3606
|
-
if ("/" === uri.charAt(1)) {
|
|
3607
|
-
uri = loc.protocol + uri;
|
|
3608
|
-
}
|
|
3609
|
-
else {
|
|
3610
|
-
uri = loc.host + uri;
|
|
3611
|
-
}
|
|
3612
|
-
}
|
|
3613
|
-
if (!/^(https?|wss?):\/\//.test(uri)) {
|
|
3614
|
-
if ("undefined" !== typeof loc) {
|
|
3615
|
-
uri = loc.protocol + "//" + uri;
|
|
3616
|
-
}
|
|
3617
|
-
else {
|
|
3618
|
-
uri = "https://" + uri;
|
|
3619
|
-
}
|
|
3620
|
-
}
|
|
3621
|
-
// parse
|
|
3622
|
-
obj = parseuri(uri);
|
|
3623
|
-
}
|
|
3624
|
-
// make sure we treat `localhost:80` and `localhost` equally
|
|
3625
|
-
if (!obj.port) {
|
|
3626
|
-
if (/^(http|ws)$/.test(obj.protocol)) {
|
|
3627
|
-
obj.port = "80";
|
|
3628
|
-
}
|
|
3629
|
-
else if (/^(http|ws)s$/.test(obj.protocol)) {
|
|
3630
|
-
obj.port = "443";
|
|
3631
|
-
}
|
|
3632
|
-
}
|
|
3633
|
-
obj.path = obj.path || "/";
|
|
3634
|
-
const ipv6 = obj.host.indexOf(":") !== -1;
|
|
3635
|
-
const host = ipv6 ? "[" + obj.host + "]" : obj.host;
|
|
3636
|
-
// define unique id
|
|
3637
|
-
obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
|
|
3638
|
-
// define href
|
|
3639
|
-
obj.href =
|
|
3640
|
-
obj.protocol +
|
|
3641
|
-
"://" +
|
|
3642
|
-
host +
|
|
3643
|
-
(loc && loc.port === obj.port ? "" : ":" + obj.port);
|
|
3644
|
-
return obj;
|
|
3645
|
-
}
|
|
3646
3690
|
|
|
3647
|
-
|
|
3691
|
+
function Emitter(obj) {
|
|
3692
|
+
if (obj) return mixin(obj);
|
|
3693
|
+
}
|
|
3648
3694
|
|
|
3649
3695
|
/**
|
|
3650
|
-
*
|
|
3651
|
-
*
|
|
3652
|
-
* Logic borrowed from Modernizr:
|
|
3696
|
+
* Mixin the emitter properties.
|
|
3653
3697
|
*
|
|
3654
|
-
*
|
|
3698
|
+
* @param {Object} obj
|
|
3699
|
+
* @return {Object}
|
|
3700
|
+
* @api private
|
|
3655
3701
|
*/
|
|
3656
3702
|
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
}
|
|
3661
|
-
|
|
3662
|
-
// when trying to create
|
|
3663
|
-
hasCors.exports = false;
|
|
3703
|
+
function mixin(obj) {
|
|
3704
|
+
for (var key in Emitter.prototype) {
|
|
3705
|
+
obj[key] = Emitter.prototype[key];
|
|
3706
|
+
}
|
|
3707
|
+
return obj;
|
|
3664
3708
|
}
|
|
3665
3709
|
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
}
|
|
3675
|
-
else {
|
|
3676
|
-
return Function("return this")();
|
|
3677
|
-
}
|
|
3678
|
-
})();
|
|
3679
|
-
|
|
3680
|
-
// browser shim for xmlhttprequest module
|
|
3681
|
-
function XMLHttpRequest$1 (opts) {
|
|
3682
|
-
const xdomain = opts.xdomain;
|
|
3683
|
-
// XMLHttpRequest can be disabled on IE
|
|
3684
|
-
try {
|
|
3685
|
-
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
|
|
3686
|
-
return new XMLHttpRequest();
|
|
3687
|
-
}
|
|
3688
|
-
}
|
|
3689
|
-
catch (e) { }
|
|
3690
|
-
if (!xdomain) {
|
|
3691
|
-
try {
|
|
3692
|
-
return new globalThis$1[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
3693
|
-
}
|
|
3694
|
-
catch (e) { }
|
|
3695
|
-
}
|
|
3696
|
-
}
|
|
3697
|
-
|
|
3698
|
-
function pick(obj, ...attr) {
|
|
3699
|
-
return attr.reduce((acc, k) => {
|
|
3700
|
-
if (obj.hasOwnProperty(k)) {
|
|
3701
|
-
acc[k] = obj[k];
|
|
3702
|
-
}
|
|
3703
|
-
return acc;
|
|
3704
|
-
}, {});
|
|
3705
|
-
}
|
|
3706
|
-
// Keep a reference to the real timeout functions so they can be used when overridden
|
|
3707
|
-
const NATIVE_SET_TIMEOUT = setTimeout;
|
|
3708
|
-
const NATIVE_CLEAR_TIMEOUT = clearTimeout;
|
|
3709
|
-
function installTimerFunctions(obj, opts) {
|
|
3710
|
-
if (opts.useNativeTimers) {
|
|
3711
|
-
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThis$1);
|
|
3712
|
-
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThis$1);
|
|
3713
|
-
}
|
|
3714
|
-
else {
|
|
3715
|
-
obj.setTimeoutFn = setTimeout.bind(globalThis$1);
|
|
3716
|
-
obj.clearTimeoutFn = clearTimeout.bind(globalThis$1);
|
|
3717
|
-
}
|
|
3718
|
-
}
|
|
3719
|
-
|
|
3720
|
-
/**
|
|
3721
|
-
* Expose `Emitter`.
|
|
3722
|
-
*/
|
|
3723
|
-
|
|
3724
|
-
var Emitter_1 = Emitter;
|
|
3725
|
-
|
|
3726
|
-
/**
|
|
3727
|
-
* Initialize a new `Emitter`.
|
|
3728
|
-
*
|
|
3729
|
-
* @api public
|
|
3730
|
-
*/
|
|
3731
|
-
|
|
3732
|
-
function Emitter(obj) {
|
|
3733
|
-
if (obj) return mixin(obj);
|
|
3734
|
-
}
|
|
3735
|
-
|
|
3736
|
-
/**
|
|
3737
|
-
* Mixin the emitter properties.
|
|
3738
|
-
*
|
|
3739
|
-
* @param {Object} obj
|
|
3740
|
-
* @return {Object}
|
|
3741
|
-
* @api private
|
|
3742
|
-
*/
|
|
3743
|
-
|
|
3744
|
-
function mixin(obj) {
|
|
3745
|
-
for (var key in Emitter.prototype) {
|
|
3746
|
-
obj[key] = Emitter.prototype[key];
|
|
3747
|
-
}
|
|
3748
|
-
return obj;
|
|
3749
|
-
}
|
|
3750
|
-
|
|
3751
|
-
/**
|
|
3752
|
-
* Listen on the given `event` with `fn`.
|
|
3753
|
-
*
|
|
3754
|
-
* @param {String} event
|
|
3755
|
-
* @param {Function} fn
|
|
3756
|
-
* @return {Emitter}
|
|
3757
|
-
* @api public
|
|
3758
|
-
*/
|
|
3710
|
+
/**
|
|
3711
|
+
* Listen on the given `event` with `fn`.
|
|
3712
|
+
*
|
|
3713
|
+
* @param {String} event
|
|
3714
|
+
* @param {Function} fn
|
|
3715
|
+
* @return {Emitter}
|
|
3716
|
+
* @api public
|
|
3717
|
+
*/
|
|
3759
3718
|
|
|
3760
3719
|
Emitter.prototype.on =
|
|
3761
3720
|
Emitter.prototype.addEventListener = function(event, fn){
|
|
@@ -3893,201 +3852,78 @@ Emitter.prototype.hasListeners = function(event){
|
|
|
3893
3852
|
return !! this.listeners(event).length;
|
|
3894
3853
|
};
|
|
3895
3854
|
|
|
3896
|
-
const
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
PACKET_TYPES["ping"] = "2";
|
|
3900
|
-
PACKET_TYPES["pong"] = "3";
|
|
3901
|
-
PACKET_TYPES["message"] = "4";
|
|
3902
|
-
PACKET_TYPES["upgrade"] = "5";
|
|
3903
|
-
PACKET_TYPES["noop"] = "6";
|
|
3904
|
-
const PACKET_TYPES_REVERSE = Object.create(null);
|
|
3905
|
-
Object.keys(PACKET_TYPES).forEach(key => {
|
|
3906
|
-
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
|
|
3907
|
-
});
|
|
3908
|
-
const ERROR_PACKET = { type: "error", data: "parser error" };
|
|
3909
|
-
|
|
3910
|
-
const withNativeBlob$1 = typeof Blob === "function" ||
|
|
3911
|
-
(typeof Blob !== "undefined" &&
|
|
3912
|
-
Object.prototype.toString.call(Blob) === "[object BlobConstructor]");
|
|
3913
|
-
const withNativeArrayBuffer$2 = typeof ArrayBuffer === "function";
|
|
3914
|
-
// ArrayBuffer.isView method is not defined in IE10
|
|
3915
|
-
const isView$1 = obj => {
|
|
3916
|
-
return typeof ArrayBuffer.isView === "function"
|
|
3917
|
-
? ArrayBuffer.isView(obj)
|
|
3918
|
-
: obj && obj.buffer instanceof ArrayBuffer;
|
|
3919
|
-
};
|
|
3920
|
-
const encodePacket = ({ type, data }, supportsBinary, callback) => {
|
|
3921
|
-
if (withNativeBlob$1 && data instanceof Blob) {
|
|
3922
|
-
if (supportsBinary) {
|
|
3923
|
-
return callback(data);
|
|
3924
|
-
}
|
|
3925
|
-
else {
|
|
3926
|
-
return encodeBlobAsBase64(data, callback);
|
|
3927
|
-
}
|
|
3855
|
+
const globalThisShim = (() => {
|
|
3856
|
+
if (typeof self !== "undefined") {
|
|
3857
|
+
return self;
|
|
3928
3858
|
}
|
|
3929
|
-
else if (
|
|
3930
|
-
|
|
3931
|
-
if (supportsBinary) {
|
|
3932
|
-
return callback(data);
|
|
3933
|
-
}
|
|
3934
|
-
else {
|
|
3935
|
-
return encodeBlobAsBase64(new Blob([data]), callback);
|
|
3936
|
-
}
|
|
3859
|
+
else if (typeof window !== "undefined") {
|
|
3860
|
+
return window;
|
|
3937
3861
|
}
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
}
|
|
3941
|
-
|
|
3942
|
-
const fileReader = new FileReader();
|
|
3943
|
-
fileReader.onload = function () {
|
|
3944
|
-
const content = fileReader.result.split(",")[1];
|
|
3945
|
-
callback("b" + content);
|
|
3946
|
-
};
|
|
3947
|
-
return fileReader.readAsDataURL(data);
|
|
3948
|
-
};
|
|
3949
|
-
|
|
3950
|
-
var base64Arraybuffer_umd = {exports: {}};
|
|
3862
|
+
else {
|
|
3863
|
+
return Function("return this")();
|
|
3864
|
+
}
|
|
3865
|
+
})();
|
|
3951
3866
|
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
*/
|
|
3957
|
-
|
|
3958
|
-
(function (module, exports) {
|
|
3959
|
-
(function (global, factory) {
|
|
3960
|
-
factory(exports) ;
|
|
3961
|
-
}(commonjsGlobal, (function (exports) {
|
|
3962
|
-
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
3963
|
-
// Use a lookup table to find the index.
|
|
3964
|
-
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
|
|
3965
|
-
for (var i = 0; i < chars.length; i++) {
|
|
3966
|
-
lookup[chars.charCodeAt(i)] = i;
|
|
3967
|
-
}
|
|
3968
|
-
var encode = function (arraybuffer) {
|
|
3969
|
-
var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
|
|
3970
|
-
for (i = 0; i < len; i += 3) {
|
|
3971
|
-
base64 += chars[bytes[i] >> 2];
|
|
3972
|
-
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
|
|
3973
|
-
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
|
|
3974
|
-
base64 += chars[bytes[i + 2] & 63];
|
|
3867
|
+
function pick(obj, ...attr) {
|
|
3868
|
+
return attr.reduce((acc, k) => {
|
|
3869
|
+
if (obj.hasOwnProperty(k)) {
|
|
3870
|
+
acc[k] = obj[k];
|
|
3975
3871
|
}
|
|
3976
|
-
|
|
3977
|
-
|
|
3872
|
+
return acc;
|
|
3873
|
+
}, {});
|
|
3874
|
+
}
|
|
3875
|
+
// Keep a reference to the real timeout functions so they can be used when overridden
|
|
3876
|
+
const NATIVE_SET_TIMEOUT = setTimeout;
|
|
3877
|
+
const NATIVE_CLEAR_TIMEOUT = clearTimeout;
|
|
3878
|
+
function installTimerFunctions(obj, opts) {
|
|
3879
|
+
if (opts.useNativeTimers) {
|
|
3880
|
+
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThisShim);
|
|
3881
|
+
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThisShim);
|
|
3882
|
+
}
|
|
3883
|
+
else {
|
|
3884
|
+
obj.setTimeoutFn = setTimeout.bind(globalThisShim);
|
|
3885
|
+
obj.clearTimeoutFn = clearTimeout.bind(globalThisShim);
|
|
3886
|
+
}
|
|
3887
|
+
}
|
|
3888
|
+
// base64 encoded buffers are about 33% bigger (https://en.wikipedia.org/wiki/Base64)
|
|
3889
|
+
const BASE64_OVERHEAD = 1.33;
|
|
3890
|
+
// we could also have used `new Blob([obj]).size`, but it isn't supported in IE9
|
|
3891
|
+
function byteLength(obj) {
|
|
3892
|
+
if (typeof obj === "string") {
|
|
3893
|
+
return utf8Length(obj);
|
|
3894
|
+
}
|
|
3895
|
+
// arraybuffer or blob
|
|
3896
|
+
return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
|
|
3897
|
+
}
|
|
3898
|
+
function utf8Length(str) {
|
|
3899
|
+
let c = 0, length = 0;
|
|
3900
|
+
for (let i = 0, l = str.length; i < l; i++) {
|
|
3901
|
+
c = str.charCodeAt(i);
|
|
3902
|
+
if (c < 0x80) {
|
|
3903
|
+
length += 1;
|
|
3978
3904
|
}
|
|
3979
|
-
else if (
|
|
3980
|
-
|
|
3905
|
+
else if (c < 0x800) {
|
|
3906
|
+
length += 2;
|
|
3981
3907
|
}
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
var decode = function (base64) {
|
|
3985
|
-
var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
|
|
3986
|
-
if (base64[base64.length - 1] === '=') {
|
|
3987
|
-
bufferLength--;
|
|
3988
|
-
if (base64[base64.length - 2] === '=') {
|
|
3989
|
-
bufferLength--;
|
|
3990
|
-
}
|
|
3908
|
+
else if (c < 0xd800 || c >= 0xe000) {
|
|
3909
|
+
length += 3;
|
|
3991
3910
|
}
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
encoded2 = lookup[base64.charCodeAt(i + 1)];
|
|
3996
|
-
encoded3 = lookup[base64.charCodeAt(i + 2)];
|
|
3997
|
-
encoded4 = lookup[base64.charCodeAt(i + 3)];
|
|
3998
|
-
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
|
3999
|
-
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
4000
|
-
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
|
3911
|
+
else {
|
|
3912
|
+
i++;
|
|
3913
|
+
length += 4;
|
|
4001
3914
|
}
|
|
4002
|
-
return arraybuffer;
|
|
4003
|
-
};
|
|
4004
|
-
|
|
4005
|
-
exports.decode = decode;
|
|
4006
|
-
exports.encode = encode;
|
|
4007
|
-
|
|
4008
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4009
|
-
|
|
4010
|
-
})));
|
|
4011
|
-
|
|
4012
|
-
}(base64Arraybuffer_umd, base64Arraybuffer_umd.exports));
|
|
4013
|
-
|
|
4014
|
-
const withNativeArrayBuffer$1 = typeof ArrayBuffer === "function";
|
|
4015
|
-
const decodePacket = (encodedPacket, binaryType) => {
|
|
4016
|
-
if (typeof encodedPacket !== "string") {
|
|
4017
|
-
return {
|
|
4018
|
-
type: "message",
|
|
4019
|
-
data: mapBinary(encodedPacket, binaryType)
|
|
4020
|
-
};
|
|
4021
|
-
}
|
|
4022
|
-
const type = encodedPacket.charAt(0);
|
|
4023
|
-
if (type === "b") {
|
|
4024
|
-
return {
|
|
4025
|
-
type: "message",
|
|
4026
|
-
data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
|
|
4027
|
-
};
|
|
4028
3915
|
}
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
return ERROR_PACKET;
|
|
4032
|
-
}
|
|
4033
|
-
return encodedPacket.length > 1
|
|
4034
|
-
? {
|
|
4035
|
-
type: PACKET_TYPES_REVERSE[type],
|
|
4036
|
-
data: encodedPacket.substring(1)
|
|
4037
|
-
}
|
|
4038
|
-
: {
|
|
4039
|
-
type: PACKET_TYPES_REVERSE[type]
|
|
4040
|
-
};
|
|
4041
|
-
};
|
|
4042
|
-
const decodeBase64Packet = (data, binaryType) => {
|
|
4043
|
-
if (withNativeArrayBuffer$1) {
|
|
4044
|
-
const decoded = base64Arraybuffer_umd.exports.decode(data);
|
|
4045
|
-
return mapBinary(decoded, binaryType);
|
|
4046
|
-
}
|
|
4047
|
-
else {
|
|
4048
|
-
return { base64: true, data }; // fallback for old browsers
|
|
4049
|
-
}
|
|
4050
|
-
};
|
|
4051
|
-
const mapBinary = (data, binaryType) => {
|
|
4052
|
-
switch (binaryType) {
|
|
4053
|
-
case "blob":
|
|
4054
|
-
return data instanceof ArrayBuffer ? new Blob([data]) : data;
|
|
4055
|
-
case "arraybuffer":
|
|
4056
|
-
default:
|
|
4057
|
-
return data; // assuming the data is already an ArrayBuffer
|
|
4058
|
-
}
|
|
4059
|
-
};
|
|
3916
|
+
return length;
|
|
3917
|
+
}
|
|
4060
3918
|
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
packets.forEach((packet, i) => {
|
|
4068
|
-
// force base64 encoding for binary packets
|
|
4069
|
-
encodePacket(packet, false, encodedPacket => {
|
|
4070
|
-
encodedPackets[i] = encodedPacket;
|
|
4071
|
-
if (++count === length) {
|
|
4072
|
-
callback(encodedPackets.join(SEPARATOR));
|
|
4073
|
-
}
|
|
4074
|
-
});
|
|
4075
|
-
});
|
|
4076
|
-
};
|
|
4077
|
-
const decodePayload = (encodedPayload, binaryType) => {
|
|
4078
|
-
const encodedPackets = encodedPayload.split(SEPARATOR);
|
|
4079
|
-
const packets = [];
|
|
4080
|
-
for (let i = 0; i < encodedPackets.length; i++) {
|
|
4081
|
-
const decodedPacket = decodePacket(encodedPackets[i], binaryType);
|
|
4082
|
-
packets.push(decodedPacket);
|
|
4083
|
-
if (decodedPacket.type === "error") {
|
|
4084
|
-
break;
|
|
4085
|
-
}
|
|
3919
|
+
class TransportError extends Error {
|
|
3920
|
+
constructor(reason, description, context) {
|
|
3921
|
+
super(reason);
|
|
3922
|
+
this.description = description;
|
|
3923
|
+
this.context = context;
|
|
3924
|
+
this.type = "TransportError";
|
|
4086
3925
|
}
|
|
4087
|
-
|
|
4088
|
-
};
|
|
4089
|
-
const protocol$1 = 4;
|
|
4090
|
-
|
|
3926
|
+
}
|
|
4091
3927
|
class Transport extends Emitter_1 {
|
|
4092
3928
|
/**
|
|
4093
3929
|
* Transport abstract constructor.
|
|
@@ -4107,17 +3943,14 @@ class Transport extends Emitter_1 {
|
|
|
4107
3943
|
/**
|
|
4108
3944
|
* Emits an error.
|
|
4109
3945
|
*
|
|
4110
|
-
* @param {String}
|
|
3946
|
+
* @param {String} reason
|
|
3947
|
+
* @param description
|
|
3948
|
+
* @param context - the error context
|
|
4111
3949
|
* @return {Transport} for chaining
|
|
4112
3950
|
* @api protected
|
|
4113
3951
|
*/
|
|
4114
|
-
onError(
|
|
4115
|
-
|
|
4116
|
-
// @ts-ignore
|
|
4117
|
-
err.type = "TransportError";
|
|
4118
|
-
// @ts-ignore
|
|
4119
|
-
err.description = desc;
|
|
4120
|
-
super.emit("error", err);
|
|
3952
|
+
onError(reason, description, context) {
|
|
3953
|
+
super.emitReserved("error", new TransportError(reason, description, context));
|
|
4121
3954
|
return this;
|
|
4122
3955
|
}
|
|
4123
3956
|
/**
|
|
@@ -4163,7 +3996,7 @@ class Transport extends Emitter_1 {
|
|
|
4163
3996
|
onOpen() {
|
|
4164
3997
|
this.readyState = "open";
|
|
4165
3998
|
this.writable = true;
|
|
4166
|
-
super.
|
|
3999
|
+
super.emitReserved("open");
|
|
4167
4000
|
}
|
|
4168
4001
|
/**
|
|
4169
4002
|
* Called with data.
|
|
@@ -4181,26 +4014,22 @@ class Transport extends Emitter_1 {
|
|
|
4181
4014
|
* @api protected
|
|
4182
4015
|
*/
|
|
4183
4016
|
onPacket(packet) {
|
|
4184
|
-
super.
|
|
4017
|
+
super.emitReserved("packet", packet);
|
|
4185
4018
|
}
|
|
4186
4019
|
/**
|
|
4187
4020
|
* Called upon close.
|
|
4188
4021
|
*
|
|
4189
4022
|
* @api protected
|
|
4190
4023
|
*/
|
|
4191
|
-
onClose() {
|
|
4024
|
+
onClose(details) {
|
|
4192
4025
|
this.readyState = "closed";
|
|
4193
|
-
super.
|
|
4026
|
+
super.emitReserved("close", details);
|
|
4194
4027
|
}
|
|
4195
4028
|
}
|
|
4196
4029
|
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
, seed = 0
|
|
4201
|
-
, i = 0
|
|
4202
|
-
, prev;
|
|
4203
|
-
|
|
4030
|
+
// imported from https://github.com/unshiftio/yeast
|
|
4031
|
+
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split(''), length = 64, map = {};
|
|
4032
|
+
let seed = 0, i = 0, prev;
|
|
4204
4033
|
/**
|
|
4205
4034
|
* Return a string representing the specified number.
|
|
4206
4035
|
*
|
|
@@ -4208,34 +4037,14 @@ var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_
|
|
|
4208
4037
|
* @returns {String} The string representation of the number.
|
|
4209
4038
|
* @api public
|
|
4210
4039
|
*/
|
|
4211
|
-
function encode(num) {
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
return encoded;
|
|
4220
|
-
}
|
|
4221
|
-
|
|
4222
|
-
/**
|
|
4223
|
-
* Return the integer value specified by the given string.
|
|
4224
|
-
*
|
|
4225
|
-
* @param {String} str The string to convert.
|
|
4226
|
-
* @returns {Number} The integer value represented by the string.
|
|
4227
|
-
* @api public
|
|
4228
|
-
*/
|
|
4229
|
-
function decode(str) {
|
|
4230
|
-
var decoded = 0;
|
|
4231
|
-
|
|
4232
|
-
for (i = 0; i < str.length; i++) {
|
|
4233
|
-
decoded = decoded * length + map[str.charAt(i)];
|
|
4234
|
-
}
|
|
4235
|
-
|
|
4236
|
-
return decoded;
|
|
4040
|
+
function encode$1(num) {
|
|
4041
|
+
let encoded = '';
|
|
4042
|
+
do {
|
|
4043
|
+
encoded = alphabet[num % length] + encoded;
|
|
4044
|
+
num = Math.floor(num / length);
|
|
4045
|
+
} while (num > 0);
|
|
4046
|
+
return encoded;
|
|
4237
4047
|
}
|
|
4238
|
-
|
|
4239
4048
|
/**
|
|
4240
4049
|
* Yeast: A tiny growing id generator.
|
|
4241
4050
|
*
|
|
@@ -4243,26 +4052,18 @@ function decode(str) {
|
|
|
4243
4052
|
* @api public
|
|
4244
4053
|
*/
|
|
4245
4054
|
function yeast() {
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4055
|
+
const now = encode$1(+new Date());
|
|
4056
|
+
if (now !== prev)
|
|
4057
|
+
return seed = 0, prev = now;
|
|
4058
|
+
return now + '.' + encode$1(seed++);
|
|
4250
4059
|
}
|
|
4251
|
-
|
|
4252
4060
|
//
|
|
4253
4061
|
// Map each character to its index.
|
|
4254
4062
|
//
|
|
4255
|
-
for (; i < length; i++)
|
|
4256
|
-
|
|
4257
|
-
//
|
|
4258
|
-
// Expose the `yeast`, `encode` and `decode` functions.
|
|
4259
|
-
//
|
|
4260
|
-
yeast.encode = encode;
|
|
4261
|
-
yeast.decode = decode;
|
|
4262
|
-
var yeast_1 = yeast;
|
|
4263
|
-
|
|
4264
|
-
var parseqs = {};
|
|
4063
|
+
for (; i < length; i++)
|
|
4064
|
+
map[alphabet[i]] = i;
|
|
4265
4065
|
|
|
4066
|
+
// imported from https://github.com/galkn/querystring
|
|
4266
4067
|
/**
|
|
4267
4068
|
* Compiles a querystring
|
|
4268
4069
|
* Returns string representation of the object
|
|
@@ -4270,41 +4071,98 @@ var parseqs = {};
|
|
|
4270
4071
|
* @param {Object}
|
|
4271
4072
|
* @api private
|
|
4272
4073
|
*/
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4074
|
+
function encode(obj) {
|
|
4075
|
+
let str = '';
|
|
4076
|
+
for (let i in obj) {
|
|
4077
|
+
if (obj.hasOwnProperty(i)) {
|
|
4078
|
+
if (str.length)
|
|
4079
|
+
str += '&';
|
|
4080
|
+
str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
|
|
4081
|
+
}
|
|
4281
4082
|
}
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
return str;
|
|
4285
|
-
};
|
|
4286
|
-
|
|
4083
|
+
return str;
|
|
4084
|
+
}
|
|
4287
4085
|
/**
|
|
4288
4086
|
* Parses a simple querystring into an object
|
|
4289
4087
|
*
|
|
4290
4088
|
* @param {String} qs
|
|
4291
4089
|
* @api private
|
|
4292
4090
|
*/
|
|
4091
|
+
function decode(qs) {
|
|
4092
|
+
let qry = {};
|
|
4093
|
+
let pairs = qs.split('&');
|
|
4094
|
+
for (let i = 0, l = pairs.length; i < l; i++) {
|
|
4095
|
+
let pair = pairs[i].split('=');
|
|
4096
|
+
qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
|
|
4097
|
+
}
|
|
4098
|
+
return qry;
|
|
4099
|
+
}
|
|
4293
4100
|
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4101
|
+
// imported from https://github.com/component/has-cors
|
|
4102
|
+
let value = false;
|
|
4103
|
+
try {
|
|
4104
|
+
value = typeof XMLHttpRequest !== 'undefined' &&
|
|
4105
|
+
'withCredentials' in new XMLHttpRequest();
|
|
4106
|
+
}
|
|
4107
|
+
catch (err) {
|
|
4108
|
+
// if XMLHttp support is disabled in IE then it will throw
|
|
4109
|
+
// when trying to create
|
|
4110
|
+
}
|
|
4111
|
+
const hasCORS = value;
|
|
4303
4112
|
|
|
4113
|
+
// browser shim for xmlhttprequest module
|
|
4114
|
+
function XHR(opts) {
|
|
4115
|
+
const xdomain = opts.xdomain;
|
|
4116
|
+
// XMLHttpRequest can be disabled on IE
|
|
4117
|
+
try {
|
|
4118
|
+
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
|
|
4119
|
+
return new XMLHttpRequest();
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
catch (e) { }
|
|
4123
|
+
if (!xdomain) {
|
|
4124
|
+
try {
|
|
4125
|
+
return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
4126
|
+
}
|
|
4127
|
+
catch (e) { }
|
|
4128
|
+
}
|
|
4129
|
+
}
|
|
4130
|
+
|
|
4131
|
+
function empty$2() { }
|
|
4132
|
+
const hasXHR2 = (function () {
|
|
4133
|
+
const xhr = new XHR({
|
|
4134
|
+
xdomain: false
|
|
4135
|
+
});
|
|
4136
|
+
return null != xhr.responseType;
|
|
4137
|
+
})();
|
|
4304
4138
|
class Polling extends Transport {
|
|
4305
|
-
|
|
4306
|
-
|
|
4139
|
+
/**
|
|
4140
|
+
* XHR Polling constructor.
|
|
4141
|
+
*
|
|
4142
|
+
* @param {Object} opts
|
|
4143
|
+
* @api public
|
|
4144
|
+
*/
|
|
4145
|
+
constructor(opts) {
|
|
4146
|
+
super(opts);
|
|
4307
4147
|
this.polling = false;
|
|
4148
|
+
if (typeof location !== "undefined") {
|
|
4149
|
+
const isSSL = "https:" === location.protocol;
|
|
4150
|
+
let port = location.port;
|
|
4151
|
+
// some user agents have empty `location.port`
|
|
4152
|
+
if (!port) {
|
|
4153
|
+
port = isSSL ? "443" : "80";
|
|
4154
|
+
}
|
|
4155
|
+
this.xd =
|
|
4156
|
+
(typeof location !== "undefined" &&
|
|
4157
|
+
opts.hostname !== location.hostname) ||
|
|
4158
|
+
port !== opts.port;
|
|
4159
|
+
this.xs = opts.secure !== isSSL;
|
|
4160
|
+
}
|
|
4161
|
+
/**
|
|
4162
|
+
* XHR supports binary
|
|
4163
|
+
*/
|
|
4164
|
+
const forceBase64 = opts && opts.forceBase64;
|
|
4165
|
+
this.supportsBinary = hasXHR2 && !forceBase64;
|
|
4308
4166
|
}
|
|
4309
4167
|
/**
|
|
4310
4168
|
* Transport name.
|
|
@@ -4360,7 +4218,7 @@ class Polling extends Transport {
|
|
|
4360
4218
|
poll() {
|
|
4361
4219
|
this.polling = true;
|
|
4362
4220
|
this.doPoll();
|
|
4363
|
-
this.
|
|
4221
|
+
this.emitReserved("poll");
|
|
4364
4222
|
}
|
|
4365
4223
|
/**
|
|
4366
4224
|
* Overloads onData to detect payloads.
|
|
@@ -4375,7 +4233,7 @@ class Polling extends Transport {
|
|
|
4375
4233
|
}
|
|
4376
4234
|
// if its a close packet, we close the ongoing requests
|
|
4377
4235
|
if ("close" === packet.type) {
|
|
4378
|
-
this.onClose();
|
|
4236
|
+
this.onClose({ description: "transport closed by the server" });
|
|
4379
4237
|
return false;
|
|
4380
4238
|
}
|
|
4381
4239
|
// otherwise bypass onData and handle the message
|
|
@@ -4387,7 +4245,7 @@ class Polling extends Transport {
|
|
|
4387
4245
|
if ("closed" !== this.readyState) {
|
|
4388
4246
|
// if we got data we're not polling
|
|
4389
4247
|
this.polling = false;
|
|
4390
|
-
this.
|
|
4248
|
+
this.emitReserved("pollComplete");
|
|
4391
4249
|
if ("open" === this.readyState) {
|
|
4392
4250
|
this.poll();
|
|
4393
4251
|
}
|
|
@@ -4423,7 +4281,7 @@ class Polling extends Transport {
|
|
|
4423
4281
|
encodePayload(packets, data => {
|
|
4424
4282
|
this.doWrite(data, () => {
|
|
4425
4283
|
this.writable = true;
|
|
4426
|
-
this.
|
|
4284
|
+
this.emitReserved("drain");
|
|
4427
4285
|
});
|
|
4428
4286
|
});
|
|
4429
4287
|
}
|
|
@@ -4438,7 +4296,7 @@ class Polling extends Transport {
|
|
|
4438
4296
|
let port = "";
|
|
4439
4297
|
// cache busting is forced
|
|
4440
4298
|
if (false !== this.opts.timestampRequests) {
|
|
4441
|
-
query[this.opts.timestampParam] =
|
|
4299
|
+
query[this.opts.timestampParam] = yeast();
|
|
4442
4300
|
}
|
|
4443
4301
|
if (!this.supportsBinary && !query.sid) {
|
|
4444
4302
|
query.b64 = 1;
|
|
@@ -4449,7 +4307,7 @@ class Polling extends Transport {
|
|
|
4449
4307
|
("http" === schema && Number(this.opts.port) !== 80))) {
|
|
4450
4308
|
port = ":" + this.opts.port;
|
|
4451
4309
|
}
|
|
4452
|
-
const encodedQuery =
|
|
4310
|
+
const encodedQuery = encode(query);
|
|
4453
4311
|
const ipv6 = this.opts.hostname.indexOf(":") !== -1;
|
|
4454
4312
|
return (schema +
|
|
4455
4313
|
"://" +
|
|
@@ -4458,47 +4316,6 @@ class Polling extends Transport {
|
|
|
4458
4316
|
this.opts.path +
|
|
4459
4317
|
(encodedQuery.length ? "?" + encodedQuery : ""));
|
|
4460
4318
|
}
|
|
4461
|
-
}
|
|
4462
|
-
|
|
4463
|
-
/* global attachEvent */
|
|
4464
|
-
/**
|
|
4465
|
-
* Empty function
|
|
4466
|
-
*/
|
|
4467
|
-
function empty$2() { }
|
|
4468
|
-
const hasXHR2 = (function () {
|
|
4469
|
-
const xhr = new XMLHttpRequest$1({
|
|
4470
|
-
xdomain: false
|
|
4471
|
-
});
|
|
4472
|
-
return null != xhr.responseType;
|
|
4473
|
-
})();
|
|
4474
|
-
class XHR extends Polling {
|
|
4475
|
-
/**
|
|
4476
|
-
* XHR Polling constructor.
|
|
4477
|
-
*
|
|
4478
|
-
* @param {Object} opts
|
|
4479
|
-
* @api public
|
|
4480
|
-
*/
|
|
4481
|
-
constructor(opts) {
|
|
4482
|
-
super(opts);
|
|
4483
|
-
if (typeof location !== "undefined") {
|
|
4484
|
-
const isSSL = "https:" === location.protocol;
|
|
4485
|
-
let port = location.port;
|
|
4486
|
-
// some user agents have empty `location.port`
|
|
4487
|
-
if (!port) {
|
|
4488
|
-
port = isSSL ? "443" : "80";
|
|
4489
|
-
}
|
|
4490
|
-
this.xd =
|
|
4491
|
-
(typeof location !== "undefined" &&
|
|
4492
|
-
opts.hostname !== location.hostname) ||
|
|
4493
|
-
port !== opts.port;
|
|
4494
|
-
this.xs = opts.secure !== isSSL;
|
|
4495
|
-
}
|
|
4496
|
-
/**
|
|
4497
|
-
* XHR supports binary
|
|
4498
|
-
*/
|
|
4499
|
-
const forceBase64 = opts && opts.forceBase64;
|
|
4500
|
-
this.supportsBinary = hasXHR2 && !forceBase64;
|
|
4501
|
-
}
|
|
4502
4319
|
/**
|
|
4503
4320
|
* Creates a request.
|
|
4504
4321
|
*
|
|
@@ -4522,8 +4339,8 @@ class XHR extends Polling {
|
|
|
4522
4339
|
data: data
|
|
4523
4340
|
});
|
|
4524
4341
|
req.on("success", fn);
|
|
4525
|
-
req.on("error",
|
|
4526
|
-
this.onError("xhr post error",
|
|
4342
|
+
req.on("error", (xhrStatus, context) => {
|
|
4343
|
+
this.onError("xhr post error", xhrStatus, context);
|
|
4527
4344
|
});
|
|
4528
4345
|
}
|
|
4529
4346
|
/**
|
|
@@ -4534,8 +4351,8 @@ class XHR extends Polling {
|
|
|
4534
4351
|
doPoll() {
|
|
4535
4352
|
const req = this.request();
|
|
4536
4353
|
req.on("data", this.onData.bind(this));
|
|
4537
|
-
req.on("error",
|
|
4538
|
-
this.onError("xhr poll error",
|
|
4354
|
+
req.on("error", (xhrStatus, context) => {
|
|
4355
|
+
this.onError("xhr poll error", xhrStatus, context);
|
|
4539
4356
|
});
|
|
4540
4357
|
this.pollXhr = req;
|
|
4541
4358
|
}
|
|
@@ -4566,7 +4383,7 @@ class Request extends Emitter_1 {
|
|
|
4566
4383
|
const opts = pick(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
4567
4384
|
opts.xdomain = !!this.opts.xd;
|
|
4568
4385
|
opts.xscheme = !!this.opts.xs;
|
|
4569
|
-
const xhr = (this.xhr = new
|
|
4386
|
+
const xhr = (this.xhr = new XHR(opts));
|
|
4570
4387
|
try {
|
|
4571
4388
|
xhr.open(this.method, this.uri, this.async);
|
|
4572
4389
|
try {
|
|
@@ -4620,30 +4437,12 @@ class Request extends Emitter_1 {
|
|
|
4620
4437
|
this.setTimeoutFn(() => {
|
|
4621
4438
|
this.onError(e);
|
|
4622
4439
|
}, 0);
|
|
4623
|
-
return;
|
|
4624
|
-
}
|
|
4625
|
-
if (typeof document !== "undefined") {
|
|
4626
|
-
this.index = Request.requestsCount++;
|
|
4627
|
-
Request.requests[this.index] = this;
|
|
4628
|
-
}
|
|
4629
|
-
}
|
|
4630
|
-
/**
|
|
4631
|
-
* Called upon successful response.
|
|
4632
|
-
*
|
|
4633
|
-
* @api private
|
|
4634
|
-
*/
|
|
4635
|
-
onSuccess() {
|
|
4636
|
-
this.emit("success");
|
|
4637
|
-
this.cleanup();
|
|
4638
|
-
}
|
|
4639
|
-
/**
|
|
4640
|
-
* Called if we have data.
|
|
4641
|
-
*
|
|
4642
|
-
* @api private
|
|
4643
|
-
*/
|
|
4644
|
-
onData(data) {
|
|
4645
|
-
this.emit("data", data);
|
|
4646
|
-
this.onSuccess();
|
|
4440
|
+
return;
|
|
4441
|
+
}
|
|
4442
|
+
if (typeof document !== "undefined") {
|
|
4443
|
+
this.index = Request.requestsCount++;
|
|
4444
|
+
Request.requests[this.index] = this;
|
|
4445
|
+
}
|
|
4647
4446
|
}
|
|
4648
4447
|
/**
|
|
4649
4448
|
* Called upon error.
|
|
@@ -4651,7 +4450,7 @@ class Request extends Emitter_1 {
|
|
|
4651
4450
|
* @api private
|
|
4652
4451
|
*/
|
|
4653
4452
|
onError(err) {
|
|
4654
|
-
this.
|
|
4453
|
+
this.emitReserved("error", err, this.xhr);
|
|
4655
4454
|
this.cleanup(true);
|
|
4656
4455
|
}
|
|
4657
4456
|
/**
|
|
@@ -4683,7 +4482,9 @@ class Request extends Emitter_1 {
|
|
|
4683
4482
|
onLoad() {
|
|
4684
4483
|
const data = this.xhr.responseText;
|
|
4685
4484
|
if (data !== null) {
|
|
4686
|
-
this.
|
|
4485
|
+
this.emitReserved("data", data);
|
|
4486
|
+
this.emitReserved("success");
|
|
4487
|
+
this.cleanup();
|
|
4687
4488
|
}
|
|
4688
4489
|
}
|
|
4689
4490
|
/**
|
|
@@ -4709,7 +4510,7 @@ if (typeof document !== "undefined") {
|
|
|
4709
4510
|
attachEvent("onunload", unloadHandler);
|
|
4710
4511
|
}
|
|
4711
4512
|
else if (typeof addEventListener === "function") {
|
|
4712
|
-
const terminationEvent = "onpagehide" in
|
|
4513
|
+
const terminationEvent = "onpagehide" in globalThisShim ? "pagehide" : "unload";
|
|
4713
4514
|
addEventListener(terminationEvent, unloadHandler, false);
|
|
4714
4515
|
}
|
|
4715
4516
|
}
|
|
@@ -4730,7 +4531,7 @@ const nextTick = (() => {
|
|
|
4730
4531
|
return (cb, setTimeoutFn) => setTimeoutFn(cb, 0);
|
|
4731
4532
|
}
|
|
4732
4533
|
})();
|
|
4733
|
-
const WebSocket =
|
|
4534
|
+
const WebSocket = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
|
|
4734
4535
|
const usingBrowserWebSocket = true;
|
|
4735
4536
|
const defaultBinaryType = "arraybuffer";
|
|
4736
4537
|
|
|
@@ -4785,7 +4586,7 @@ class WS extends Transport {
|
|
|
4785
4586
|
: new WebSocket(uri, protocols, opts);
|
|
4786
4587
|
}
|
|
4787
4588
|
catch (err) {
|
|
4788
|
-
return this.
|
|
4589
|
+
return this.emitReserved("error", err);
|
|
4789
4590
|
}
|
|
4790
4591
|
this.ws.binaryType = this.socket.binaryType || defaultBinaryType;
|
|
4791
4592
|
this.addEventListeners();
|
|
@@ -4802,7 +4603,10 @@ class WS extends Transport {
|
|
|
4802
4603
|
}
|
|
4803
4604
|
this.onOpen();
|
|
4804
4605
|
};
|
|
4805
|
-
this.ws.onclose = this.onClose
|
|
4606
|
+
this.ws.onclose = closeEvent => this.onClose({
|
|
4607
|
+
description: "websocket connection closed",
|
|
4608
|
+
context: closeEvent
|
|
4609
|
+
});
|
|
4806
4610
|
this.ws.onmessage = ev => this.onData(ev.data);
|
|
4807
4611
|
this.ws.onerror = e => this.onError("websocket error", e);
|
|
4808
4612
|
}
|
|
@@ -4838,7 +4642,7 @@ class WS extends Transport {
|
|
|
4838
4642
|
// defer to next tick to allow Socket to clear writeBuffer
|
|
4839
4643
|
nextTick(() => {
|
|
4840
4644
|
this.writable = true;
|
|
4841
|
-
this.
|
|
4645
|
+
this.emitReserved("drain");
|
|
4842
4646
|
}, this.setTimeoutFn);
|
|
4843
4647
|
}
|
|
4844
4648
|
});
|
|
@@ -4872,13 +4676,13 @@ class WS extends Transport {
|
|
|
4872
4676
|
}
|
|
4873
4677
|
// append timestamp to URI
|
|
4874
4678
|
if (this.opts.timestampRequests) {
|
|
4875
|
-
query[this.opts.timestampParam] =
|
|
4679
|
+
query[this.opts.timestampParam] = yeast();
|
|
4876
4680
|
}
|
|
4877
4681
|
// communicate binary support capabilities
|
|
4878
4682
|
if (!this.supportsBinary) {
|
|
4879
4683
|
query.b64 = 1;
|
|
4880
4684
|
}
|
|
4881
|
-
const encodedQuery =
|
|
4685
|
+
const encodedQuery = encode(query);
|
|
4882
4686
|
const ipv6 = this.opts.hostname.indexOf(":") !== -1;
|
|
4883
4687
|
return (schema +
|
|
4884
4688
|
"://" +
|
|
@@ -4894,16 +4698,65 @@ class WS extends Transport {
|
|
|
4894
4698
|
* @api public
|
|
4895
4699
|
*/
|
|
4896
4700
|
check() {
|
|
4897
|
-
return
|
|
4898
|
-
!("__initialize" in WebSocket && this.name === WS.prototype.name));
|
|
4701
|
+
return !!WebSocket;
|
|
4899
4702
|
}
|
|
4900
4703
|
}
|
|
4901
4704
|
|
|
4902
4705
|
const transports = {
|
|
4903
4706
|
websocket: WS,
|
|
4904
|
-
polling:
|
|
4707
|
+
polling: Polling
|
|
4905
4708
|
};
|
|
4906
4709
|
|
|
4710
|
+
// imported from https://github.com/galkn/parseuri
|
|
4711
|
+
/**
|
|
4712
|
+
* Parses an URI
|
|
4713
|
+
*
|
|
4714
|
+
* @author Steven Levithan <stevenlevithan.com> (MIT license)
|
|
4715
|
+
* @api private
|
|
4716
|
+
*/
|
|
4717
|
+
const re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
|
4718
|
+
const parts = [
|
|
4719
|
+
'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
|
|
4720
|
+
];
|
|
4721
|
+
function parse$2(str) {
|
|
4722
|
+
const src = str, b = str.indexOf('['), e = str.indexOf(']');
|
|
4723
|
+
if (b != -1 && e != -1) {
|
|
4724
|
+
str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
|
|
4725
|
+
}
|
|
4726
|
+
let m = re.exec(str || ''), uri = {}, i = 14;
|
|
4727
|
+
while (i--) {
|
|
4728
|
+
uri[parts[i]] = m[i] || '';
|
|
4729
|
+
}
|
|
4730
|
+
if (b != -1 && e != -1) {
|
|
4731
|
+
uri.source = src;
|
|
4732
|
+
uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
|
|
4733
|
+
uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
|
|
4734
|
+
uri.ipv6uri = true;
|
|
4735
|
+
}
|
|
4736
|
+
uri.pathNames = pathNames(uri, uri['path']);
|
|
4737
|
+
uri.queryKey = queryKey(uri, uri['query']);
|
|
4738
|
+
return uri;
|
|
4739
|
+
}
|
|
4740
|
+
function pathNames(obj, path) {
|
|
4741
|
+
const regx = /\/{2,9}/g, names = path.replace(regx, "/").split("/");
|
|
4742
|
+
if (path.substr(0, 1) == '/' || path.length === 0) {
|
|
4743
|
+
names.splice(0, 1);
|
|
4744
|
+
}
|
|
4745
|
+
if (path.substr(path.length - 1, 1) == '/') {
|
|
4746
|
+
names.splice(names.length - 1, 1);
|
|
4747
|
+
}
|
|
4748
|
+
return names;
|
|
4749
|
+
}
|
|
4750
|
+
function queryKey(uri, query) {
|
|
4751
|
+
const data = {};
|
|
4752
|
+
query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
|
|
4753
|
+
if ($1) {
|
|
4754
|
+
data[$1] = $2;
|
|
4755
|
+
}
|
|
4756
|
+
});
|
|
4757
|
+
return data;
|
|
4758
|
+
}
|
|
4759
|
+
|
|
4907
4760
|
class Socket$1 extends Emitter_1 {
|
|
4908
4761
|
/**
|
|
4909
4762
|
* Socket constructor.
|
|
@@ -4919,7 +4772,7 @@ class Socket$1 extends Emitter_1 {
|
|
|
4919
4772
|
uri = null;
|
|
4920
4773
|
}
|
|
4921
4774
|
if (uri) {
|
|
4922
|
-
uri =
|
|
4775
|
+
uri = parse$2(uri);
|
|
4923
4776
|
opts.hostname = uri.host;
|
|
4924
4777
|
opts.secure = uri.protocol === "https" || uri.protocol === "wss";
|
|
4925
4778
|
opts.port = uri.port;
|
|
@@ -4927,7 +4780,7 @@ class Socket$1 extends Emitter_1 {
|
|
|
4927
4780
|
opts.query = uri.query;
|
|
4928
4781
|
}
|
|
4929
4782
|
else if (opts.host) {
|
|
4930
|
-
opts.hostname =
|
|
4783
|
+
opts.hostname = parse$2(opts.host).host;
|
|
4931
4784
|
}
|
|
4932
4785
|
installTimerFunctions(this, opts);
|
|
4933
4786
|
this.secure =
|
|
@@ -4968,7 +4821,7 @@ class Socket$1 extends Emitter_1 {
|
|
|
4968
4821
|
}, opts);
|
|
4969
4822
|
this.opts.path = this.opts.path.replace(/\/$/, "") + "/";
|
|
4970
4823
|
if (typeof this.opts.query === "string") {
|
|
4971
|
-
this.opts.query =
|
|
4824
|
+
this.opts.query = decode(this.opts.query);
|
|
4972
4825
|
}
|
|
4973
4826
|
// set on handshake
|
|
4974
4827
|
this.id = null;
|
|
@@ -4992,7 +4845,9 @@ class Socket$1 extends Emitter_1 {
|
|
|
4992
4845
|
}
|
|
4993
4846
|
if (this.hostname !== "localhost") {
|
|
4994
4847
|
this.offlineEventListener = () => {
|
|
4995
|
-
this.onClose("transport close"
|
|
4848
|
+
this.onClose("transport close", {
|
|
4849
|
+
description: "network connection lost"
|
|
4850
|
+
});
|
|
4996
4851
|
};
|
|
4997
4852
|
addEventListener("offline", this.offlineEventListener, false);
|
|
4998
4853
|
}
|
|
@@ -5007,7 +4862,7 @@ class Socket$1 extends Emitter_1 {
|
|
|
5007
4862
|
* @api private
|
|
5008
4863
|
*/
|
|
5009
4864
|
createTransport(name) {
|
|
5010
|
-
const query =
|
|
4865
|
+
const query = Object.assign({}, this.opts.query);
|
|
5011
4866
|
// append engine.io protocol identifier
|
|
5012
4867
|
query.EIO = protocol$1;
|
|
5013
4868
|
// transport name
|
|
@@ -5075,9 +4930,7 @@ class Socket$1 extends Emitter_1 {
|
|
|
5075
4930
|
.on("drain", this.onDrain.bind(this))
|
|
5076
4931
|
.on("packet", this.onPacket.bind(this))
|
|
5077
4932
|
.on("error", this.onError.bind(this))
|
|
5078
|
-
.on("close",
|
|
5079
|
-
this.onClose("transport close");
|
|
5080
|
-
});
|
|
4933
|
+
.on("close", reason => this.onClose("transport close", reason));
|
|
5081
4934
|
}
|
|
5082
4935
|
/**
|
|
5083
4936
|
* Probes a transport.
|
|
@@ -5239,6 +5092,7 @@ class Socket$1 extends Emitter_1 {
|
|
|
5239
5092
|
this.upgrades = this.filterUpgrades(data.upgrades);
|
|
5240
5093
|
this.pingInterval = data.pingInterval;
|
|
5241
5094
|
this.pingTimeout = data.pingTimeout;
|
|
5095
|
+
this.maxPayload = data.maxPayload;
|
|
5242
5096
|
this.onOpen();
|
|
5243
5097
|
// In case open handler closes socket
|
|
5244
5098
|
if ("closed" === this.readyState)
|
|
@@ -5287,13 +5141,40 @@ class Socket$1 extends Emitter_1 {
|
|
|
5287
5141
|
this.transport.writable &&
|
|
5288
5142
|
!this.upgrading &&
|
|
5289
5143
|
this.writeBuffer.length) {
|
|
5290
|
-
this.
|
|
5144
|
+
const packets = this.getWritablePackets();
|
|
5145
|
+
this.transport.send(packets);
|
|
5291
5146
|
// keep track of current length of writeBuffer
|
|
5292
5147
|
// splice writeBuffer and callbackBuffer on `drain`
|
|
5293
|
-
this.prevBufferLen =
|
|
5148
|
+
this.prevBufferLen = packets.length;
|
|
5294
5149
|
this.emitReserved("flush");
|
|
5295
5150
|
}
|
|
5296
5151
|
}
|
|
5152
|
+
/**
|
|
5153
|
+
* Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
|
|
5154
|
+
* long-polling)
|
|
5155
|
+
*
|
|
5156
|
+
* @private
|
|
5157
|
+
*/
|
|
5158
|
+
getWritablePackets() {
|
|
5159
|
+
const shouldCheckPayloadSize = this.maxPayload &&
|
|
5160
|
+
this.transport.name === "polling" &&
|
|
5161
|
+
this.writeBuffer.length > 1;
|
|
5162
|
+
if (!shouldCheckPayloadSize) {
|
|
5163
|
+
return this.writeBuffer;
|
|
5164
|
+
}
|
|
5165
|
+
let payloadSize = 1; // first packet type
|
|
5166
|
+
for (let i = 0; i < this.writeBuffer.length; i++) {
|
|
5167
|
+
const data = this.writeBuffer[i].data;
|
|
5168
|
+
if (data) {
|
|
5169
|
+
payloadSize += byteLength(data);
|
|
5170
|
+
}
|
|
5171
|
+
if (i > 0 && payloadSize > this.maxPayload) {
|
|
5172
|
+
return this.writeBuffer.slice(0, i);
|
|
5173
|
+
}
|
|
5174
|
+
payloadSize += 2; // separator + packet type
|
|
5175
|
+
}
|
|
5176
|
+
return this.writeBuffer;
|
|
5177
|
+
}
|
|
5297
5178
|
/**
|
|
5298
5179
|
* Sends a message.
|
|
5299
5180
|
*
|
|
@@ -5401,7 +5282,7 @@ class Socket$1 extends Emitter_1 {
|
|
|
5401
5282
|
*
|
|
5402
5283
|
* @api private
|
|
5403
5284
|
*/
|
|
5404
|
-
onClose(reason,
|
|
5285
|
+
onClose(reason, description) {
|
|
5405
5286
|
if ("opening" === this.readyState ||
|
|
5406
5287
|
"open" === this.readyState ||
|
|
5407
5288
|
"closing" === this.readyState) {
|
|
@@ -5421,7 +5302,7 @@ class Socket$1 extends Emitter_1 {
|
|
|
5421
5302
|
// clear session id
|
|
5422
5303
|
this.id = null;
|
|
5423
5304
|
// emit close event
|
|
5424
|
-
this.emitReserved("close", reason,
|
|
5305
|
+
this.emitReserved("close", reason, description);
|
|
5425
5306
|
// clean buffers after, so users can still
|
|
5426
5307
|
// grab the buffers on `close` event
|
|
5427
5308
|
this.writeBuffer = [];
|
|
@@ -5447,18 +5328,68 @@ class Socket$1 extends Emitter_1 {
|
|
|
5447
5328
|
}
|
|
5448
5329
|
}
|
|
5449
5330
|
Socket$1.protocol = protocol$1;
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5331
|
+
|
|
5332
|
+
Socket$1.protocol;
|
|
5333
|
+
|
|
5334
|
+
/**
|
|
5335
|
+
* URL parser.
|
|
5336
|
+
*
|
|
5337
|
+
* @param uri - url
|
|
5338
|
+
* @param path - the request path of the connection
|
|
5339
|
+
* @param loc - An object meant to mimic window.location.
|
|
5340
|
+
* Defaults to window.location.
|
|
5341
|
+
* @public
|
|
5342
|
+
*/
|
|
5343
|
+
function url(uri, path = "", loc) {
|
|
5344
|
+
let obj = uri;
|
|
5345
|
+
// default to window.location
|
|
5346
|
+
loc = loc || (typeof location !== "undefined" && location);
|
|
5347
|
+
if (null == uri)
|
|
5348
|
+
uri = loc.protocol + "//" + loc.host;
|
|
5349
|
+
// relative path support
|
|
5350
|
+
if (typeof uri === "string") {
|
|
5351
|
+
if ("/" === uri.charAt(0)) {
|
|
5352
|
+
if ("/" === uri.charAt(1)) {
|
|
5353
|
+
uri = loc.protocol + uri;
|
|
5354
|
+
}
|
|
5355
|
+
else {
|
|
5356
|
+
uri = loc.host + uri;
|
|
5357
|
+
}
|
|
5358
|
+
}
|
|
5359
|
+
if (!/^(https?|wss?):\/\//.test(uri)) {
|
|
5360
|
+
if ("undefined" !== typeof loc) {
|
|
5361
|
+
uri = loc.protocol + "//" + uri;
|
|
5362
|
+
}
|
|
5363
|
+
else {
|
|
5364
|
+
uri = "https://" + uri;
|
|
5365
|
+
}
|
|
5366
|
+
}
|
|
5367
|
+
// parse
|
|
5368
|
+
obj = parse$2(uri);
|
|
5369
|
+
}
|
|
5370
|
+
// make sure we treat `localhost:80` and `localhost` equally
|
|
5371
|
+
if (!obj.port) {
|
|
5372
|
+
if (/^(http|ws)$/.test(obj.protocol)) {
|
|
5373
|
+
obj.port = "80";
|
|
5374
|
+
}
|
|
5375
|
+
else if (/^(http|ws)s$/.test(obj.protocol)) {
|
|
5376
|
+
obj.port = "443";
|
|
5455
5377
|
}
|
|
5456
5378
|
}
|
|
5457
|
-
|
|
5379
|
+
obj.path = obj.path || "/";
|
|
5380
|
+
const ipv6 = obj.host.indexOf(":") !== -1;
|
|
5381
|
+
const host = ipv6 ? "[" + obj.host + "]" : obj.host;
|
|
5382
|
+
// define unique id
|
|
5383
|
+
obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
|
|
5384
|
+
// define href
|
|
5385
|
+
obj.href =
|
|
5386
|
+
obj.protocol +
|
|
5387
|
+
"://" +
|
|
5388
|
+
host +
|
|
5389
|
+
(loc && loc.port === obj.port ? "" : ":" + obj.port);
|
|
5390
|
+
return obj;
|
|
5458
5391
|
}
|
|
5459
5392
|
|
|
5460
|
-
Socket$1.protocol;
|
|
5461
|
-
|
|
5462
5393
|
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
|
|
5463
5394
|
const isView = (obj) => {
|
|
5464
5395
|
return typeof ArrayBuffer.isView === "function"
|
|
@@ -5605,6 +5536,14 @@ var PacketType;
|
|
|
5605
5536
|
* A socket.io Encoder instance
|
|
5606
5537
|
*/
|
|
5607
5538
|
class Encoder {
|
|
5539
|
+
/**
|
|
5540
|
+
* Encoder constructor
|
|
5541
|
+
*
|
|
5542
|
+
* @param {function} replacer - custom replacer to pass down to JSON.parse
|
|
5543
|
+
*/
|
|
5544
|
+
constructor(replacer) {
|
|
5545
|
+
this.replacer = replacer;
|
|
5546
|
+
}
|
|
5608
5547
|
/**
|
|
5609
5548
|
* Encode a packet as a single string if non-binary, or as a
|
|
5610
5549
|
* buffer sequence, depending on packet type.
|
|
@@ -5645,7 +5584,7 @@ class Encoder {
|
|
|
5645
5584
|
}
|
|
5646
5585
|
// json data
|
|
5647
5586
|
if (null != obj.data) {
|
|
5648
|
-
str += JSON.stringify(obj.data);
|
|
5587
|
+
str += JSON.stringify(obj.data, this.replacer);
|
|
5649
5588
|
}
|
|
5650
5589
|
return str;
|
|
5651
5590
|
}
|
|
@@ -5668,8 +5607,14 @@ class Encoder {
|
|
|
5668
5607
|
* @return {Object} decoder
|
|
5669
5608
|
*/
|
|
5670
5609
|
class Decoder extends Emitter_1 {
|
|
5671
|
-
|
|
5610
|
+
/**
|
|
5611
|
+
* Decoder constructor
|
|
5612
|
+
*
|
|
5613
|
+
* @param {function} reviver - custom reviver to pass down to JSON.stringify
|
|
5614
|
+
*/
|
|
5615
|
+
constructor(reviver) {
|
|
5672
5616
|
super();
|
|
5617
|
+
this.reviver = reviver;
|
|
5673
5618
|
}
|
|
5674
5619
|
/**
|
|
5675
5620
|
* Decodes an encoded packet string into packet JSON.
|
|
@@ -5770,7 +5715,7 @@ class Decoder extends Emitter_1 {
|
|
|
5770
5715
|
}
|
|
5771
5716
|
// look up json data
|
|
5772
5717
|
if (str.charAt(++i)) {
|
|
5773
|
-
const payload = tryParse(str.substr(i));
|
|
5718
|
+
const payload = this.tryParse(str.substr(i));
|
|
5774
5719
|
if (Decoder.isPayloadValid(p.type, payload)) {
|
|
5775
5720
|
p.data = payload;
|
|
5776
5721
|
}
|
|
@@ -5780,6 +5725,14 @@ class Decoder extends Emitter_1 {
|
|
|
5780
5725
|
}
|
|
5781
5726
|
return p;
|
|
5782
5727
|
}
|
|
5728
|
+
tryParse(str) {
|
|
5729
|
+
try {
|
|
5730
|
+
return JSON.parse(str, this.reviver);
|
|
5731
|
+
}
|
|
5732
|
+
catch (e) {
|
|
5733
|
+
return false;
|
|
5734
|
+
}
|
|
5735
|
+
}
|
|
5783
5736
|
static isPayloadValid(type, payload) {
|
|
5784
5737
|
switch (type) {
|
|
5785
5738
|
case PacketType.CONNECT:
|
|
@@ -5805,14 +5758,6 @@ class Decoder extends Emitter_1 {
|
|
|
5805
5758
|
}
|
|
5806
5759
|
}
|
|
5807
5760
|
}
|
|
5808
|
-
function tryParse(str) {
|
|
5809
|
-
try {
|
|
5810
|
-
return JSON.parse(str);
|
|
5811
|
-
}
|
|
5812
|
-
catch (e) {
|
|
5813
|
-
return false;
|
|
5814
|
-
}
|
|
5815
|
-
}
|
|
5816
5761
|
/**
|
|
5817
5762
|
* A manager of a binary event's 'buffer sequence'. Should
|
|
5818
5763
|
* be constructed whenever a packet of type BINARY_EVENT is
|
|
@@ -5891,7 +5836,6 @@ class Socket extends Emitter_1 {
|
|
|
5891
5836
|
constructor(io, nsp, opts) {
|
|
5892
5837
|
super();
|
|
5893
5838
|
this.connected = false;
|
|
5894
|
-
this.disconnected = true;
|
|
5895
5839
|
this.receiveBuffer = [];
|
|
5896
5840
|
this.sendBuffer = [];
|
|
5897
5841
|
this.ids = 0;
|
|
@@ -5905,6 +5849,12 @@ class Socket extends Emitter_1 {
|
|
|
5905
5849
|
if (this.io._autoConnect)
|
|
5906
5850
|
this.open();
|
|
5907
5851
|
}
|
|
5852
|
+
/**
|
|
5853
|
+
* Whether the socket is currently disconnected
|
|
5854
|
+
*/
|
|
5855
|
+
get disconnected() {
|
|
5856
|
+
return !this.connected;
|
|
5857
|
+
}
|
|
5908
5858
|
/**
|
|
5909
5859
|
* Subscribe to open, close and packet events
|
|
5910
5860
|
*
|
|
@@ -5990,6 +5940,7 @@ class Socket extends Emitter_1 {
|
|
|
5990
5940
|
const discardPacket = this.flags.volatile && (!isTransportWritable || !this.connected);
|
|
5991
5941
|
if (discardPacket) ;
|
|
5992
5942
|
else if (this.connected) {
|
|
5943
|
+
this.notifyOutgoingListeners(packet);
|
|
5993
5944
|
this.packet(packet);
|
|
5994
5945
|
}
|
|
5995
5946
|
else {
|
|
@@ -6063,13 +6014,13 @@ class Socket extends Emitter_1 {
|
|
|
6063
6014
|
* Called upon engine `close`.
|
|
6064
6015
|
*
|
|
6065
6016
|
* @param reason
|
|
6017
|
+
* @param description
|
|
6066
6018
|
* @private
|
|
6067
6019
|
*/
|
|
6068
|
-
onclose(reason) {
|
|
6020
|
+
onclose(reason, description) {
|
|
6069
6021
|
this.connected = false;
|
|
6070
|
-
this.disconnected = true;
|
|
6071
6022
|
delete this.id;
|
|
6072
|
-
this.emitReserved("disconnect", reason);
|
|
6023
|
+
this.emitReserved("disconnect", reason, description);
|
|
6073
6024
|
}
|
|
6074
6025
|
/**
|
|
6075
6026
|
* Called with socket packet.
|
|
@@ -6092,14 +6043,10 @@ class Socket extends Emitter_1 {
|
|
|
6092
6043
|
}
|
|
6093
6044
|
break;
|
|
6094
6045
|
case PacketType.EVENT:
|
|
6095
|
-
this.onevent(packet);
|
|
6096
|
-
break;
|
|
6097
6046
|
case PacketType.BINARY_EVENT:
|
|
6098
6047
|
this.onevent(packet);
|
|
6099
6048
|
break;
|
|
6100
6049
|
case PacketType.ACK:
|
|
6101
|
-
this.onack(packet);
|
|
6102
|
-
break;
|
|
6103
6050
|
case PacketType.BINARY_ACK:
|
|
6104
6051
|
this.onack(packet);
|
|
6105
6052
|
break;
|
|
@@ -6183,7 +6130,6 @@ class Socket extends Emitter_1 {
|
|
|
6183
6130
|
onconnect(id) {
|
|
6184
6131
|
this.id = id;
|
|
6185
6132
|
this.connected = true;
|
|
6186
|
-
this.disconnected = false;
|
|
6187
6133
|
this.emitBuffered();
|
|
6188
6134
|
this.emitReserved("connect");
|
|
6189
6135
|
}
|
|
@@ -6195,7 +6141,10 @@ class Socket extends Emitter_1 {
|
|
|
6195
6141
|
emitBuffered() {
|
|
6196
6142
|
this.receiveBuffer.forEach((args) => this.emitEvent(args));
|
|
6197
6143
|
this.receiveBuffer = [];
|
|
6198
|
-
this.sendBuffer.forEach((packet) =>
|
|
6144
|
+
this.sendBuffer.forEach((packet) => {
|
|
6145
|
+
this.notifyOutgoingListeners(packet);
|
|
6146
|
+
this.packet(packet);
|
|
6147
|
+
});
|
|
6199
6148
|
this.sendBuffer = [];
|
|
6200
6149
|
}
|
|
6201
6150
|
/**
|
|
@@ -6347,14 +6296,112 @@ class Socket extends Emitter_1 {
|
|
|
6347
6296
|
listenersAny() {
|
|
6348
6297
|
return this._anyListeners || [];
|
|
6349
6298
|
}
|
|
6299
|
+
/**
|
|
6300
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
6301
|
+
* callback.
|
|
6302
|
+
*
|
|
6303
|
+
* @param listener
|
|
6304
|
+
*
|
|
6305
|
+
* <pre><code>
|
|
6306
|
+
*
|
|
6307
|
+
* socket.onAnyOutgoing((event, ...args) => {
|
|
6308
|
+
* console.log(event);
|
|
6309
|
+
* });
|
|
6310
|
+
*
|
|
6311
|
+
* </pre></code>
|
|
6312
|
+
*
|
|
6313
|
+
* @public
|
|
6314
|
+
*/
|
|
6315
|
+
onAnyOutgoing(listener) {
|
|
6316
|
+
this._anyOutgoingListeners = this._anyOutgoingListeners || [];
|
|
6317
|
+
this._anyOutgoingListeners.push(listener);
|
|
6318
|
+
return this;
|
|
6319
|
+
}
|
|
6320
|
+
/**
|
|
6321
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
6322
|
+
* callback. The listener is added to the beginning of the listeners array.
|
|
6323
|
+
*
|
|
6324
|
+
* @param listener
|
|
6325
|
+
*
|
|
6326
|
+
* <pre><code>
|
|
6327
|
+
*
|
|
6328
|
+
* socket.prependAnyOutgoing((event, ...args) => {
|
|
6329
|
+
* console.log(event);
|
|
6330
|
+
* });
|
|
6331
|
+
*
|
|
6332
|
+
* </pre></code>
|
|
6333
|
+
*
|
|
6334
|
+
* @public
|
|
6335
|
+
*/
|
|
6336
|
+
prependAnyOutgoing(listener) {
|
|
6337
|
+
this._anyOutgoingListeners = this._anyOutgoingListeners || [];
|
|
6338
|
+
this._anyOutgoingListeners.unshift(listener);
|
|
6339
|
+
return this;
|
|
6340
|
+
}
|
|
6341
|
+
/**
|
|
6342
|
+
* Removes the listener that will be fired when any event is emitted.
|
|
6343
|
+
*
|
|
6344
|
+
* @param listener
|
|
6345
|
+
*
|
|
6346
|
+
* <pre><code>
|
|
6347
|
+
*
|
|
6348
|
+
* const handler = (event, ...args) => {
|
|
6349
|
+
* console.log(event);
|
|
6350
|
+
* }
|
|
6351
|
+
*
|
|
6352
|
+
* socket.onAnyOutgoing(handler);
|
|
6353
|
+
*
|
|
6354
|
+
* // then later
|
|
6355
|
+
* socket.offAnyOutgoing(handler);
|
|
6356
|
+
*
|
|
6357
|
+
* </pre></code>
|
|
6358
|
+
*
|
|
6359
|
+
* @public
|
|
6360
|
+
*/
|
|
6361
|
+
offAnyOutgoing(listener) {
|
|
6362
|
+
if (!this._anyOutgoingListeners) {
|
|
6363
|
+
return this;
|
|
6364
|
+
}
|
|
6365
|
+
if (listener) {
|
|
6366
|
+
const listeners = this._anyOutgoingListeners;
|
|
6367
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
6368
|
+
if (listener === listeners[i]) {
|
|
6369
|
+
listeners.splice(i, 1);
|
|
6370
|
+
return this;
|
|
6371
|
+
}
|
|
6372
|
+
}
|
|
6373
|
+
}
|
|
6374
|
+
else {
|
|
6375
|
+
this._anyOutgoingListeners = [];
|
|
6376
|
+
}
|
|
6377
|
+
return this;
|
|
6378
|
+
}
|
|
6379
|
+
/**
|
|
6380
|
+
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
6381
|
+
* e.g. to remove listeners.
|
|
6382
|
+
*
|
|
6383
|
+
* @public
|
|
6384
|
+
*/
|
|
6385
|
+
listenersAnyOutgoing() {
|
|
6386
|
+
return this._anyOutgoingListeners || [];
|
|
6387
|
+
}
|
|
6388
|
+
/**
|
|
6389
|
+
* Notify the listeners for each packet sent
|
|
6390
|
+
*
|
|
6391
|
+
* @param packet
|
|
6392
|
+
*
|
|
6393
|
+
* @private
|
|
6394
|
+
*/
|
|
6395
|
+
notifyOutgoingListeners(packet) {
|
|
6396
|
+
if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
|
|
6397
|
+
const listeners = this._anyOutgoingListeners.slice();
|
|
6398
|
+
for (const listener of listeners) {
|
|
6399
|
+
listener.apply(this, packet.data);
|
|
6400
|
+
}
|
|
6401
|
+
}
|
|
6402
|
+
}
|
|
6350
6403
|
}
|
|
6351
6404
|
|
|
6352
|
-
/**
|
|
6353
|
-
* Expose `Backoff`.
|
|
6354
|
-
*/
|
|
6355
|
-
|
|
6356
|
-
var backo2 = Backoff;
|
|
6357
|
-
|
|
6358
6405
|
/**
|
|
6359
6406
|
* Initialize backoff timer with `opts`.
|
|
6360
6407
|
*
|
|
@@ -6366,71 +6413,60 @@ var backo2 = Backoff;
|
|
|
6366
6413
|
* @param {Object} opts
|
|
6367
6414
|
* @api public
|
|
6368
6415
|
*/
|
|
6369
|
-
|
|
6370
6416
|
function Backoff(opts) {
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6417
|
+
opts = opts || {};
|
|
6418
|
+
this.ms = opts.min || 100;
|
|
6419
|
+
this.max = opts.max || 10000;
|
|
6420
|
+
this.factor = opts.factor || 2;
|
|
6421
|
+
this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
|
|
6422
|
+
this.attempts = 0;
|
|
6377
6423
|
}
|
|
6378
|
-
|
|
6379
6424
|
/**
|
|
6380
6425
|
* Return the backoff duration.
|
|
6381
6426
|
*
|
|
6382
6427
|
* @return {Number}
|
|
6383
6428
|
* @api public
|
|
6384
6429
|
*/
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
return Math.min(ms, this.max) | 0;
|
|
6430
|
+
Backoff.prototype.duration = function () {
|
|
6431
|
+
var ms = this.ms * Math.pow(this.factor, this.attempts++);
|
|
6432
|
+
if (this.jitter) {
|
|
6433
|
+
var rand = Math.random();
|
|
6434
|
+
var deviation = Math.floor(rand * this.jitter * ms);
|
|
6435
|
+
ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
|
|
6436
|
+
}
|
|
6437
|
+
return Math.min(ms, this.max) | 0;
|
|
6394
6438
|
};
|
|
6395
|
-
|
|
6396
6439
|
/**
|
|
6397
6440
|
* Reset the number of attempts.
|
|
6398
6441
|
*
|
|
6399
6442
|
* @api public
|
|
6400
6443
|
*/
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
this.attempts = 0;
|
|
6444
|
+
Backoff.prototype.reset = function () {
|
|
6445
|
+
this.attempts = 0;
|
|
6404
6446
|
};
|
|
6405
|
-
|
|
6406
6447
|
/**
|
|
6407
6448
|
* Set the minimum duration
|
|
6408
6449
|
*
|
|
6409
6450
|
* @api public
|
|
6410
6451
|
*/
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
this.ms = min;
|
|
6452
|
+
Backoff.prototype.setMin = function (min) {
|
|
6453
|
+
this.ms = min;
|
|
6414
6454
|
};
|
|
6415
|
-
|
|
6416
6455
|
/**
|
|
6417
6456
|
* Set the maximum duration
|
|
6418
6457
|
*
|
|
6419
6458
|
* @api public
|
|
6420
6459
|
*/
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
this.max = max;
|
|
6460
|
+
Backoff.prototype.setMax = function (max) {
|
|
6461
|
+
this.max = max;
|
|
6424
6462
|
};
|
|
6425
|
-
|
|
6426
6463
|
/**
|
|
6427
6464
|
* Set the jitter
|
|
6428
6465
|
*
|
|
6429
6466
|
* @api public
|
|
6430
6467
|
*/
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
this.jitter = jitter;
|
|
6468
|
+
Backoff.prototype.setJitter = function (jitter) {
|
|
6469
|
+
this.jitter = jitter;
|
|
6434
6470
|
};
|
|
6435
6471
|
|
|
6436
6472
|
class Manager extends Emitter_1 {
|
|
@@ -6452,7 +6488,7 @@ class Manager extends Emitter_1 {
|
|
|
6452
6488
|
this.reconnectionDelay(opts.reconnectionDelay || 1000);
|
|
6453
6489
|
this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
|
|
6454
6490
|
this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : 0.5);
|
|
6455
|
-
this.backoff = new
|
|
6491
|
+
this.backoff = new Backoff({
|
|
6456
6492
|
min: this.reconnectionDelay(),
|
|
6457
6493
|
max: this.reconnectionDelayMax(),
|
|
6458
6494
|
jitter: this.randomizationFactor(),
|
|
@@ -6713,11 +6749,11 @@ class Manager extends Emitter_1 {
|
|
|
6713
6749
|
*
|
|
6714
6750
|
* @private
|
|
6715
6751
|
*/
|
|
6716
|
-
onclose(reason) {
|
|
6752
|
+
onclose(reason, description) {
|
|
6717
6753
|
this.cleanup();
|
|
6718
6754
|
this.backoff.reset();
|
|
6719
6755
|
this._readyState = "closed";
|
|
6720
|
-
this.emitReserved("close", reason);
|
|
6756
|
+
this.emitReserved("close", reason, description);
|
|
6721
6757
|
if (this._reconnection && !this.skipReconnect) {
|
|
6722
6758
|
this.reconnect();
|
|
6723
6759
|
}
|
|
@@ -7645,6 +7681,35 @@ var ChatMessage = function (props) {
|
|
|
7645
7681
|
React__default$1["default"].createElement("div", { className: "chat-msg-container ".concat(getClassName(props.message)) }, renderByType())));
|
|
7646
7682
|
};
|
|
7647
7683
|
|
|
7684
|
+
/**
|
|
7685
|
+
* value must be like "60m", "2h" etc.
|
|
7686
|
+
*/
|
|
7687
|
+
function convertToSeconds(value) {
|
|
7688
|
+
var unit = value === null || value === void 0 ? void 0 : value.slice(-1);
|
|
7689
|
+
var number = parseFloat(value === null || value === void 0 ? void 0 : value.slice(0, -1));
|
|
7690
|
+
switch (unit) {
|
|
7691
|
+
case "d": {
|
|
7692
|
+
return number * 24 * 60 * 60;
|
|
7693
|
+
}
|
|
7694
|
+
case "h": {
|
|
7695
|
+
return number * 60 * 60;
|
|
7696
|
+
}
|
|
7697
|
+
case "m": {
|
|
7698
|
+
return number * 60;
|
|
7699
|
+
}
|
|
7700
|
+
case "s": {
|
|
7701
|
+
return number;
|
|
7702
|
+
}
|
|
7703
|
+
default: {
|
|
7704
|
+
return number;
|
|
7705
|
+
}
|
|
7706
|
+
}
|
|
7707
|
+
}
|
|
7708
|
+
|
|
7709
|
+
function checkSessionExpiration(duration, lastMessageTimestamp, lastTimestamp) {
|
|
7710
|
+
return lastTimestamp - lastMessageTimestamp > convertToSeconds(duration);
|
|
7711
|
+
}
|
|
7712
|
+
|
|
7648
7713
|
function useExternalScript(url) {
|
|
7649
7714
|
React$1.useEffect(function () {
|
|
7650
7715
|
if (!url) {
|
|
@@ -30824,7 +30889,13 @@ var ChatWidget = function (props) {
|
|
|
30824
30889
|
set$1("visible", newVisible);
|
|
30825
30890
|
}, [staticMode]);
|
|
30826
30891
|
React$1.useEffect(function () {
|
|
30827
|
-
|
|
30892
|
+
var _a;
|
|
30893
|
+
if (checkSessionExpiration(chatState === null || chatState === void 0 ? void 0 : chatState.sessionExpiration, (_a = chatState === null || chatState === void 0 ? void 0 : chatState.chats[chatState.chats.length - 1]) === null || _a === void 0 ? void 0 : _a.timestamp, chatState === null || chatState === void 0 ? void 0 : chatState.lastTimestamp)) {
|
|
30894
|
+
innerDispatch(reset());
|
|
30895
|
+
}
|
|
30896
|
+
}, []);
|
|
30897
|
+
React$1.useEffect(function () {
|
|
30898
|
+
// For reopen widget after move on same windowyar
|
|
30828
30899
|
if (get("opened")) {
|
|
30829
30900
|
setVisible(true);
|
|
30830
30901
|
}
|
|
@@ -30994,7 +31065,7 @@ function createDefaultState(state) {
|
|
|
30994
31065
|
connectionStatus: "offline",
|
|
30995
31066
|
token: null,
|
|
30996
31067
|
greetingRequested: false
|
|
30997
|
-
}, accountStatus: "offline", departments: {}, visitor: DEFAULT_VISITOR, agents: {}, chats: [], lastTimestamp: 0, lastRatingRequestTimestamp: 0, hasRating: false, isChatting: false, queuePosition: 0, failureMsg: null, visitorId: visitorFingerprint(), chips: [] }, state);
|
|
31068
|
+
}, accountStatus: "offline", departments: {}, visitor: DEFAULT_VISITOR, agents: {}, chats: [], lastTimestamp: 0, lastRatingRequestTimestamp: 0, hasRating: false, isChatting: false, queuePosition: 0, failureMsg: null, visitorId: visitorFingerprint(), chips: [], sessionExpiration: "24h" }, state);
|
|
30998
31069
|
}
|
|
30999
31070
|
var DEFAULT_STATE = createDefaultState();
|
|
31000
31071
|
|
|
@@ -31191,7 +31262,7 @@ function createChatStore(config, dataStorage) {
|
|
|
31191
31262
|
if (dataStorage === void 0) { dataStorage = localStorage; }
|
|
31192
31263
|
var connection = config.connection;
|
|
31193
31264
|
var storage = new BrowserStateStorage(dataStorage, "xappchat.".concat(connection.serverUrl, ".").concat(connection.accountKey));
|
|
31194
|
-
var defaultState = createDefaultState({ accessToken: config.accessToken, userId: config.userId, attributes: config.attributes });
|
|
31265
|
+
var defaultState = createDefaultState({ accessToken: config.accessToken, userId: config.userId, attributes: config.attributes, sessionExpiration: config.sessionExpiration });
|
|
31195
31266
|
var chatReducer = persistStateReducer(storage, defaultState, storeHandler);
|
|
31196
31267
|
var middlewares = [
|
|
31197
31268
|
thunk__default["default"]
|
|
@@ -31201,19 +31272,20 @@ function createChatStore(config, dataStorage) {
|
|
|
31201
31272
|
}
|
|
31202
31273
|
|
|
31203
31274
|
var ChatWidgetContainer = function (props) {
|
|
31204
|
-
var _a, _b, _c, _d;
|
|
31275
|
+
var _a, _b, _c, _d, _e;
|
|
31205
31276
|
var messageMiddleware = useStandardMiddleware();
|
|
31206
31277
|
var connection = useServerConfig(props.config);
|
|
31207
31278
|
var chatStore = React$1.useMemo(function () {
|
|
31208
|
-
var _a, _b, _c;
|
|
31279
|
+
var _a, _b, _c, _d;
|
|
31209
31280
|
return createChatStore({
|
|
31210
31281
|
connection: connection,
|
|
31211
31282
|
userId: (_a = props.config) === null || _a === void 0 ? void 0 : _a.userId,
|
|
31212
31283
|
accessToken: (_b = props.config) === null || _b === void 0 ? void 0 : _b.accessToken,
|
|
31213
31284
|
attributes: (_c = props.config) === null || _c === void 0 ? void 0 : _c.attributes,
|
|
31285
|
+
sessionExpiration: (_d = props.config) === null || _d === void 0 ? void 0 : _d.sessionExpiration
|
|
31214
31286
|
});
|
|
31215
|
-
}, [connection, (_a = props.config) === null || _a === void 0 ? void 0 : _a.userId, (_b = props.config) === null || _b === void 0 ? void 0 : _b.accessToken, (_c = props.config) === null || _c === void 0 ? void 0 : _c.attributes]);
|
|
31216
|
-
if ((
|
|
31287
|
+
}, [connection, (_a = props.config) === null || _a === void 0 ? void 0 : _a.userId, (_b = props.config) === null || _b === void 0 ? void 0 : _b.accessToken, (_c = props.config) === null || _c === void 0 ? void 0 : _c.attributes, (_d = props.config) === null || _d === void 0 ? void 0 : _d.sessionExpiration]);
|
|
31288
|
+
if ((_e = props.config) === null || _e === void 0 ? void 0 : _e.disabled) {
|
|
31217
31289
|
return React__default$1["default"].createElement(React__default$1["default"].Fragment, null);
|
|
31218
31290
|
}
|
|
31219
31291
|
var widgetProps = __assign(__assign({}, props), { messageMiddleware: messageMiddleware });
|