@stacks/blockchain-api-client 7.1.0 → 7.1.7
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/README.md +4 -4
- package/lib/generated/apis/FaucetsApi.d.ts +4 -4
- package/lib/generated/apis/FaucetsApi.js +2 -2
- package/lib/generated/apis/FungibleTokensApi.d.ts +8 -8
- package/lib/generated/apis/FungibleTokensApi.js +4 -4
- package/lib/generated/apis/NonFungibleTokensApi.d.ts +8 -8
- package/lib/generated/apis/NonFungibleTokensApi.js +4 -4
- package/lib/generated/runtime.js +1 -1
- package/lib/generated/runtime.js.map +1 -1
- package/lib/index.umd.js +1081 -764
- package/lib/index.umd.js.map +1 -1
- package/package.json +6 -6
- package/src/generated/apis/FaucetsApi.ts +4 -4
- package/src/generated/apis/FungibleTokensApi.ts +8 -8
- package/src/generated/apis/NonFungibleTokensApi.ts +8 -8
- package/src/generated/runtime.ts +1 -1
package/lib/index.umd.js
CHANGED
|
@@ -376,7 +376,7 @@
|
|
|
376
376
|
}, check);
|
|
377
377
|
}
|
|
378
378
|
|
|
379
|
-
var BASE_PATH = "https://
|
|
379
|
+
var BASE_PATH = "https://api.mainnet.hiro.so".replace(/\/+$/, "");
|
|
380
380
|
|
|
381
381
|
var isBlob = function isBlob(value) {
|
|
382
382
|
return typeof Blob !== 'undefined' && value instanceof Blob;
|
|
@@ -7325,7 +7325,7 @@
|
|
|
7325
7325
|
}
|
|
7326
7326
|
}
|
|
7327
7327
|
/**
|
|
7328
|
-
* Add 500 STX tokens to the specified testnet address. Testnet STX addresses begin with `ST`. If the `stacking` parameter is set to `true`, the faucet will add the required number of tokens for individual stacking to the specified testnet address. The endpoint returns the transaction ID, which you can use to view the transaction in the [Stacks Explorer](https://explorer.
|
|
7328
|
+
* Add 500 STX tokens to the specified testnet address. Testnet STX addresses begin with `ST`. If the `stacking` parameter is set to `true`, the faucet will add the required number of tokens for individual stacking to the specified testnet address. The endpoint returns the transaction ID, which you can use to view the transaction in the [Stacks Explorer](https://explorer.hiro.so/?chain=testnet). The tokens are delivered once the transaction has been included in an anchor block. A common reason for failed faucet transactions is that the faucet has run out of tokens. If you are experiencing failed faucet transactions to a testnet address, you can get help in [Discord](https://stacks.chat). **Note:** This is a testnet only endpoint. This endpoint will not work on the mainnet.
|
|
7329
7329
|
* Get STX testnet tokens
|
|
7330
7330
|
*/
|
|
7331
7331
|
;
|
|
@@ -7366,7 +7366,7 @@
|
|
|
7366
7366
|
}
|
|
7367
7367
|
}
|
|
7368
7368
|
/**
|
|
7369
|
-
* Add 500 STX tokens to the specified testnet address. Testnet STX addresses begin with `ST`. If the `stacking` parameter is set to `true`, the faucet will add the required number of tokens for individual stacking to the specified testnet address. The endpoint returns the transaction ID, which you can use to view the transaction in the [Stacks Explorer](https://explorer.
|
|
7369
|
+
* Add 500 STX tokens to the specified testnet address. Testnet STX addresses begin with `ST`. If the `stacking` parameter is set to `true`, the faucet will add the required number of tokens for individual stacking to the specified testnet address. The endpoint returns the transaction ID, which you can use to view the transaction in the [Stacks Explorer](https://explorer.hiro.so/?chain=testnet). The tokens are delivered once the transaction has been included in an anchor block. A common reason for failed faucet transactions is that the faucet has run out of tokens. If you are experiencing failed faucet transactions to a testnet address, you can get help in [Discord](https://stacks.chat). **Note:** This is a testnet only endpoint. This endpoint will not work on the mainnet.
|
|
7370
7370
|
* Get STX testnet tokens
|
|
7371
7371
|
*/
|
|
7372
7372
|
;
|
|
@@ -7550,7 +7550,7 @@
|
|
|
7550
7550
|
var _proto = FungibleTokensApi.prototype;
|
|
7551
7551
|
|
|
7552
7552
|
/**
|
|
7553
|
-
* Retrieves the metadata for fungible tokens for a given contract id
|
|
7553
|
+
* **NOTE:** This endpoint is deprecated in favor of the [Token Metadata Service](https://github.com/hirosystems/token-metadata-service). Retrieves the metadata for fungible tokens for a given contract id
|
|
7554
7554
|
* Fungible tokens metadata for contract id
|
|
7555
7555
|
*/
|
|
7556
7556
|
_proto.getContractFtMetadataRaw = function getContractFtMetadataRaw(requestParameters, initOverrides) {
|
|
@@ -7578,7 +7578,7 @@
|
|
|
7578
7578
|
}
|
|
7579
7579
|
}
|
|
7580
7580
|
/**
|
|
7581
|
-
* Retrieves the metadata for fungible tokens for a given contract id
|
|
7581
|
+
* **NOTE:** This endpoint is deprecated in favor of the [Token Metadata Service](https://github.com/hirosystems/token-metadata-service). Retrieves the metadata for fungible tokens for a given contract id
|
|
7582
7582
|
* Fungible tokens metadata for contract id
|
|
7583
7583
|
*/
|
|
7584
7584
|
;
|
|
@@ -7595,7 +7595,7 @@
|
|
|
7595
7595
|
}
|
|
7596
7596
|
}
|
|
7597
7597
|
/**
|
|
7598
|
-
* Retrieves list of fungible tokens with their metadata. More information on Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#fungible-tokens).
|
|
7598
|
+
* **NOTE:** This endpoint is deprecated in favor of the [Token Metadata Service](https://github.com/hirosystems/token-metadata-service). Retrieves list of fungible tokens with their metadata. More information on Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#fungible-tokens).
|
|
7599
7599
|
* Fungible tokens metadata list
|
|
7600
7600
|
*/
|
|
7601
7601
|
;
|
|
@@ -7630,7 +7630,7 @@
|
|
|
7630
7630
|
}
|
|
7631
7631
|
}
|
|
7632
7632
|
/**
|
|
7633
|
-
* Retrieves list of fungible tokens with their metadata. More information on Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#fungible-tokens).
|
|
7633
|
+
* **NOTE:** This endpoint is deprecated in favor of the [Token Metadata Service](https://github.com/hirosystems/token-metadata-service). Retrieves list of fungible tokens with their metadata. More information on Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#fungible-tokens).
|
|
7634
7634
|
* Fungible tokens metadata list
|
|
7635
7635
|
*/
|
|
7636
7636
|
;
|
|
@@ -8729,7 +8729,7 @@
|
|
|
8729
8729
|
var _proto = NonFungibleTokensApi.prototype;
|
|
8730
8730
|
|
|
8731
8731
|
/**
|
|
8732
|
-
* Retrieves metadata for non fungible tokens for a given contract id. More information on Non-Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#non-fungible-tokens-nfts).
|
|
8732
|
+
* **NOTE:** This endpoint is deprecated in favor of the [Token Metadata Service](https://github.com/hirosystems/token-metadata-service). Retrieves metadata for non fungible tokens for a given contract id. More information on Non-Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#non-fungible-tokens-nfts).
|
|
8733
8733
|
* Non fungible tokens metadata for contract ID
|
|
8734
8734
|
*/
|
|
8735
8735
|
_proto.getContractNftMetadataRaw = function getContractNftMetadataRaw(requestParameters, initOverrides) {
|
|
@@ -8757,7 +8757,7 @@
|
|
|
8757
8757
|
}
|
|
8758
8758
|
}
|
|
8759
8759
|
/**
|
|
8760
|
-
* Retrieves metadata for non fungible tokens for a given contract id. More information on Non-Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#non-fungible-tokens-nfts).
|
|
8760
|
+
* **NOTE:** This endpoint is deprecated in favor of the [Token Metadata Service](https://github.com/hirosystems/token-metadata-service). Retrieves metadata for non fungible tokens for a given contract id. More information on Non-Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#non-fungible-tokens-nfts).
|
|
8761
8761
|
* Non fungible tokens metadata for contract ID
|
|
8762
8762
|
*/
|
|
8763
8763
|
;
|
|
@@ -8922,7 +8922,7 @@
|
|
|
8922
8922
|
}
|
|
8923
8923
|
}
|
|
8924
8924
|
/**
|
|
8925
|
-
* Retrieves a list of non fungible tokens with their metadata. More information on Non-Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#non-fungible-tokens-nfts).
|
|
8925
|
+
* **NOTE:** This endpoint is deprecated in favor of the [Token Metadata Service](https://github.com/hirosystems/token-metadata-service). Retrieves a list of non fungible tokens with their metadata. More information on Non-Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#non-fungible-tokens-nfts).
|
|
8926
8926
|
* Non fungible tokens metadata list
|
|
8927
8927
|
*/
|
|
8928
8928
|
;
|
|
@@ -8957,7 +8957,7 @@
|
|
|
8957
8957
|
}
|
|
8958
8958
|
}
|
|
8959
8959
|
/**
|
|
8960
|
-
* Retrieves a list of non fungible tokens with their metadata. More information on Non-Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#non-fungible-tokens-nfts).
|
|
8960
|
+
* **NOTE:** This endpoint is deprecated in favor of the [Token Metadata Service](https://github.com/hirosystems/token-metadata-service). Retrieves a list of non fungible tokens with their metadata. More information on Non-Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#non-fungible-tokens-nfts).
|
|
8961
8961
|
* Non fungible tokens metadata list
|
|
8962
8962
|
*/
|
|
8963
8963
|
;
|
|
@@ -11441,7 +11441,7 @@
|
|
|
11441
11441
|
validateMessage(object, true);
|
|
11442
11442
|
return object;
|
|
11443
11443
|
}
|
|
11444
|
-
function parse(message) {
|
|
11444
|
+
function parse$1(message) {
|
|
11445
11445
|
if (!isString(message)) {
|
|
11446
11446
|
return new JsonRpcParsed(JsonRpcError.invalidRequest(message), "invalid" /* invalid */);
|
|
11447
11447
|
}
|
|
@@ -12043,7 +12043,7 @@
|
|
|
12043
12043
|
this.eventEmitter = new eventemitter3.EventEmitter();
|
|
12044
12044
|
this.webSocket = webSocket;
|
|
12045
12045
|
webSocket.addEventListener('message', function (event) {
|
|
12046
|
-
var parsed = parse(event.data);
|
|
12046
|
+
var parsed = parse$1(event.data);
|
|
12047
12047
|
var rpcObjects = Array.isArray(parsed) ? parsed : [parsed];
|
|
12048
12048
|
rpcObjects.forEach(function (obj) {
|
|
12049
12049
|
if (obj.type === "notification"
|
|
@@ -12410,209 +12410,164 @@
|
|
|
12410
12410
|
}
|
|
12411
12411
|
}
|
|
12412
12412
|
|
|
12413
|
-
|
|
12414
|
-
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
-
|
|
12422
|
-
|
|
12423
|
-
|
|
12424
|
-
|
|
12425
|
-
|
|
12426
|
-
var src = str,
|
|
12427
|
-
b = str.indexOf('['),
|
|
12428
|
-
e = str.indexOf(']');
|
|
12429
|
-
|
|
12430
|
-
if (b != -1 && e != -1) {
|
|
12431
|
-
str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
|
|
12432
|
-
}
|
|
12433
|
-
|
|
12434
|
-
var m = re.exec(str || ''),
|
|
12435
|
-
uri = {},
|
|
12436
|
-
i = 14;
|
|
12437
|
-
|
|
12438
|
-
while (i--) {
|
|
12439
|
-
uri[parts[i]] = m[i] || '';
|
|
12440
|
-
}
|
|
12441
|
-
|
|
12442
|
-
if (b != -1 && e != -1) {
|
|
12443
|
-
uri.source = src;
|
|
12444
|
-
uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
|
|
12445
|
-
uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
|
|
12446
|
-
uri.ipv6uri = true;
|
|
12447
|
-
}
|
|
12448
|
-
|
|
12449
|
-
uri.pathNames = pathNames(uri, uri['path']);
|
|
12450
|
-
uri.queryKey = queryKey(uri, uri['query']);
|
|
12413
|
+
const PACKET_TYPES = Object.create(null); // no Map = no polyfill
|
|
12414
|
+
PACKET_TYPES["open"] = "0";
|
|
12415
|
+
PACKET_TYPES["close"] = "1";
|
|
12416
|
+
PACKET_TYPES["ping"] = "2";
|
|
12417
|
+
PACKET_TYPES["pong"] = "3";
|
|
12418
|
+
PACKET_TYPES["message"] = "4";
|
|
12419
|
+
PACKET_TYPES["upgrade"] = "5";
|
|
12420
|
+
PACKET_TYPES["noop"] = "6";
|
|
12421
|
+
const PACKET_TYPES_REVERSE = Object.create(null);
|
|
12422
|
+
Object.keys(PACKET_TYPES).forEach(key => {
|
|
12423
|
+
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
|
|
12424
|
+
});
|
|
12425
|
+
const ERROR_PACKET = { type: "error", data: "parser error" };
|
|
12451
12426
|
|
|
12452
|
-
|
|
12427
|
+
const withNativeBlob$1 = typeof Blob === "function" ||
|
|
12428
|
+
(typeof Blob !== "undefined" &&
|
|
12429
|
+
Object.prototype.toString.call(Blob) === "[object BlobConstructor]");
|
|
12430
|
+
const withNativeArrayBuffer$2 = typeof ArrayBuffer === "function";
|
|
12431
|
+
// ArrayBuffer.isView method is not defined in IE10
|
|
12432
|
+
const isView$1 = obj => {
|
|
12433
|
+
return typeof ArrayBuffer.isView === "function"
|
|
12434
|
+
? ArrayBuffer.isView(obj)
|
|
12435
|
+
: obj && obj.buffer instanceof ArrayBuffer;
|
|
12453
12436
|
};
|
|
12454
|
-
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
if (path.substr(0, 1) == '/' || path.length === 0) {
|
|
12460
|
-
names.splice(0, 1);
|
|
12461
|
-
}
|
|
12462
|
-
if (path.substr(path.length - 1, 1) == '/') {
|
|
12463
|
-
names.splice(names.length - 1, 1);
|
|
12464
|
-
}
|
|
12465
|
-
|
|
12466
|
-
return names;
|
|
12467
|
-
}
|
|
12468
|
-
|
|
12469
|
-
function queryKey(uri, query) {
|
|
12470
|
-
var data = {};
|
|
12471
|
-
|
|
12472
|
-
query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
|
|
12473
|
-
if ($1) {
|
|
12474
|
-
data[$1] = $2;
|
|
12475
|
-
}
|
|
12476
|
-
});
|
|
12477
|
-
|
|
12478
|
-
return data;
|
|
12479
|
-
}
|
|
12480
|
-
|
|
12481
|
-
/**
|
|
12482
|
-
* URL parser.
|
|
12483
|
-
*
|
|
12484
|
-
* @param uri - url
|
|
12485
|
-
* @param path - the request path of the connection
|
|
12486
|
-
* @param loc - An object meant to mimic window.location.
|
|
12487
|
-
* Defaults to window.location.
|
|
12488
|
-
* @public
|
|
12489
|
-
*/
|
|
12490
|
-
function url(uri, path = "", loc) {
|
|
12491
|
-
let obj = uri;
|
|
12492
|
-
// default to window.location
|
|
12493
|
-
loc = loc || (typeof location !== "undefined" && location);
|
|
12494
|
-
if (null == uri)
|
|
12495
|
-
uri = loc.protocol + "//" + loc.host;
|
|
12496
|
-
// relative path support
|
|
12497
|
-
if (typeof uri === "string") {
|
|
12498
|
-
if ("/" === uri.charAt(0)) {
|
|
12499
|
-
if ("/" === uri.charAt(1)) {
|
|
12500
|
-
uri = loc.protocol + uri;
|
|
12501
|
-
}
|
|
12502
|
-
else {
|
|
12503
|
-
uri = loc.host + uri;
|
|
12504
|
-
}
|
|
12437
|
+
const encodePacket = ({ type, data }, supportsBinary, callback) => {
|
|
12438
|
+
if (withNativeBlob$1 && data instanceof Blob) {
|
|
12439
|
+
if (supportsBinary) {
|
|
12440
|
+
return callback(data);
|
|
12505
12441
|
}
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
uri = loc.protocol + "//" + uri;
|
|
12509
|
-
}
|
|
12510
|
-
else {
|
|
12511
|
-
uri = "https://" + uri;
|
|
12512
|
-
}
|
|
12442
|
+
else {
|
|
12443
|
+
return encodeBlobAsBase64(data, callback);
|
|
12513
12444
|
}
|
|
12514
|
-
// parse
|
|
12515
|
-
obj = parseuri(uri);
|
|
12516
12445
|
}
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
if (
|
|
12520
|
-
|
|
12446
|
+
else if (withNativeArrayBuffer$2 &&
|
|
12447
|
+
(data instanceof ArrayBuffer || isView$1(data))) {
|
|
12448
|
+
if (supportsBinary) {
|
|
12449
|
+
return callback(data);
|
|
12521
12450
|
}
|
|
12522
|
-
else
|
|
12523
|
-
|
|
12451
|
+
else {
|
|
12452
|
+
return encodeBlobAsBase64(new Blob([data]), callback);
|
|
12524
12453
|
}
|
|
12525
12454
|
}
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
|
|
12534
|
-
|
|
12535
|
-
|
|
12536
|
-
|
|
12537
|
-
return obj;
|
|
12538
|
-
}
|
|
12539
|
-
|
|
12540
|
-
var hasCors = createCommonjsModule(function (module) {
|
|
12541
|
-
/**
|
|
12542
|
-
* Module exports.
|
|
12543
|
-
*
|
|
12544
|
-
* Logic borrowed from Modernizr:
|
|
12545
|
-
*
|
|
12546
|
-
* - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cors.js
|
|
12547
|
-
*/
|
|
12455
|
+
// plain string
|
|
12456
|
+
return callback(PACKET_TYPES[type] + (data || ""));
|
|
12457
|
+
};
|
|
12458
|
+
const encodeBlobAsBase64 = (data, callback) => {
|
|
12459
|
+
const fileReader = new FileReader();
|
|
12460
|
+
fileReader.onload = function () {
|
|
12461
|
+
const content = fileReader.result.split(",")[1];
|
|
12462
|
+
callback("b" + (content || ""));
|
|
12463
|
+
};
|
|
12464
|
+
return fileReader.readAsDataURL(data);
|
|
12465
|
+
};
|
|
12548
12466
|
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
|
|
12553
|
-
|
|
12554
|
-
|
|
12555
|
-
module.exports = false;
|
|
12467
|
+
// imported from https://github.com/socketio/base64-arraybuffer
|
|
12468
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
12469
|
+
// Use a lookup table to find the index.
|
|
12470
|
+
const lookup$1 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
|
|
12471
|
+
for (let i = 0; i < chars.length; i++) {
|
|
12472
|
+
lookup$1[chars.charCodeAt(i)] = i;
|
|
12556
12473
|
}
|
|
12557
|
-
|
|
12558
|
-
|
|
12559
|
-
|
|
12560
|
-
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
|
|
12564
|
-
return window;
|
|
12474
|
+
const decode$1 = (base64) => {
|
|
12475
|
+
let bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
|
|
12476
|
+
if (base64[base64.length - 1] === '=') {
|
|
12477
|
+
bufferLength--;
|
|
12478
|
+
if (base64[base64.length - 2] === '=') {
|
|
12479
|
+
bufferLength--;
|
|
12480
|
+
}
|
|
12565
12481
|
}
|
|
12566
|
-
|
|
12567
|
-
|
|
12482
|
+
const arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
|
|
12483
|
+
for (i = 0; i < len; i += 4) {
|
|
12484
|
+
encoded1 = lookup$1[base64.charCodeAt(i)];
|
|
12485
|
+
encoded2 = lookup$1[base64.charCodeAt(i + 1)];
|
|
12486
|
+
encoded3 = lookup$1[base64.charCodeAt(i + 2)];
|
|
12487
|
+
encoded4 = lookup$1[base64.charCodeAt(i + 3)];
|
|
12488
|
+
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
|
12489
|
+
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
12490
|
+
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
|
12568
12491
|
}
|
|
12569
|
-
|
|
12492
|
+
return arraybuffer;
|
|
12493
|
+
};
|
|
12570
12494
|
|
|
12571
|
-
|
|
12572
|
-
|
|
12573
|
-
|
|
12574
|
-
|
|
12575
|
-
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
}
|
|
12495
|
+
const withNativeArrayBuffer$1 = typeof ArrayBuffer === "function";
|
|
12496
|
+
const decodePacket = (encodedPacket, binaryType) => {
|
|
12497
|
+
if (typeof encodedPacket !== "string") {
|
|
12498
|
+
return {
|
|
12499
|
+
type: "message",
|
|
12500
|
+
data: mapBinary(encodedPacket, binaryType)
|
|
12501
|
+
};
|
|
12579
12502
|
}
|
|
12580
|
-
|
|
12581
|
-
if (
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12503
|
+
const type = encodedPacket.charAt(0);
|
|
12504
|
+
if (type === "b") {
|
|
12505
|
+
return {
|
|
12506
|
+
type: "message",
|
|
12507
|
+
data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
|
|
12508
|
+
};
|
|
12586
12509
|
}
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
|
|
12592
|
-
|
|
12510
|
+
const packetType = PACKET_TYPES_REVERSE[type];
|
|
12511
|
+
if (!packetType) {
|
|
12512
|
+
return ERROR_PACKET;
|
|
12513
|
+
}
|
|
12514
|
+
return encodedPacket.length > 1
|
|
12515
|
+
? {
|
|
12516
|
+
type: PACKET_TYPES_REVERSE[type],
|
|
12517
|
+
data: encodedPacket.substring(1)
|
|
12593
12518
|
}
|
|
12594
|
-
|
|
12595
|
-
|
|
12596
|
-
|
|
12597
|
-
|
|
12598
|
-
const
|
|
12599
|
-
|
|
12600
|
-
|
|
12601
|
-
|
|
12602
|
-
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThis);
|
|
12603
|
-
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThis);
|
|
12519
|
+
: {
|
|
12520
|
+
type: PACKET_TYPES_REVERSE[type]
|
|
12521
|
+
};
|
|
12522
|
+
};
|
|
12523
|
+
const decodeBase64Packet = (data, binaryType) => {
|
|
12524
|
+
if (withNativeArrayBuffer$1) {
|
|
12525
|
+
const decoded = decode$1(data);
|
|
12526
|
+
return mapBinary(decoded, binaryType);
|
|
12604
12527
|
}
|
|
12605
12528
|
else {
|
|
12606
|
-
|
|
12607
|
-
obj.clearTimeoutFn = clearTimeout.bind(globalThis);
|
|
12529
|
+
return { base64: true, data }; // fallback for old browsers
|
|
12608
12530
|
}
|
|
12609
|
-
}
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
|
|
12613
|
-
|
|
12531
|
+
};
|
|
12532
|
+
const mapBinary = (data, binaryType) => {
|
|
12533
|
+
switch (binaryType) {
|
|
12534
|
+
case "blob":
|
|
12535
|
+
return data instanceof ArrayBuffer ? new Blob([data]) : data;
|
|
12536
|
+
case "arraybuffer":
|
|
12537
|
+
default:
|
|
12538
|
+
return data; // assuming the data is already an ArrayBuffer
|
|
12539
|
+
}
|
|
12540
|
+
};
|
|
12614
12541
|
|
|
12615
|
-
|
|
12542
|
+
const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
|
|
12543
|
+
const encodePayload = (packets, callback) => {
|
|
12544
|
+
// some packets may be added to the array while encoding, so the initial length must be saved
|
|
12545
|
+
const length = packets.length;
|
|
12546
|
+
const encodedPackets = new Array(length);
|
|
12547
|
+
let count = 0;
|
|
12548
|
+
packets.forEach((packet, i) => {
|
|
12549
|
+
// force base64 encoding for binary packets
|
|
12550
|
+
encodePacket(packet, false, encodedPacket => {
|
|
12551
|
+
encodedPackets[i] = encodedPacket;
|
|
12552
|
+
if (++count === length) {
|
|
12553
|
+
callback(encodedPackets.join(SEPARATOR));
|
|
12554
|
+
}
|
|
12555
|
+
});
|
|
12556
|
+
});
|
|
12557
|
+
};
|
|
12558
|
+
const decodePayload = (encodedPayload, binaryType) => {
|
|
12559
|
+
const encodedPackets = encodedPayload.split(SEPARATOR);
|
|
12560
|
+
const packets = [];
|
|
12561
|
+
for (let i = 0; i < encodedPackets.length; i++) {
|
|
12562
|
+
const decodedPacket = decodePacket(encodedPackets[i], binaryType);
|
|
12563
|
+
packets.push(decodedPacket);
|
|
12564
|
+
if (decodedPacket.type === "error") {
|
|
12565
|
+
break;
|
|
12566
|
+
}
|
|
12567
|
+
}
|
|
12568
|
+
return packets;
|
|
12569
|
+
};
|
|
12570
|
+
const protocol$1 = 4;
|
|
12616
12571
|
|
|
12617
12572
|
/**
|
|
12618
12573
|
* Initialize a new `Emitter`.
|
|
@@ -12784,175 +12739,84 @@
|
|
|
12784
12739
|
return !! this.listeners(event).length;
|
|
12785
12740
|
};
|
|
12786
12741
|
|
|
12787
|
-
const
|
|
12788
|
-
|
|
12789
|
-
|
|
12790
|
-
PACKET_TYPES["ping"] = "2";
|
|
12791
|
-
PACKET_TYPES["pong"] = "3";
|
|
12792
|
-
PACKET_TYPES["message"] = "4";
|
|
12793
|
-
PACKET_TYPES["upgrade"] = "5";
|
|
12794
|
-
PACKET_TYPES["noop"] = "6";
|
|
12795
|
-
const PACKET_TYPES_REVERSE = Object.create(null);
|
|
12796
|
-
Object.keys(PACKET_TYPES).forEach(key => {
|
|
12797
|
-
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
|
|
12798
|
-
});
|
|
12799
|
-
const ERROR_PACKET = { type: "error", data: "parser error" };
|
|
12800
|
-
|
|
12801
|
-
const withNativeBlob$1 = typeof Blob === "function" ||
|
|
12802
|
-
(typeof Blob !== "undefined" &&
|
|
12803
|
-
Object.prototype.toString.call(Blob) === "[object BlobConstructor]");
|
|
12804
|
-
const withNativeArrayBuffer$2 = typeof ArrayBuffer === "function";
|
|
12805
|
-
// ArrayBuffer.isView method is not defined in IE10
|
|
12806
|
-
const isView$1 = obj => {
|
|
12807
|
-
return typeof ArrayBuffer.isView === "function"
|
|
12808
|
-
? ArrayBuffer.isView(obj)
|
|
12809
|
-
: obj && obj.buffer instanceof ArrayBuffer;
|
|
12810
|
-
};
|
|
12811
|
-
const encodePacket = ({ type, data }, supportsBinary, callback) => {
|
|
12812
|
-
if (withNativeBlob$1 && data instanceof Blob) {
|
|
12813
|
-
if (supportsBinary) {
|
|
12814
|
-
return callback(data);
|
|
12815
|
-
}
|
|
12816
|
-
else {
|
|
12817
|
-
return encodeBlobAsBase64(data, callback);
|
|
12818
|
-
}
|
|
12819
|
-
}
|
|
12820
|
-
else if (withNativeArrayBuffer$2 &&
|
|
12821
|
-
(data instanceof ArrayBuffer || isView$1(data))) {
|
|
12822
|
-
if (supportsBinary) {
|
|
12823
|
-
return callback(data);
|
|
12824
|
-
}
|
|
12825
|
-
else {
|
|
12826
|
-
return encodeBlobAsBase64(new Blob([data]), callback);
|
|
12827
|
-
}
|
|
12742
|
+
const globalThisShim = (() => {
|
|
12743
|
+
if (typeof self !== "undefined") {
|
|
12744
|
+
return self;
|
|
12828
12745
|
}
|
|
12829
|
-
|
|
12830
|
-
|
|
12831
|
-
};
|
|
12832
|
-
const encodeBlobAsBase64 = (data, callback) => {
|
|
12833
|
-
const fileReader = new FileReader();
|
|
12834
|
-
fileReader.onload = function () {
|
|
12835
|
-
const content = fileReader.result.split(",")[1];
|
|
12836
|
-
callback("b" + content);
|
|
12837
|
-
};
|
|
12838
|
-
return fileReader.readAsDataURL(data);
|
|
12839
|
-
};
|
|
12840
|
-
|
|
12841
|
-
/*
|
|
12842
|
-
* base64-arraybuffer 1.0.1 <https://github.com/niklasvh/base64-arraybuffer>
|
|
12843
|
-
* Copyright (c) 2021 Niklas von Hertzen <https://hertzen.com>
|
|
12844
|
-
* Released under MIT License
|
|
12845
|
-
*/
|
|
12846
|
-
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
12847
|
-
// Use a lookup table to find the index.
|
|
12848
|
-
var lookup$1 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
|
|
12849
|
-
for (var i$1 = 0; i$1 < chars.length; i$1++) {
|
|
12850
|
-
lookup$1[chars.charCodeAt(i$1)] = i$1;
|
|
12851
|
-
}
|
|
12852
|
-
var decode$2 = function (base64) {
|
|
12853
|
-
var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
|
|
12854
|
-
if (base64[base64.length - 1] === '=') {
|
|
12855
|
-
bufferLength--;
|
|
12856
|
-
if (base64[base64.length - 2] === '=') {
|
|
12857
|
-
bufferLength--;
|
|
12858
|
-
}
|
|
12746
|
+
else if (typeof window !== "undefined") {
|
|
12747
|
+
return window;
|
|
12859
12748
|
}
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
encoded1 = lookup$1[base64.charCodeAt(i)];
|
|
12863
|
-
encoded2 = lookup$1[base64.charCodeAt(i + 1)];
|
|
12864
|
-
encoded3 = lookup$1[base64.charCodeAt(i + 2)];
|
|
12865
|
-
encoded4 = lookup$1[base64.charCodeAt(i + 3)];
|
|
12866
|
-
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
|
12867
|
-
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
12868
|
-
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
|
12749
|
+
else {
|
|
12750
|
+
return Function("return this")();
|
|
12869
12751
|
}
|
|
12870
|
-
|
|
12871
|
-
};
|
|
12752
|
+
})();
|
|
12872
12753
|
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
|
|
12877
|
-
type: "message",
|
|
12878
|
-
data: mapBinary(encodedPacket, binaryType)
|
|
12879
|
-
};
|
|
12880
|
-
}
|
|
12881
|
-
const type = encodedPacket.charAt(0);
|
|
12882
|
-
if (type === "b") {
|
|
12883
|
-
return {
|
|
12884
|
-
type: "message",
|
|
12885
|
-
data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
|
|
12886
|
-
};
|
|
12887
|
-
}
|
|
12888
|
-
const packetType = PACKET_TYPES_REVERSE[type];
|
|
12889
|
-
if (!packetType) {
|
|
12890
|
-
return ERROR_PACKET;
|
|
12891
|
-
}
|
|
12892
|
-
return encodedPacket.length > 1
|
|
12893
|
-
? {
|
|
12894
|
-
type: PACKET_TYPES_REVERSE[type],
|
|
12895
|
-
data: encodedPacket.substring(1)
|
|
12754
|
+
function pick(obj, ...attr) {
|
|
12755
|
+
return attr.reduce((acc, k) => {
|
|
12756
|
+
if (obj.hasOwnProperty(k)) {
|
|
12757
|
+
acc[k] = obj[k];
|
|
12896
12758
|
}
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
const
|
|
12902
|
-
|
|
12903
|
-
|
|
12904
|
-
|
|
12759
|
+
return acc;
|
|
12760
|
+
}, {});
|
|
12761
|
+
}
|
|
12762
|
+
// Keep a reference to the real timeout functions so they can be used when overridden
|
|
12763
|
+
const NATIVE_SET_TIMEOUT = globalThisShim.setTimeout;
|
|
12764
|
+
const NATIVE_CLEAR_TIMEOUT = globalThisShim.clearTimeout;
|
|
12765
|
+
function installTimerFunctions(obj, opts) {
|
|
12766
|
+
if (opts.useNativeTimers) {
|
|
12767
|
+
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThisShim);
|
|
12768
|
+
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThisShim);
|
|
12905
12769
|
}
|
|
12906
12770
|
else {
|
|
12907
|
-
|
|
12908
|
-
|
|
12909
|
-
|
|
12910
|
-
|
|
12911
|
-
|
|
12912
|
-
|
|
12913
|
-
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
|
|
12917
|
-
}
|
|
12918
|
-
|
|
12919
|
-
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
12923
|
-
|
|
12924
|
-
|
|
12925
|
-
|
|
12926
|
-
|
|
12927
|
-
|
|
12928
|
-
|
|
12929
|
-
|
|
12930
|
-
|
|
12931
|
-
|
|
12932
|
-
|
|
12933
|
-
}
|
|
12934
|
-
|
|
12935
|
-
|
|
12936
|
-
|
|
12937
|
-
const encodedPackets = encodedPayload.split(SEPARATOR);
|
|
12938
|
-
const packets = [];
|
|
12939
|
-
for (let i = 0; i < encodedPackets.length; i++) {
|
|
12940
|
-
const decodedPacket = decodePacket(encodedPackets[i], binaryType);
|
|
12941
|
-
packets.push(decodedPacket);
|
|
12942
|
-
if (decodedPacket.type === "error") {
|
|
12943
|
-
break;
|
|
12771
|
+
obj.setTimeoutFn = globalThisShim.setTimeout.bind(globalThisShim);
|
|
12772
|
+
obj.clearTimeoutFn = globalThisShim.clearTimeout.bind(globalThisShim);
|
|
12773
|
+
}
|
|
12774
|
+
}
|
|
12775
|
+
// base64 encoded buffers are about 33% bigger (https://en.wikipedia.org/wiki/Base64)
|
|
12776
|
+
const BASE64_OVERHEAD = 1.33;
|
|
12777
|
+
// we could also have used `new Blob([obj]).size`, but it isn't supported in IE9
|
|
12778
|
+
function byteLength(obj) {
|
|
12779
|
+
if (typeof obj === "string") {
|
|
12780
|
+
return utf8Length(obj);
|
|
12781
|
+
}
|
|
12782
|
+
// arraybuffer or blob
|
|
12783
|
+
return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
|
|
12784
|
+
}
|
|
12785
|
+
function utf8Length(str) {
|
|
12786
|
+
let c = 0, length = 0;
|
|
12787
|
+
for (let i = 0, l = str.length; i < l; i++) {
|
|
12788
|
+
c = str.charCodeAt(i);
|
|
12789
|
+
if (c < 0x80) {
|
|
12790
|
+
length += 1;
|
|
12791
|
+
}
|
|
12792
|
+
else if (c < 0x800) {
|
|
12793
|
+
length += 2;
|
|
12794
|
+
}
|
|
12795
|
+
else if (c < 0xd800 || c >= 0xe000) {
|
|
12796
|
+
length += 3;
|
|
12797
|
+
}
|
|
12798
|
+
else {
|
|
12799
|
+
i++;
|
|
12800
|
+
length += 4;
|
|
12944
12801
|
}
|
|
12945
12802
|
}
|
|
12946
|
-
return
|
|
12947
|
-
}
|
|
12948
|
-
const protocol$1 = 4;
|
|
12803
|
+
return length;
|
|
12804
|
+
}
|
|
12949
12805
|
|
|
12950
|
-
class
|
|
12806
|
+
class TransportError extends Error {
|
|
12807
|
+
constructor(reason, description, context) {
|
|
12808
|
+
super(reason);
|
|
12809
|
+
this.description = description;
|
|
12810
|
+
this.context = context;
|
|
12811
|
+
this.type = "TransportError";
|
|
12812
|
+
}
|
|
12813
|
+
}
|
|
12814
|
+
class Transport extends Emitter {
|
|
12951
12815
|
/**
|
|
12952
12816
|
* Transport abstract constructor.
|
|
12953
12817
|
*
|
|
12954
|
-
* @param {Object} options
|
|
12955
|
-
* @
|
|
12818
|
+
* @param {Object} opts - options
|
|
12819
|
+
* @protected
|
|
12956
12820
|
*/
|
|
12957
12821
|
constructor(opts) {
|
|
12958
12822
|
super();
|
|
@@ -12960,44 +12824,34 @@
|
|
|
12960
12824
|
installTimerFunctions(this, opts);
|
|
12961
12825
|
this.opts = opts;
|
|
12962
12826
|
this.query = opts.query;
|
|
12963
|
-
this.readyState = "";
|
|
12964
12827
|
this.socket = opts.socket;
|
|
12965
12828
|
}
|
|
12966
12829
|
/**
|
|
12967
12830
|
* Emits an error.
|
|
12968
12831
|
*
|
|
12969
|
-
* @param {String}
|
|
12832
|
+
* @param {String} reason
|
|
12833
|
+
* @param description
|
|
12834
|
+
* @param context - the error context
|
|
12970
12835
|
* @return {Transport} for chaining
|
|
12971
|
-
* @
|
|
12836
|
+
* @protected
|
|
12972
12837
|
*/
|
|
12973
|
-
onError(
|
|
12974
|
-
|
|
12975
|
-
// @ts-ignore
|
|
12976
|
-
err.type = "TransportError";
|
|
12977
|
-
// @ts-ignore
|
|
12978
|
-
err.description = desc;
|
|
12979
|
-
super.emit("error", err);
|
|
12838
|
+
onError(reason, description, context) {
|
|
12839
|
+
super.emitReserved("error", new TransportError(reason, description, context));
|
|
12980
12840
|
return this;
|
|
12981
12841
|
}
|
|
12982
12842
|
/**
|
|
12983
12843
|
* Opens the transport.
|
|
12984
|
-
*
|
|
12985
|
-
* @api public
|
|
12986
12844
|
*/
|
|
12987
12845
|
open() {
|
|
12988
|
-
|
|
12989
|
-
|
|
12990
|
-
this.doOpen();
|
|
12991
|
-
}
|
|
12846
|
+
this.readyState = "opening";
|
|
12847
|
+
this.doOpen();
|
|
12992
12848
|
return this;
|
|
12993
12849
|
}
|
|
12994
12850
|
/**
|
|
12995
12851
|
* Closes the transport.
|
|
12996
|
-
*
|
|
12997
|
-
* @api public
|
|
12998
12852
|
*/
|
|
12999
12853
|
close() {
|
|
13000
|
-
if ("opening"
|
|
12854
|
+
if (this.readyState === "opening" || this.readyState === "open") {
|
|
13001
12855
|
this.doClose();
|
|
13002
12856
|
this.onClose();
|
|
13003
12857
|
}
|
|
@@ -13007,28 +12861,27 @@
|
|
|
13007
12861
|
* Sends multiple packets.
|
|
13008
12862
|
*
|
|
13009
12863
|
* @param {Array} packets
|
|
13010
|
-
* @api public
|
|
13011
12864
|
*/
|
|
13012
12865
|
send(packets) {
|
|
13013
|
-
if ("open"
|
|
12866
|
+
if (this.readyState === "open") {
|
|
13014
12867
|
this.write(packets);
|
|
13015
12868
|
}
|
|
13016
12869
|
}
|
|
13017
12870
|
/**
|
|
13018
12871
|
* Called upon open
|
|
13019
12872
|
*
|
|
13020
|
-
* @
|
|
12873
|
+
* @protected
|
|
13021
12874
|
*/
|
|
13022
12875
|
onOpen() {
|
|
13023
12876
|
this.readyState = "open";
|
|
13024
12877
|
this.writable = true;
|
|
13025
|
-
super.
|
|
12878
|
+
super.emitReserved("open");
|
|
13026
12879
|
}
|
|
13027
12880
|
/**
|
|
13028
12881
|
* Called with data.
|
|
13029
12882
|
*
|
|
13030
12883
|
* @param {String} data
|
|
13031
|
-
* @
|
|
12884
|
+
* @protected
|
|
13032
12885
|
*/
|
|
13033
12886
|
onData(data) {
|
|
13034
12887
|
const packet = decodePacket(data, this.socket.binaryType);
|
|
@@ -13037,64 +12890,46 @@
|
|
|
13037
12890
|
/**
|
|
13038
12891
|
* Called with a decoded packet.
|
|
13039
12892
|
*
|
|
13040
|
-
* @
|
|
12893
|
+
* @protected
|
|
13041
12894
|
*/
|
|
13042
12895
|
onPacket(packet) {
|
|
13043
|
-
super.
|
|
12896
|
+
super.emitReserved("packet", packet);
|
|
13044
12897
|
}
|
|
13045
12898
|
/**
|
|
13046
12899
|
* Called upon close.
|
|
13047
12900
|
*
|
|
13048
|
-
* @
|
|
12901
|
+
* @protected
|
|
13049
12902
|
*/
|
|
13050
|
-
onClose() {
|
|
12903
|
+
onClose(details) {
|
|
13051
12904
|
this.readyState = "closed";
|
|
13052
|
-
super.
|
|
12905
|
+
super.emitReserved("close", details);
|
|
13053
12906
|
}
|
|
12907
|
+
/**
|
|
12908
|
+
* Pauses the transport, in order not to lose packets during an upgrade.
|
|
12909
|
+
*
|
|
12910
|
+
* @param onPause
|
|
12911
|
+
*/
|
|
12912
|
+
pause(onPause) { }
|
|
13054
12913
|
}
|
|
13055
12914
|
|
|
13056
|
-
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
, seed = 0
|
|
13060
|
-
, i = 0
|
|
13061
|
-
, prev;
|
|
13062
|
-
|
|
12915
|
+
// imported from https://github.com/unshiftio/yeast
|
|
12916
|
+
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split(''), length = 64, map = {};
|
|
12917
|
+
let seed = 0, i = 0, prev;
|
|
13063
12918
|
/**
|
|
13064
12919
|
* Return a string representing the specified number.
|
|
13065
12920
|
*
|
|
13066
12921
|
* @param {Number} num The number to convert.
|
|
13067
12922
|
* @returns {String} The string representation of the number.
|
|
13068
|
-
* @api public
|
|
13069
|
-
*/
|
|
13070
|
-
function encode$1(num) {
|
|
13071
|
-
|
|
13072
|
-
|
|
13073
|
-
|
|
13074
|
-
|
|
13075
|
-
|
|
13076
|
-
|
|
13077
|
-
|
|
13078
|
-
return encoded;
|
|
13079
|
-
}
|
|
13080
|
-
|
|
13081
|
-
/**
|
|
13082
|
-
* Return the integer value specified by the given string.
|
|
13083
|
-
*
|
|
13084
|
-
* @param {String} str The string to convert.
|
|
13085
|
-
* @returns {Number} The integer value represented by the string.
|
|
13086
|
-
* @api public
|
|
13087
|
-
*/
|
|
13088
|
-
function decode$1(str) {
|
|
13089
|
-
var decoded = 0;
|
|
13090
|
-
|
|
13091
|
-
for (i = 0; i < str.length; i++) {
|
|
13092
|
-
decoded = decoded * length + map[str.charAt(i)];
|
|
13093
|
-
}
|
|
13094
|
-
|
|
13095
|
-
return decoded;
|
|
12923
|
+
* @api public
|
|
12924
|
+
*/
|
|
12925
|
+
function encode$1(num) {
|
|
12926
|
+
let encoded = '';
|
|
12927
|
+
do {
|
|
12928
|
+
encoded = alphabet[num % length] + encoded;
|
|
12929
|
+
num = Math.floor(num / length);
|
|
12930
|
+
} while (num > 0);
|
|
12931
|
+
return encoded;
|
|
13096
12932
|
}
|
|
13097
|
-
|
|
13098
12933
|
/**
|
|
13099
12934
|
* Yeast: A tiny growing id generator.
|
|
13100
12935
|
*
|
|
@@ -13102,24 +12937,18 @@
|
|
|
13102
12937
|
* @api public
|
|
13103
12938
|
*/
|
|
13104
12939
|
function yeast() {
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
|
|
12940
|
+
const now = encode$1(+new Date());
|
|
12941
|
+
if (now !== prev)
|
|
12942
|
+
return seed = 0, prev = now;
|
|
12943
|
+
return now + '.' + encode$1(seed++);
|
|
13109
12944
|
}
|
|
13110
|
-
|
|
13111
12945
|
//
|
|
13112
12946
|
// Map each character to its index.
|
|
13113
12947
|
//
|
|
13114
|
-
for (; i < length; i++)
|
|
13115
|
-
|
|
13116
|
-
//
|
|
13117
|
-
// Expose the `yeast`, `encode` and `decode` functions.
|
|
13118
|
-
//
|
|
13119
|
-
yeast.encode = encode$1;
|
|
13120
|
-
yeast.decode = decode$1;
|
|
13121
|
-
var yeast_1 = yeast;
|
|
12948
|
+
for (; i < length; i++)
|
|
12949
|
+
map[alphabet[i]] = i;
|
|
13122
12950
|
|
|
12951
|
+
// imported from https://github.com/galkn/querystring
|
|
13123
12952
|
/**
|
|
13124
12953
|
* Compiles a querystring
|
|
13125
12954
|
* Returns string representation of the object
|
|
@@ -13127,49 +12956,99 @@
|
|
|
13127
12956
|
* @param {Object}
|
|
13128
12957
|
* @api private
|
|
13129
12958
|
*/
|
|
13130
|
-
|
|
13131
|
-
|
|
13132
|
-
|
|
13133
|
-
|
|
13134
|
-
|
|
13135
|
-
|
|
13136
|
-
|
|
12959
|
+
function encode(obj) {
|
|
12960
|
+
let str = '';
|
|
12961
|
+
for (let i in obj) {
|
|
12962
|
+
if (obj.hasOwnProperty(i)) {
|
|
12963
|
+
if (str.length)
|
|
12964
|
+
str += '&';
|
|
12965
|
+
str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
|
|
12966
|
+
}
|
|
13137
12967
|
}
|
|
13138
|
-
|
|
13139
|
-
|
|
13140
|
-
return str;
|
|
13141
|
-
};
|
|
13142
|
-
|
|
12968
|
+
return str;
|
|
12969
|
+
}
|
|
13143
12970
|
/**
|
|
13144
12971
|
* Parses a simple querystring into an object
|
|
13145
12972
|
*
|
|
13146
12973
|
* @param {String} qs
|
|
13147
12974
|
* @api private
|
|
13148
12975
|
*/
|
|
12976
|
+
function decode(qs) {
|
|
12977
|
+
let qry = {};
|
|
12978
|
+
let pairs = qs.split('&');
|
|
12979
|
+
for (let i = 0, l = pairs.length; i < l; i++) {
|
|
12980
|
+
let pair = pairs[i].split('=');
|
|
12981
|
+
qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
|
|
12982
|
+
}
|
|
12983
|
+
return qry;
|
|
12984
|
+
}
|
|
13149
12985
|
|
|
13150
|
-
|
|
13151
|
-
|
|
13152
|
-
|
|
13153
|
-
|
|
13154
|
-
|
|
13155
|
-
|
|
13156
|
-
|
|
13157
|
-
|
|
13158
|
-
|
|
12986
|
+
// imported from https://github.com/component/has-cors
|
|
12987
|
+
let value = false;
|
|
12988
|
+
try {
|
|
12989
|
+
value = typeof XMLHttpRequest !== 'undefined' &&
|
|
12990
|
+
'withCredentials' in new XMLHttpRequest();
|
|
12991
|
+
}
|
|
12992
|
+
catch (err) {
|
|
12993
|
+
// if XMLHttp support is disabled in IE then it will throw
|
|
12994
|
+
// when trying to create
|
|
12995
|
+
}
|
|
12996
|
+
const hasCORS = value;
|
|
13159
12997
|
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
|
|
12998
|
+
// browser shim for xmlhttprequest module
|
|
12999
|
+
function XHR(opts) {
|
|
13000
|
+
const xdomain = opts.xdomain;
|
|
13001
|
+
// XMLHttpRequest can be disabled on IE
|
|
13002
|
+
try {
|
|
13003
|
+
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
|
|
13004
|
+
return new XMLHttpRequest();
|
|
13005
|
+
}
|
|
13006
|
+
}
|
|
13007
|
+
catch (e) { }
|
|
13008
|
+
if (!xdomain) {
|
|
13009
|
+
try {
|
|
13010
|
+
return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
13011
|
+
}
|
|
13012
|
+
catch (e) { }
|
|
13013
|
+
}
|
|
13014
|
+
}
|
|
13164
13015
|
|
|
13016
|
+
function empty() { }
|
|
13017
|
+
const hasXHR2 = (function () {
|
|
13018
|
+
const xhr = new XHR({
|
|
13019
|
+
xdomain: false,
|
|
13020
|
+
});
|
|
13021
|
+
return null != xhr.responseType;
|
|
13022
|
+
})();
|
|
13165
13023
|
class Polling extends Transport {
|
|
13166
|
-
constructor() {
|
|
13167
|
-
super(...arguments);
|
|
13168
|
-
this.polling = false;
|
|
13169
|
-
}
|
|
13170
13024
|
/**
|
|
13171
|
-
*
|
|
13025
|
+
* XHR Polling constructor.
|
|
13026
|
+
*
|
|
13027
|
+
* @param {Object} opts
|
|
13028
|
+
* @package
|
|
13172
13029
|
*/
|
|
13030
|
+
constructor(opts) {
|
|
13031
|
+
super(opts);
|
|
13032
|
+
this.polling = false;
|
|
13033
|
+
if (typeof location !== "undefined") {
|
|
13034
|
+
const isSSL = "https:" === location.protocol;
|
|
13035
|
+
let port = location.port;
|
|
13036
|
+
// some user agents have empty `location.port`
|
|
13037
|
+
if (!port) {
|
|
13038
|
+
port = isSSL ? "443" : "80";
|
|
13039
|
+
}
|
|
13040
|
+
this.xd =
|
|
13041
|
+
(typeof location !== "undefined" &&
|
|
13042
|
+
opts.hostname !== location.hostname) ||
|
|
13043
|
+
port !== opts.port;
|
|
13044
|
+
this.xs = opts.secure !== isSSL;
|
|
13045
|
+
}
|
|
13046
|
+
/**
|
|
13047
|
+
* XHR supports binary
|
|
13048
|
+
*/
|
|
13049
|
+
const forceBase64 = opts && opts.forceBase64;
|
|
13050
|
+
this.supportsBinary = hasXHR2 && !forceBase64;
|
|
13051
|
+
}
|
|
13173
13052
|
get name() {
|
|
13174
13053
|
return "polling";
|
|
13175
13054
|
}
|
|
@@ -13177,7 +13056,7 @@
|
|
|
13177
13056
|
* Opens the socket (triggers polling). We write a PING message to determine
|
|
13178
13057
|
* when the transport is open.
|
|
13179
13058
|
*
|
|
13180
|
-
* @
|
|
13059
|
+
* @protected
|
|
13181
13060
|
*/
|
|
13182
13061
|
doOpen() {
|
|
13183
13062
|
this.poll();
|
|
@@ -13185,8 +13064,8 @@
|
|
|
13185
13064
|
/**
|
|
13186
13065
|
* Pauses polling.
|
|
13187
13066
|
*
|
|
13188
|
-
* @param {Function} callback upon buffers are flushed and transport is paused
|
|
13189
|
-
* @
|
|
13067
|
+
* @param {Function} onPause - callback upon buffers are flushed and transport is paused
|
|
13068
|
+
* @package
|
|
13190
13069
|
*/
|
|
13191
13070
|
pause(onPause) {
|
|
13192
13071
|
this.readyState = "pausing";
|
|
@@ -13216,27 +13095,27 @@
|
|
|
13216
13095
|
/**
|
|
13217
13096
|
* Starts polling cycle.
|
|
13218
13097
|
*
|
|
13219
|
-
* @
|
|
13098
|
+
* @private
|
|
13220
13099
|
*/
|
|
13221
13100
|
poll() {
|
|
13222
13101
|
this.polling = true;
|
|
13223
13102
|
this.doPoll();
|
|
13224
|
-
this.
|
|
13103
|
+
this.emitReserved("poll");
|
|
13225
13104
|
}
|
|
13226
13105
|
/**
|
|
13227
13106
|
* Overloads onData to detect payloads.
|
|
13228
13107
|
*
|
|
13229
|
-
* @
|
|
13108
|
+
* @protected
|
|
13230
13109
|
*/
|
|
13231
13110
|
onData(data) {
|
|
13232
|
-
const callback = packet => {
|
|
13111
|
+
const callback = (packet) => {
|
|
13233
13112
|
// if its the first message we consider the transport open
|
|
13234
13113
|
if ("opening" === this.readyState && packet.type === "open") {
|
|
13235
13114
|
this.onOpen();
|
|
13236
13115
|
}
|
|
13237
13116
|
// if its a close packet, we close the ongoing requests
|
|
13238
13117
|
if ("close" === packet.type) {
|
|
13239
|
-
this.onClose();
|
|
13118
|
+
this.onClose({ description: "transport closed by the server" });
|
|
13240
13119
|
return false;
|
|
13241
13120
|
}
|
|
13242
13121
|
// otherwise bypass onData and handle the message
|
|
@@ -13248,7 +13127,7 @@
|
|
|
13248
13127
|
if ("closed" !== this.readyState) {
|
|
13249
13128
|
// if we got data we're not polling
|
|
13250
13129
|
this.polling = false;
|
|
13251
|
-
this.
|
|
13130
|
+
this.emitReserved("pollComplete");
|
|
13252
13131
|
if ("open" === this.readyState) {
|
|
13253
13132
|
this.poll();
|
|
13254
13133
|
}
|
|
@@ -13257,7 +13136,7 @@
|
|
|
13257
13136
|
/**
|
|
13258
13137
|
* For polling, send a close packet.
|
|
13259
13138
|
*
|
|
13260
|
-
* @
|
|
13139
|
+
* @protected
|
|
13261
13140
|
*/
|
|
13262
13141
|
doClose() {
|
|
13263
13142
|
const close = () => {
|
|
@@ -13275,23 +13154,22 @@
|
|
|
13275
13154
|
/**
|
|
13276
13155
|
* Writes a packets payload.
|
|
13277
13156
|
*
|
|
13278
|
-
* @param {Array} data packets
|
|
13279
|
-
* @
|
|
13280
|
-
* @api private
|
|
13157
|
+
* @param {Array} packets - data packets
|
|
13158
|
+
* @protected
|
|
13281
13159
|
*/
|
|
13282
13160
|
write(packets) {
|
|
13283
13161
|
this.writable = false;
|
|
13284
|
-
encodePayload(packets, data => {
|
|
13162
|
+
encodePayload(packets, (data) => {
|
|
13285
13163
|
this.doWrite(data, () => {
|
|
13286
13164
|
this.writable = true;
|
|
13287
|
-
this.
|
|
13165
|
+
this.emitReserved("drain");
|
|
13288
13166
|
});
|
|
13289
13167
|
});
|
|
13290
13168
|
}
|
|
13291
13169
|
/**
|
|
13292
13170
|
* Generates uri for connection.
|
|
13293
13171
|
*
|
|
13294
|
-
* @
|
|
13172
|
+
* @private
|
|
13295
13173
|
*/
|
|
13296
13174
|
uri() {
|
|
13297
13175
|
let query = this.query || {};
|
|
@@ -13299,7 +13177,7 @@
|
|
|
13299
13177
|
let port = "";
|
|
13300
13178
|
// cache busting is forced
|
|
13301
13179
|
if (false !== this.opts.timestampRequests) {
|
|
13302
|
-
query[this.opts.timestampParam] =
|
|
13180
|
+
query[this.opts.timestampParam] = yeast();
|
|
13303
13181
|
}
|
|
13304
13182
|
if (!this.supportsBinary && !query.sid) {
|
|
13305
13183
|
query.b64 = 1;
|
|
@@ -13310,7 +13188,7 @@
|
|
|
13310
13188
|
("http" === schema && Number(this.opts.port) !== 80))) {
|
|
13311
13189
|
port = ":" + this.opts.port;
|
|
13312
13190
|
}
|
|
13313
|
-
const encodedQuery =
|
|
13191
|
+
const encodedQuery = encode(query);
|
|
13314
13192
|
const ipv6 = this.opts.hostname.indexOf(":") !== -1;
|
|
13315
13193
|
return (schema +
|
|
13316
13194
|
"://" +
|
|
@@ -13319,52 +13197,11 @@
|
|
|
13319
13197
|
this.opts.path +
|
|
13320
13198
|
(encodedQuery.length ? "?" + encodedQuery : ""));
|
|
13321
13199
|
}
|
|
13322
|
-
}
|
|
13323
|
-
|
|
13324
|
-
/* global attachEvent */
|
|
13325
|
-
/**
|
|
13326
|
-
* Empty function
|
|
13327
|
-
*/
|
|
13328
|
-
function empty() { }
|
|
13329
|
-
const hasXHR2 = (function () {
|
|
13330
|
-
const xhr = new XMLHttpRequest$1({
|
|
13331
|
-
xdomain: false
|
|
13332
|
-
});
|
|
13333
|
-
return null != xhr.responseType;
|
|
13334
|
-
})();
|
|
13335
|
-
class XHR extends Polling {
|
|
13336
|
-
/**
|
|
13337
|
-
* XHR Polling constructor.
|
|
13338
|
-
*
|
|
13339
|
-
* @param {Object} opts
|
|
13340
|
-
* @api public
|
|
13341
|
-
*/
|
|
13342
|
-
constructor(opts) {
|
|
13343
|
-
super(opts);
|
|
13344
|
-
if (typeof location !== "undefined") {
|
|
13345
|
-
const isSSL = "https:" === location.protocol;
|
|
13346
|
-
let port = location.port;
|
|
13347
|
-
// some user agents have empty `location.port`
|
|
13348
|
-
if (!port) {
|
|
13349
|
-
port = isSSL ? "443" : "80";
|
|
13350
|
-
}
|
|
13351
|
-
this.xd =
|
|
13352
|
-
(typeof location !== "undefined" &&
|
|
13353
|
-
opts.hostname !== location.hostname) ||
|
|
13354
|
-
port !== opts.port;
|
|
13355
|
-
this.xs = opts.secure !== isSSL;
|
|
13356
|
-
}
|
|
13357
|
-
/**
|
|
13358
|
-
* XHR supports binary
|
|
13359
|
-
*/
|
|
13360
|
-
const forceBase64 = opts && opts.forceBase64;
|
|
13361
|
-
this.supportsBinary = hasXHR2 && !forceBase64;
|
|
13362
|
-
}
|
|
13363
13200
|
/**
|
|
13364
13201
|
* Creates a request.
|
|
13365
13202
|
*
|
|
13366
13203
|
* @param {String} method
|
|
13367
|
-
* @
|
|
13204
|
+
* @private
|
|
13368
13205
|
*/
|
|
13369
13206
|
request(opts = {}) {
|
|
13370
13207
|
Object.assign(opts, { xd: this.xd, xs: this.xs }, this.opts);
|
|
@@ -13375,38 +13212,38 @@
|
|
|
13375
13212
|
*
|
|
13376
13213
|
* @param {String} data to send.
|
|
13377
13214
|
* @param {Function} called upon flush.
|
|
13378
|
-
* @
|
|
13215
|
+
* @private
|
|
13379
13216
|
*/
|
|
13380
13217
|
doWrite(data, fn) {
|
|
13381
13218
|
const req = this.request({
|
|
13382
13219
|
method: "POST",
|
|
13383
|
-
data: data
|
|
13220
|
+
data: data,
|
|
13384
13221
|
});
|
|
13385
13222
|
req.on("success", fn);
|
|
13386
|
-
req.on("error",
|
|
13387
|
-
this.onError("xhr post error",
|
|
13223
|
+
req.on("error", (xhrStatus, context) => {
|
|
13224
|
+
this.onError("xhr post error", xhrStatus, context);
|
|
13388
13225
|
});
|
|
13389
13226
|
}
|
|
13390
13227
|
/**
|
|
13391
13228
|
* Starts a poll cycle.
|
|
13392
13229
|
*
|
|
13393
|
-
* @
|
|
13230
|
+
* @private
|
|
13394
13231
|
*/
|
|
13395
13232
|
doPoll() {
|
|
13396
13233
|
const req = this.request();
|
|
13397
13234
|
req.on("data", this.onData.bind(this));
|
|
13398
|
-
req.on("error",
|
|
13399
|
-
this.onError("xhr poll error",
|
|
13235
|
+
req.on("error", (xhrStatus, context) => {
|
|
13236
|
+
this.onError("xhr poll error", xhrStatus, context);
|
|
13400
13237
|
});
|
|
13401
13238
|
this.pollXhr = req;
|
|
13402
13239
|
}
|
|
13403
13240
|
}
|
|
13404
|
-
class Request extends
|
|
13241
|
+
class Request extends Emitter {
|
|
13405
13242
|
/**
|
|
13406
13243
|
* Request constructor
|
|
13407
13244
|
*
|
|
13408
13245
|
* @param {Object} options
|
|
13409
|
-
* @
|
|
13246
|
+
* @package
|
|
13410
13247
|
*/
|
|
13411
13248
|
constructor(uri, opts) {
|
|
13412
13249
|
super();
|
|
@@ -13421,13 +13258,13 @@
|
|
|
13421
13258
|
/**
|
|
13422
13259
|
* Creates the XHR object and sends the request.
|
|
13423
13260
|
*
|
|
13424
|
-
* @
|
|
13261
|
+
* @private
|
|
13425
13262
|
*/
|
|
13426
13263
|
create() {
|
|
13427
13264
|
const opts = pick(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
13428
13265
|
opts.xdomain = !!this.opts.xd;
|
|
13429
13266
|
opts.xscheme = !!this.opts.xs;
|
|
13430
|
-
const xhr = (this.xhr = new
|
|
13267
|
+
const xhr = (this.xhr = new XHR(opts));
|
|
13431
13268
|
try {
|
|
13432
13269
|
xhr.open(this.method, this.uri, this.async);
|
|
13433
13270
|
try {
|
|
@@ -13488,37 +13325,19 @@
|
|
|
13488
13325
|
Request.requests[this.index] = this;
|
|
13489
13326
|
}
|
|
13490
13327
|
}
|
|
13491
|
-
/**
|
|
13492
|
-
* Called upon successful response.
|
|
13493
|
-
*
|
|
13494
|
-
* @api private
|
|
13495
|
-
*/
|
|
13496
|
-
onSuccess() {
|
|
13497
|
-
this.emit("success");
|
|
13498
|
-
this.cleanup();
|
|
13499
|
-
}
|
|
13500
|
-
/**
|
|
13501
|
-
* Called if we have data.
|
|
13502
|
-
*
|
|
13503
|
-
* @api private
|
|
13504
|
-
*/
|
|
13505
|
-
onData(data) {
|
|
13506
|
-
this.emit("data", data);
|
|
13507
|
-
this.onSuccess();
|
|
13508
|
-
}
|
|
13509
13328
|
/**
|
|
13510
13329
|
* Called upon error.
|
|
13511
13330
|
*
|
|
13512
|
-
* @
|
|
13331
|
+
* @private
|
|
13513
13332
|
*/
|
|
13514
13333
|
onError(err) {
|
|
13515
|
-
this.
|
|
13334
|
+
this.emitReserved("error", err, this.xhr);
|
|
13516
13335
|
this.cleanup(true);
|
|
13517
13336
|
}
|
|
13518
13337
|
/**
|
|
13519
13338
|
* Cleans up house.
|
|
13520
13339
|
*
|
|
13521
|
-
* @
|
|
13340
|
+
* @private
|
|
13522
13341
|
*/
|
|
13523
13342
|
cleanup(fromError) {
|
|
13524
13343
|
if ("undefined" === typeof this.xhr || null === this.xhr) {
|
|
@@ -13539,18 +13358,20 @@
|
|
|
13539
13358
|
/**
|
|
13540
13359
|
* Called upon load.
|
|
13541
13360
|
*
|
|
13542
|
-
* @
|
|
13361
|
+
* @private
|
|
13543
13362
|
*/
|
|
13544
13363
|
onLoad() {
|
|
13545
13364
|
const data = this.xhr.responseText;
|
|
13546
13365
|
if (data !== null) {
|
|
13547
|
-
this.
|
|
13366
|
+
this.emitReserved("data", data);
|
|
13367
|
+
this.emitReserved("success");
|
|
13368
|
+
this.cleanup();
|
|
13548
13369
|
}
|
|
13549
13370
|
}
|
|
13550
13371
|
/**
|
|
13551
13372
|
* Aborts the request.
|
|
13552
13373
|
*
|
|
13553
|
-
* @
|
|
13374
|
+
* @package
|
|
13554
13375
|
*/
|
|
13555
13376
|
abort() {
|
|
13556
13377
|
this.cleanup();
|
|
@@ -13570,7 +13391,7 @@
|
|
|
13570
13391
|
attachEvent("onunload", unloadHandler);
|
|
13571
13392
|
}
|
|
13572
13393
|
else if (typeof addEventListener === "function") {
|
|
13573
|
-
const terminationEvent = "onpagehide" in
|
|
13394
|
+
const terminationEvent = "onpagehide" in globalThisShim ? "pagehide" : "unload";
|
|
13574
13395
|
addEventListener(terminationEvent, unloadHandler, false);
|
|
13575
13396
|
}
|
|
13576
13397
|
}
|
|
@@ -13585,13 +13406,13 @@
|
|
|
13585
13406
|
const nextTick = (() => {
|
|
13586
13407
|
const isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
|
|
13587
13408
|
if (isPromiseAvailable) {
|
|
13588
|
-
return cb => Promise.resolve().then(cb);
|
|
13409
|
+
return (cb) => Promise.resolve().then(cb);
|
|
13589
13410
|
}
|
|
13590
13411
|
else {
|
|
13591
13412
|
return (cb, setTimeoutFn) => setTimeoutFn(cb, 0);
|
|
13592
13413
|
}
|
|
13593
13414
|
})();
|
|
13594
|
-
const WebSocket$1 =
|
|
13415
|
+
const WebSocket$1 = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
|
|
13595
13416
|
const usingBrowserWebSocket = true;
|
|
13596
13417
|
const defaultBinaryType = "arraybuffer";
|
|
13597
13418
|
|
|
@@ -13603,26 +13424,16 @@
|
|
|
13603
13424
|
/**
|
|
13604
13425
|
* WebSocket transport constructor.
|
|
13605
13426
|
*
|
|
13606
|
-
* @
|
|
13607
|
-
* @
|
|
13427
|
+
* @param {Object} opts - connection options
|
|
13428
|
+
* @protected
|
|
13608
13429
|
*/
|
|
13609
13430
|
constructor(opts) {
|
|
13610
13431
|
super(opts);
|
|
13611
13432
|
this.supportsBinary = !opts.forceBase64;
|
|
13612
13433
|
}
|
|
13613
|
-
/**
|
|
13614
|
-
* Transport name.
|
|
13615
|
-
*
|
|
13616
|
-
* @api public
|
|
13617
|
-
*/
|
|
13618
13434
|
get name() {
|
|
13619
13435
|
return "websocket";
|
|
13620
13436
|
}
|
|
13621
|
-
/**
|
|
13622
|
-
* Opens socket.
|
|
13623
|
-
*
|
|
13624
|
-
* @api private
|
|
13625
|
-
*/
|
|
13626
13437
|
doOpen() {
|
|
13627
13438
|
if (!this.check()) {
|
|
13628
13439
|
// let probe timeout
|
|
@@ -13646,7 +13457,7 @@
|
|
|
13646
13457
|
: new WebSocket$1(uri, protocols, opts);
|
|
13647
13458
|
}
|
|
13648
13459
|
catch (err) {
|
|
13649
|
-
return this.
|
|
13460
|
+
return this.emitReserved("error", err);
|
|
13650
13461
|
}
|
|
13651
13462
|
this.ws.binaryType = this.socket.binaryType || defaultBinaryType;
|
|
13652
13463
|
this.addEventListeners();
|
|
@@ -13654,7 +13465,7 @@
|
|
|
13654
13465
|
/**
|
|
13655
13466
|
* Adds event listeners to the socket
|
|
13656
13467
|
*
|
|
13657
|
-
* @
|
|
13468
|
+
* @private
|
|
13658
13469
|
*/
|
|
13659
13470
|
addEventListeners() {
|
|
13660
13471
|
this.ws.onopen = () => {
|
|
@@ -13663,16 +13474,13 @@
|
|
|
13663
13474
|
}
|
|
13664
13475
|
this.onOpen();
|
|
13665
13476
|
};
|
|
13666
|
-
this.ws.onclose = this.onClose
|
|
13667
|
-
|
|
13668
|
-
|
|
13477
|
+
this.ws.onclose = (closeEvent) => this.onClose({
|
|
13478
|
+
description: "websocket connection closed",
|
|
13479
|
+
context: closeEvent,
|
|
13480
|
+
});
|
|
13481
|
+
this.ws.onmessage = (ev) => this.onData(ev.data);
|
|
13482
|
+
this.ws.onerror = (e) => this.onError("websocket error", e);
|
|
13669
13483
|
}
|
|
13670
|
-
/**
|
|
13671
|
-
* Writes data to socket.
|
|
13672
|
-
*
|
|
13673
|
-
* @param {Array} array of packets.
|
|
13674
|
-
* @api private
|
|
13675
|
-
*/
|
|
13676
13484
|
write(packets) {
|
|
13677
13485
|
this.writable = false;
|
|
13678
13486
|
// encodePacket efficient as it uses WS framing
|
|
@@ -13680,7 +13488,7 @@
|
|
|
13680
13488
|
for (let i = 0; i < packets.length; i++) {
|
|
13681
13489
|
const packet = packets[i];
|
|
13682
13490
|
const lastPacket = i === packets.length - 1;
|
|
13683
|
-
encodePacket(packet, this.supportsBinary, data => {
|
|
13491
|
+
encodePacket(packet, this.supportsBinary, (data) => {
|
|
13684
13492
|
// always create a new object (GH-437)
|
|
13685
13493
|
const opts = {};
|
|
13686
13494
|
// Sometimes the websocket has already been closed but the browser didn't
|
|
@@ -13699,17 +13507,12 @@
|
|
|
13699
13507
|
// defer to next tick to allow Socket to clear writeBuffer
|
|
13700
13508
|
nextTick(() => {
|
|
13701
13509
|
this.writable = true;
|
|
13702
|
-
this.
|
|
13510
|
+
this.emitReserved("drain");
|
|
13703
13511
|
}, this.setTimeoutFn);
|
|
13704
13512
|
}
|
|
13705
13513
|
});
|
|
13706
13514
|
}
|
|
13707
13515
|
}
|
|
13708
|
-
/**
|
|
13709
|
-
* Closes socket.
|
|
13710
|
-
*
|
|
13711
|
-
* @api private
|
|
13712
|
-
*/
|
|
13713
13516
|
doClose() {
|
|
13714
13517
|
if (typeof this.ws !== "undefined") {
|
|
13715
13518
|
this.ws.close();
|
|
@@ -13719,7 +13522,7 @@
|
|
|
13719
13522
|
/**
|
|
13720
13523
|
* Generates uri for connection.
|
|
13721
13524
|
*
|
|
13722
|
-
* @
|
|
13525
|
+
* @private
|
|
13723
13526
|
*/
|
|
13724
13527
|
uri() {
|
|
13725
13528
|
let query = this.query || {};
|
|
@@ -13733,13 +13536,13 @@
|
|
|
13733
13536
|
}
|
|
13734
13537
|
// append timestamp to URI
|
|
13735
13538
|
if (this.opts.timestampRequests) {
|
|
13736
|
-
query[this.opts.timestampParam] =
|
|
13539
|
+
query[this.opts.timestampParam] = yeast();
|
|
13737
13540
|
}
|
|
13738
13541
|
// communicate binary support capabilities
|
|
13739
13542
|
if (!this.supportsBinary) {
|
|
13740
13543
|
query.b64 = 1;
|
|
13741
13544
|
}
|
|
13742
|
-
const encodedQuery =
|
|
13545
|
+
const encodedQuery = encode(query);
|
|
13743
13546
|
const ipv6 = this.opts.hostname.indexOf(":") !== -1;
|
|
13744
13547
|
return (schema +
|
|
13745
13548
|
"://" +
|
|
@@ -13752,35 +13555,96 @@
|
|
|
13752
13555
|
* Feature detection for WebSocket.
|
|
13753
13556
|
*
|
|
13754
13557
|
* @return {Boolean} whether this transport is available.
|
|
13755
|
-
* @
|
|
13558
|
+
* @private
|
|
13756
13559
|
*/
|
|
13757
13560
|
check() {
|
|
13758
|
-
return
|
|
13759
|
-
!("__initialize" in WebSocket$1 && this.name === WS.prototype.name));
|
|
13561
|
+
return !!WebSocket$1;
|
|
13760
13562
|
}
|
|
13761
13563
|
}
|
|
13762
13564
|
|
|
13763
13565
|
const transports = {
|
|
13764
13566
|
websocket: WS,
|
|
13765
|
-
polling:
|
|
13567
|
+
polling: Polling,
|
|
13766
13568
|
};
|
|
13767
13569
|
|
|
13768
|
-
|
|
13570
|
+
// imported from https://github.com/galkn/parseuri
|
|
13571
|
+
/**
|
|
13572
|
+
* Parses a URI
|
|
13573
|
+
*
|
|
13574
|
+
* Note: we could also have used the built-in URL object, but it isn't supported on all platforms.
|
|
13575
|
+
*
|
|
13576
|
+
* See:
|
|
13577
|
+
* - https://developer.mozilla.org/en-US/docs/Web/API/URL
|
|
13578
|
+
* - https://caniuse.com/url
|
|
13579
|
+
* - https://www.rfc-editor.org/rfc/rfc3986#appendix-B
|
|
13580
|
+
*
|
|
13581
|
+
* History of the parse() method:
|
|
13582
|
+
* - first commit: https://github.com/socketio/socket.io-client/commit/4ee1d5d94b3906a9c052b459f1a818b15f38f91c
|
|
13583
|
+
* - export into its own module: https://github.com/socketio/engine.io-client/commit/de2c561e4564efeb78f1bdb1ba39ef81b2822cb3
|
|
13584
|
+
* - reimport: https://github.com/socketio/engine.io-client/commit/df32277c3f6d622eec5ed09f493cae3f3391d242
|
|
13585
|
+
*
|
|
13586
|
+
* @author Steven Levithan <stevenlevithan.com> (MIT license)
|
|
13587
|
+
* @api private
|
|
13588
|
+
*/
|
|
13589
|
+
const re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
|
13590
|
+
const parts = [
|
|
13591
|
+
'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
|
|
13592
|
+
];
|
|
13593
|
+
function parse(str) {
|
|
13594
|
+
const src = str, b = str.indexOf('['), e = str.indexOf(']');
|
|
13595
|
+
if (b != -1 && e != -1) {
|
|
13596
|
+
str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
|
|
13597
|
+
}
|
|
13598
|
+
let m = re.exec(str || ''), uri = {}, i = 14;
|
|
13599
|
+
while (i--) {
|
|
13600
|
+
uri[parts[i]] = m[i] || '';
|
|
13601
|
+
}
|
|
13602
|
+
if (b != -1 && e != -1) {
|
|
13603
|
+
uri.source = src;
|
|
13604
|
+
uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
|
|
13605
|
+
uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
|
|
13606
|
+
uri.ipv6uri = true;
|
|
13607
|
+
}
|
|
13608
|
+
uri.pathNames = pathNames(uri, uri['path']);
|
|
13609
|
+
uri.queryKey = queryKey(uri, uri['query']);
|
|
13610
|
+
return uri;
|
|
13611
|
+
}
|
|
13612
|
+
function pathNames(obj, path) {
|
|
13613
|
+
const regx = /\/{2,9}/g, names = path.replace(regx, "/").split("/");
|
|
13614
|
+
if (path.slice(0, 1) == '/' || path.length === 0) {
|
|
13615
|
+
names.splice(0, 1);
|
|
13616
|
+
}
|
|
13617
|
+
if (path.slice(-1) == '/') {
|
|
13618
|
+
names.splice(names.length - 1, 1);
|
|
13619
|
+
}
|
|
13620
|
+
return names;
|
|
13621
|
+
}
|
|
13622
|
+
function queryKey(uri, query) {
|
|
13623
|
+
const data = {};
|
|
13624
|
+
query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
|
|
13625
|
+
if ($1) {
|
|
13626
|
+
data[$1] = $2;
|
|
13627
|
+
}
|
|
13628
|
+
});
|
|
13629
|
+
return data;
|
|
13630
|
+
}
|
|
13631
|
+
|
|
13632
|
+
class Socket$1 extends Emitter {
|
|
13769
13633
|
/**
|
|
13770
13634
|
* Socket constructor.
|
|
13771
13635
|
*
|
|
13772
|
-
* @param {String|Object} uri or options
|
|
13636
|
+
* @param {String|Object} uri - uri or options
|
|
13773
13637
|
* @param {Object} opts - options
|
|
13774
|
-
* @api public
|
|
13775
13638
|
*/
|
|
13776
13639
|
constructor(uri, opts = {}) {
|
|
13777
13640
|
super();
|
|
13641
|
+
this.writeBuffer = [];
|
|
13778
13642
|
if (uri && "object" === typeof uri) {
|
|
13779
13643
|
opts = uri;
|
|
13780
13644
|
uri = null;
|
|
13781
13645
|
}
|
|
13782
13646
|
if (uri) {
|
|
13783
|
-
uri =
|
|
13647
|
+
uri = parse(uri);
|
|
13784
13648
|
opts.hostname = uri.host;
|
|
13785
13649
|
opts.secure = uri.protocol === "https" || uri.protocol === "wss";
|
|
13786
13650
|
opts.port = uri.port;
|
|
@@ -13788,7 +13652,7 @@
|
|
|
13788
13652
|
opts.query = uri.query;
|
|
13789
13653
|
}
|
|
13790
13654
|
else if (opts.host) {
|
|
13791
|
-
opts.hostname =
|
|
13655
|
+
opts.hostname = parse(opts.host).host;
|
|
13792
13656
|
}
|
|
13793
13657
|
installTimerFunctions(this, opts);
|
|
13794
13658
|
this.secure =
|
|
@@ -13810,7 +13674,6 @@
|
|
|
13810
13674
|
? "443"
|
|
13811
13675
|
: "80");
|
|
13812
13676
|
this.transports = opts.transports || ["polling", "websocket"];
|
|
13813
|
-
this.readyState = "";
|
|
13814
13677
|
this.writeBuffer = [];
|
|
13815
13678
|
this.prevBufferLen = 0;
|
|
13816
13679
|
this.opts = Object.assign({
|
|
@@ -13820,16 +13683,19 @@
|
|
|
13820
13683
|
upgrade: true,
|
|
13821
13684
|
timestampParam: "t",
|
|
13822
13685
|
rememberUpgrade: false,
|
|
13686
|
+
addTrailingSlash: true,
|
|
13823
13687
|
rejectUnauthorized: true,
|
|
13824
13688
|
perMessageDeflate: {
|
|
13825
|
-
threshold: 1024
|
|
13689
|
+
threshold: 1024,
|
|
13826
13690
|
},
|
|
13827
13691
|
transportOptions: {},
|
|
13828
|
-
closeOnBeforeunload: true
|
|
13692
|
+
closeOnBeforeunload: true,
|
|
13829
13693
|
}, opts);
|
|
13830
|
-
this.opts.path =
|
|
13694
|
+
this.opts.path =
|
|
13695
|
+
this.opts.path.replace(/\/$/, "") +
|
|
13696
|
+
(this.opts.addTrailingSlash ? "/" : "");
|
|
13831
13697
|
if (typeof this.opts.query === "string") {
|
|
13832
|
-
this.opts.query =
|
|
13698
|
+
this.opts.query = decode(this.opts.query);
|
|
13833
13699
|
}
|
|
13834
13700
|
// set on handshake
|
|
13835
13701
|
this.id = null;
|
|
@@ -13843,17 +13709,20 @@
|
|
|
13843
13709
|
// Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
|
|
13844
13710
|
// ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
|
|
13845
13711
|
// closed/reloaded)
|
|
13846
|
-
|
|
13712
|
+
this.beforeunloadEventListener = () => {
|
|
13847
13713
|
if (this.transport) {
|
|
13848
13714
|
// silently close the transport
|
|
13849
13715
|
this.transport.removeAllListeners();
|
|
13850
13716
|
this.transport.close();
|
|
13851
13717
|
}
|
|
13852
|
-
}
|
|
13718
|
+
};
|
|
13719
|
+
addEventListener("beforeunload", this.beforeunloadEventListener, false);
|
|
13853
13720
|
}
|
|
13854
13721
|
if (this.hostname !== "localhost") {
|
|
13855
13722
|
this.offlineEventListener = () => {
|
|
13856
|
-
this.onClose("transport close"
|
|
13723
|
+
this.onClose("transport close", {
|
|
13724
|
+
description: "network connection lost",
|
|
13725
|
+
});
|
|
13857
13726
|
};
|
|
13858
13727
|
addEventListener("offline", this.offlineEventListener, false);
|
|
13859
13728
|
}
|
|
@@ -13863,12 +13732,12 @@
|
|
|
13863
13732
|
/**
|
|
13864
13733
|
* Creates transport of the given type.
|
|
13865
13734
|
*
|
|
13866
|
-
* @param {String} transport name
|
|
13735
|
+
* @param {String} name - transport name
|
|
13867
13736
|
* @return {Transport}
|
|
13868
|
-
* @
|
|
13737
|
+
* @private
|
|
13869
13738
|
*/
|
|
13870
13739
|
createTransport(name) {
|
|
13871
|
-
const query =
|
|
13740
|
+
const query = Object.assign({}, this.opts.query);
|
|
13872
13741
|
// append engine.io protocol identifier
|
|
13873
13742
|
query.EIO = protocol$1;
|
|
13874
13743
|
// transport name
|
|
@@ -13881,14 +13750,14 @@
|
|
|
13881
13750
|
socket: this,
|
|
13882
13751
|
hostname: this.hostname,
|
|
13883
13752
|
secure: this.secure,
|
|
13884
|
-
port: this.port
|
|
13753
|
+
port: this.port,
|
|
13885
13754
|
});
|
|
13886
13755
|
return new transports[name](opts);
|
|
13887
13756
|
}
|
|
13888
13757
|
/**
|
|
13889
13758
|
* Initializes transport to use and starts probe.
|
|
13890
13759
|
*
|
|
13891
|
-
* @
|
|
13760
|
+
* @private
|
|
13892
13761
|
*/
|
|
13893
13762
|
open() {
|
|
13894
13763
|
let transport;
|
|
@@ -13923,7 +13792,7 @@
|
|
|
13923
13792
|
/**
|
|
13924
13793
|
* Sets the current transport. Disables the existing one (if any).
|
|
13925
13794
|
*
|
|
13926
|
-
* @
|
|
13795
|
+
* @private
|
|
13927
13796
|
*/
|
|
13928
13797
|
setTransport(transport) {
|
|
13929
13798
|
if (this.transport) {
|
|
@@ -13936,15 +13805,13 @@
|
|
|
13936
13805
|
.on("drain", this.onDrain.bind(this))
|
|
13937
13806
|
.on("packet", this.onPacket.bind(this))
|
|
13938
13807
|
.on("error", this.onError.bind(this))
|
|
13939
|
-
.on("close", () =>
|
|
13940
|
-
this.onClose("transport close");
|
|
13941
|
-
});
|
|
13808
|
+
.on("close", (reason) => this.onClose("transport close", reason));
|
|
13942
13809
|
}
|
|
13943
13810
|
/**
|
|
13944
13811
|
* Probes a transport.
|
|
13945
13812
|
*
|
|
13946
|
-
* @param {String} transport name
|
|
13947
|
-
* @
|
|
13813
|
+
* @param {String} name - transport name
|
|
13814
|
+
* @private
|
|
13948
13815
|
*/
|
|
13949
13816
|
probe(name) {
|
|
13950
13817
|
let transport = this.createTransport(name);
|
|
@@ -13954,7 +13821,7 @@
|
|
|
13954
13821
|
if (failed)
|
|
13955
13822
|
return;
|
|
13956
13823
|
transport.send([{ type: "ping", data: "probe" }]);
|
|
13957
|
-
transport.once("packet", msg => {
|
|
13824
|
+
transport.once("packet", (msg) => {
|
|
13958
13825
|
if (failed)
|
|
13959
13826
|
return;
|
|
13960
13827
|
if ("pong" === msg.type && "probe" === msg.data) {
|
|
@@ -13995,7 +13862,7 @@
|
|
|
13995
13862
|
transport = null;
|
|
13996
13863
|
}
|
|
13997
13864
|
// Handle any error that happens while probing
|
|
13998
|
-
const onerror = err => {
|
|
13865
|
+
const onerror = (err) => {
|
|
13999
13866
|
const error = new Error("probe error: " + err);
|
|
14000
13867
|
// @ts-ignore
|
|
14001
13868
|
error.transport = transport.name;
|
|
@@ -14033,7 +13900,7 @@
|
|
|
14033
13900
|
/**
|
|
14034
13901
|
* Called when connection is deemed open.
|
|
14035
13902
|
*
|
|
14036
|
-
* @
|
|
13903
|
+
* @private
|
|
14037
13904
|
*/
|
|
14038
13905
|
onOpen() {
|
|
14039
13906
|
this.readyState = "open";
|
|
@@ -14042,9 +13909,7 @@
|
|
|
14042
13909
|
this.flush();
|
|
14043
13910
|
// we check for `readyState` in case an `open`
|
|
14044
13911
|
// listener already closed the socket
|
|
14045
|
-
if ("open" === this.readyState &&
|
|
14046
|
-
this.opts.upgrade &&
|
|
14047
|
-
this.transport.pause) {
|
|
13912
|
+
if ("open" === this.readyState && this.opts.upgrade) {
|
|
14048
13913
|
let i = 0;
|
|
14049
13914
|
const l = this.upgrades.length;
|
|
14050
13915
|
for (; i < l; i++) {
|
|
@@ -14055,7 +13920,7 @@
|
|
|
14055
13920
|
/**
|
|
14056
13921
|
* Handles a packet.
|
|
14057
13922
|
*
|
|
14058
|
-
* @
|
|
13923
|
+
* @private
|
|
14059
13924
|
*/
|
|
14060
13925
|
onPacket(packet) {
|
|
14061
13926
|
if ("opening" === this.readyState ||
|
|
@@ -14091,7 +13956,7 @@
|
|
|
14091
13956
|
* Called upon handshake completion.
|
|
14092
13957
|
*
|
|
14093
13958
|
* @param {Object} data - handshake obj
|
|
14094
|
-
* @
|
|
13959
|
+
* @private
|
|
14095
13960
|
*/
|
|
14096
13961
|
onHandshake(data) {
|
|
14097
13962
|
this.emitReserved("handshake", data);
|
|
@@ -14100,6 +13965,7 @@
|
|
|
14100
13965
|
this.upgrades = this.filterUpgrades(data.upgrades);
|
|
14101
13966
|
this.pingInterval = data.pingInterval;
|
|
14102
13967
|
this.pingTimeout = data.pingTimeout;
|
|
13968
|
+
this.maxPayload = data.maxPayload;
|
|
14103
13969
|
this.onOpen();
|
|
14104
13970
|
// In case open handler closes socket
|
|
14105
13971
|
if ("closed" === this.readyState)
|
|
@@ -14109,7 +13975,7 @@
|
|
|
14109
13975
|
/**
|
|
14110
13976
|
* Sets and resets ping timeout timer based on server pings.
|
|
14111
13977
|
*
|
|
14112
|
-
* @
|
|
13978
|
+
* @private
|
|
14113
13979
|
*/
|
|
14114
13980
|
resetPingTimeout() {
|
|
14115
13981
|
this.clearTimeoutFn(this.pingTimeoutTimer);
|
|
@@ -14123,7 +13989,7 @@
|
|
|
14123
13989
|
/**
|
|
14124
13990
|
* Called on `drain` event
|
|
14125
13991
|
*
|
|
14126
|
-
* @
|
|
13992
|
+
* @private
|
|
14127
13993
|
*/
|
|
14128
13994
|
onDrain() {
|
|
14129
13995
|
this.writeBuffer.splice(0, this.prevBufferLen);
|
|
@@ -14141,28 +14007,54 @@
|
|
|
14141
14007
|
/**
|
|
14142
14008
|
* Flush write buffers.
|
|
14143
14009
|
*
|
|
14144
|
-
* @
|
|
14010
|
+
* @private
|
|
14145
14011
|
*/
|
|
14146
14012
|
flush() {
|
|
14147
14013
|
if ("closed" !== this.readyState &&
|
|
14148
14014
|
this.transport.writable &&
|
|
14149
14015
|
!this.upgrading &&
|
|
14150
14016
|
this.writeBuffer.length) {
|
|
14151
|
-
this.
|
|
14017
|
+
const packets = this.getWritablePackets();
|
|
14018
|
+
this.transport.send(packets);
|
|
14152
14019
|
// keep track of current length of writeBuffer
|
|
14153
14020
|
// splice writeBuffer and callbackBuffer on `drain`
|
|
14154
|
-
this.prevBufferLen =
|
|
14021
|
+
this.prevBufferLen = packets.length;
|
|
14155
14022
|
this.emitReserved("flush");
|
|
14156
14023
|
}
|
|
14157
14024
|
}
|
|
14025
|
+
/**
|
|
14026
|
+
* Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
|
|
14027
|
+
* long-polling)
|
|
14028
|
+
*
|
|
14029
|
+
* @private
|
|
14030
|
+
*/
|
|
14031
|
+
getWritablePackets() {
|
|
14032
|
+
const shouldCheckPayloadSize = this.maxPayload &&
|
|
14033
|
+
this.transport.name === "polling" &&
|
|
14034
|
+
this.writeBuffer.length > 1;
|
|
14035
|
+
if (!shouldCheckPayloadSize) {
|
|
14036
|
+
return this.writeBuffer;
|
|
14037
|
+
}
|
|
14038
|
+
let payloadSize = 1; // first packet type
|
|
14039
|
+
for (let i = 0; i < this.writeBuffer.length; i++) {
|
|
14040
|
+
const data = this.writeBuffer[i].data;
|
|
14041
|
+
if (data) {
|
|
14042
|
+
payloadSize += byteLength(data);
|
|
14043
|
+
}
|
|
14044
|
+
if (i > 0 && payloadSize > this.maxPayload) {
|
|
14045
|
+
return this.writeBuffer.slice(0, i);
|
|
14046
|
+
}
|
|
14047
|
+
payloadSize += 2; // separator + packet type
|
|
14048
|
+
}
|
|
14049
|
+
return this.writeBuffer;
|
|
14050
|
+
}
|
|
14158
14051
|
/**
|
|
14159
14052
|
* Sends a message.
|
|
14160
14053
|
*
|
|
14161
|
-
* @param {String} message.
|
|
14162
|
-
* @param {Function} callback function.
|
|
14054
|
+
* @param {String} msg - message.
|
|
14163
14055
|
* @param {Object} options.
|
|
14056
|
+
* @param {Function} callback function.
|
|
14164
14057
|
* @return {Socket} for chaining.
|
|
14165
|
-
* @api public
|
|
14166
14058
|
*/
|
|
14167
14059
|
write(msg, options, fn) {
|
|
14168
14060
|
this.sendPacket("message", msg, options, fn);
|
|
@@ -14175,11 +14067,11 @@
|
|
|
14175
14067
|
/**
|
|
14176
14068
|
* Sends a packet.
|
|
14177
14069
|
*
|
|
14178
|
-
* @param {String} packet type.
|
|
14070
|
+
* @param {String} type: packet type.
|
|
14179
14071
|
* @param {String} data.
|
|
14180
14072
|
* @param {Object} options.
|
|
14181
|
-
* @param {Function} callback function.
|
|
14182
|
-
* @
|
|
14073
|
+
* @param {Function} fn - callback function.
|
|
14074
|
+
* @private
|
|
14183
14075
|
*/
|
|
14184
14076
|
sendPacket(type, data, options, fn) {
|
|
14185
14077
|
if ("function" === typeof data) {
|
|
@@ -14198,7 +14090,7 @@
|
|
|
14198
14090
|
const packet = {
|
|
14199
14091
|
type: type,
|
|
14200
14092
|
data: data,
|
|
14201
|
-
options: options
|
|
14093
|
+
options: options,
|
|
14202
14094
|
};
|
|
14203
14095
|
this.emitReserved("packetCreate", packet);
|
|
14204
14096
|
this.writeBuffer.push(packet);
|
|
@@ -14208,8 +14100,6 @@
|
|
|
14208
14100
|
}
|
|
14209
14101
|
/**
|
|
14210
14102
|
* Closes the connection.
|
|
14211
|
-
*
|
|
14212
|
-
* @api public
|
|
14213
14103
|
*/
|
|
14214
14104
|
close() {
|
|
14215
14105
|
const close = () => {
|
|
@@ -14250,7 +14140,7 @@
|
|
|
14250
14140
|
/**
|
|
14251
14141
|
* Called upon transport error
|
|
14252
14142
|
*
|
|
14253
|
-
* @
|
|
14143
|
+
* @private
|
|
14254
14144
|
*/
|
|
14255
14145
|
onError(err) {
|
|
14256
14146
|
Socket$1.priorWebsocketSuccess = false;
|
|
@@ -14260,9 +14150,9 @@
|
|
|
14260
14150
|
/**
|
|
14261
14151
|
* Called upon transport close.
|
|
14262
14152
|
*
|
|
14263
|
-
* @
|
|
14153
|
+
* @private
|
|
14264
14154
|
*/
|
|
14265
|
-
onClose(reason,
|
|
14155
|
+
onClose(reason, description) {
|
|
14266
14156
|
if ("opening" === this.readyState ||
|
|
14267
14157
|
"open" === this.readyState ||
|
|
14268
14158
|
"closing" === this.readyState) {
|
|
@@ -14275,6 +14165,7 @@
|
|
|
14275
14165
|
// ignore further transport communication
|
|
14276
14166
|
this.transport.removeAllListeners();
|
|
14277
14167
|
if (typeof removeEventListener === "function") {
|
|
14168
|
+
removeEventListener("beforeunload", this.beforeunloadEventListener, false);
|
|
14278
14169
|
removeEventListener("offline", this.offlineEventListener, false);
|
|
14279
14170
|
}
|
|
14280
14171
|
// set ready state
|
|
@@ -14282,7 +14173,7 @@
|
|
|
14282
14173
|
// clear session id
|
|
14283
14174
|
this.id = null;
|
|
14284
14175
|
// emit close event
|
|
14285
|
-
this.emitReserved("close", reason,
|
|
14176
|
+
this.emitReserved("close", reason, description);
|
|
14286
14177
|
// clean buffers after, so users can still
|
|
14287
14178
|
// grab the buffers on `close` event
|
|
14288
14179
|
this.writeBuffer = [];
|
|
@@ -14292,9 +14183,8 @@
|
|
|
14292
14183
|
/**
|
|
14293
14184
|
* Filters upgrades, returning only those matching client transports.
|
|
14294
14185
|
*
|
|
14295
|
-
* @param {Array} server upgrades
|
|
14296
|
-
* @
|
|
14297
|
-
*
|
|
14186
|
+
* @param {Array} upgrades - server upgrades
|
|
14187
|
+
* @private
|
|
14298
14188
|
*/
|
|
14299
14189
|
filterUpgrades(upgrades) {
|
|
14300
14190
|
const filteredUpgrades = [];
|
|
@@ -14304,18 +14194,68 @@
|
|
|
14304
14194
|
if (~this.transports.indexOf(upgrades[i]))
|
|
14305
14195
|
filteredUpgrades.push(upgrades[i]);
|
|
14306
14196
|
}
|
|
14307
|
-
return filteredUpgrades;
|
|
14197
|
+
return filteredUpgrades;
|
|
14198
|
+
}
|
|
14199
|
+
}
|
|
14200
|
+
Socket$1.protocol = protocol$1;
|
|
14201
|
+
|
|
14202
|
+
/**
|
|
14203
|
+
* URL parser.
|
|
14204
|
+
*
|
|
14205
|
+
* @param uri - url
|
|
14206
|
+
* @param path - the request path of the connection
|
|
14207
|
+
* @param loc - An object meant to mimic window.location.
|
|
14208
|
+
* Defaults to window.location.
|
|
14209
|
+
* @public
|
|
14210
|
+
*/
|
|
14211
|
+
function url(uri, path = "", loc) {
|
|
14212
|
+
let obj = uri;
|
|
14213
|
+
// default to window.location
|
|
14214
|
+
loc = loc || (typeof location !== "undefined" && location);
|
|
14215
|
+
if (null == uri)
|
|
14216
|
+
uri = loc.protocol + "//" + loc.host;
|
|
14217
|
+
// relative path support
|
|
14218
|
+
if (typeof uri === "string") {
|
|
14219
|
+
if ("/" === uri.charAt(0)) {
|
|
14220
|
+
if ("/" === uri.charAt(1)) {
|
|
14221
|
+
uri = loc.protocol + uri;
|
|
14222
|
+
}
|
|
14223
|
+
else {
|
|
14224
|
+
uri = loc.host + uri;
|
|
14225
|
+
}
|
|
14226
|
+
}
|
|
14227
|
+
if (!/^(https?|wss?):\/\//.test(uri)) {
|
|
14228
|
+
if ("undefined" !== typeof loc) {
|
|
14229
|
+
uri = loc.protocol + "//" + uri;
|
|
14230
|
+
}
|
|
14231
|
+
else {
|
|
14232
|
+
uri = "https://" + uri;
|
|
14233
|
+
}
|
|
14234
|
+
}
|
|
14235
|
+
// parse
|
|
14236
|
+
obj = parse(uri);
|
|
14308
14237
|
}
|
|
14309
|
-
|
|
14310
|
-
|
|
14311
|
-
|
|
14312
|
-
|
|
14313
|
-
|
|
14314
|
-
if (obj.
|
|
14315
|
-
|
|
14238
|
+
// make sure we treat `localhost:80` and `localhost` equally
|
|
14239
|
+
if (!obj.port) {
|
|
14240
|
+
if (/^(http|ws)$/.test(obj.protocol)) {
|
|
14241
|
+
obj.port = "80";
|
|
14242
|
+
}
|
|
14243
|
+
else if (/^(http|ws)s$/.test(obj.protocol)) {
|
|
14244
|
+
obj.port = "443";
|
|
14316
14245
|
}
|
|
14317
14246
|
}
|
|
14318
|
-
|
|
14247
|
+
obj.path = obj.path || "/";
|
|
14248
|
+
const ipv6 = obj.host.indexOf(":") !== -1;
|
|
14249
|
+
const host = ipv6 ? "[" + obj.host + "]" : obj.host;
|
|
14250
|
+
// define unique id
|
|
14251
|
+
obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
|
|
14252
|
+
// define href
|
|
14253
|
+
obj.href =
|
|
14254
|
+
obj.protocol +
|
|
14255
|
+
"://" +
|
|
14256
|
+
host +
|
|
14257
|
+
(loc && loc.port === obj.port ? "" : ":" + obj.port);
|
|
14258
|
+
return obj;
|
|
14319
14259
|
}
|
|
14320
14260
|
|
|
14321
14261
|
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
|
|
@@ -14402,7 +14342,7 @@
|
|
|
14402
14342
|
else if (typeof data === "object" && !(data instanceof Date)) {
|
|
14403
14343
|
const newData = {};
|
|
14404
14344
|
for (const key in data) {
|
|
14405
|
-
if (
|
|
14345
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
14406
14346
|
newData[key] = _deconstructPacket(data[key], buffers);
|
|
14407
14347
|
}
|
|
14408
14348
|
}
|
|
@@ -14420,14 +14360,22 @@
|
|
|
14420
14360
|
*/
|
|
14421
14361
|
function reconstructPacket(packet, buffers) {
|
|
14422
14362
|
packet.data = _reconstructPacket(packet.data, buffers);
|
|
14423
|
-
packet.attachments
|
|
14363
|
+
delete packet.attachments; // no longer useful
|
|
14424
14364
|
return packet;
|
|
14425
14365
|
}
|
|
14426
14366
|
function _reconstructPacket(data, buffers) {
|
|
14427
14367
|
if (!data)
|
|
14428
14368
|
return data;
|
|
14429
|
-
if (data && data._placeholder) {
|
|
14430
|
-
|
|
14369
|
+
if (data && data._placeholder === true) {
|
|
14370
|
+
const isIndexValid = typeof data.num === "number" &&
|
|
14371
|
+
data.num >= 0 &&
|
|
14372
|
+
data.num < buffers.length;
|
|
14373
|
+
if (isIndexValid) {
|
|
14374
|
+
return buffers[data.num]; // appropriate buffer (should be natural order anyway)
|
|
14375
|
+
}
|
|
14376
|
+
else {
|
|
14377
|
+
throw new Error("illegal attachments");
|
|
14378
|
+
}
|
|
14431
14379
|
}
|
|
14432
14380
|
else if (Array.isArray(data)) {
|
|
14433
14381
|
for (let i = 0; i < data.length; i++) {
|
|
@@ -14436,7 +14384,7 @@
|
|
|
14436
14384
|
}
|
|
14437
14385
|
else if (typeof data === "object") {
|
|
14438
14386
|
for (const key in data) {
|
|
14439
|
-
if (
|
|
14387
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
14440
14388
|
data[key] = _reconstructPacket(data[key], buffers);
|
|
14441
14389
|
}
|
|
14442
14390
|
}
|
|
@@ -14464,6 +14412,14 @@
|
|
|
14464
14412
|
* A socket.io Encoder instance
|
|
14465
14413
|
*/
|
|
14466
14414
|
class Encoder {
|
|
14415
|
+
/**
|
|
14416
|
+
* Encoder constructor
|
|
14417
|
+
*
|
|
14418
|
+
* @param {function} replacer - custom replacer to pass down to JSON.parse
|
|
14419
|
+
*/
|
|
14420
|
+
constructor(replacer) {
|
|
14421
|
+
this.replacer = replacer;
|
|
14422
|
+
}
|
|
14467
14423
|
/**
|
|
14468
14424
|
* Encode a packet as a single string if non-binary, or as a
|
|
14469
14425
|
* buffer sequence, depending on packet type.
|
|
@@ -14473,11 +14429,14 @@
|
|
|
14473
14429
|
encode(obj) {
|
|
14474
14430
|
if (obj.type === PacketType.EVENT || obj.type === PacketType.ACK) {
|
|
14475
14431
|
if (hasBinary(obj)) {
|
|
14476
|
-
|
|
14477
|
-
obj.type === PacketType.EVENT
|
|
14432
|
+
return this.encodeAsBinary({
|
|
14433
|
+
type: obj.type === PacketType.EVENT
|
|
14478
14434
|
? PacketType.BINARY_EVENT
|
|
14479
|
-
: PacketType.BINARY_ACK
|
|
14480
|
-
|
|
14435
|
+
: PacketType.BINARY_ACK,
|
|
14436
|
+
nsp: obj.nsp,
|
|
14437
|
+
data: obj.data,
|
|
14438
|
+
id: obj.id,
|
|
14439
|
+
});
|
|
14481
14440
|
}
|
|
14482
14441
|
}
|
|
14483
14442
|
return [this.encodeAsString(obj)];
|
|
@@ -14504,7 +14463,7 @@
|
|
|
14504
14463
|
}
|
|
14505
14464
|
// json data
|
|
14506
14465
|
if (null != obj.data) {
|
|
14507
|
-
str += JSON.stringify(obj.data);
|
|
14466
|
+
str += JSON.stringify(obj.data, this.replacer);
|
|
14508
14467
|
}
|
|
14509
14468
|
return str;
|
|
14510
14469
|
}
|
|
@@ -14526,9 +14485,15 @@
|
|
|
14526
14485
|
*
|
|
14527
14486
|
* @return {Object} decoder
|
|
14528
14487
|
*/
|
|
14529
|
-
class Decoder extends
|
|
14530
|
-
|
|
14488
|
+
class Decoder extends Emitter {
|
|
14489
|
+
/**
|
|
14490
|
+
* Decoder constructor
|
|
14491
|
+
*
|
|
14492
|
+
* @param {function} reviver - custom reviver to pass down to JSON.stringify
|
|
14493
|
+
*/
|
|
14494
|
+
constructor(reviver) {
|
|
14531
14495
|
super();
|
|
14496
|
+
this.reviver = reviver;
|
|
14532
14497
|
}
|
|
14533
14498
|
/**
|
|
14534
14499
|
* Decodes an encoded packet string into packet JSON.
|
|
@@ -14538,9 +14503,13 @@
|
|
|
14538
14503
|
add(obj) {
|
|
14539
14504
|
let packet;
|
|
14540
14505
|
if (typeof obj === "string") {
|
|
14506
|
+
if (this.reconstructor) {
|
|
14507
|
+
throw new Error("got plaintext data when reconstructing a packet");
|
|
14508
|
+
}
|
|
14541
14509
|
packet = this.decodeString(obj);
|
|
14542
|
-
|
|
14543
|
-
|
|
14510
|
+
const isBinaryEvent = packet.type === PacketType.BINARY_EVENT;
|
|
14511
|
+
if (isBinaryEvent || packet.type === PacketType.BINARY_ACK) {
|
|
14512
|
+
packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK;
|
|
14544
14513
|
// binary packet's json
|
|
14545
14514
|
this.reconstructor = new BinaryReconstructor(packet);
|
|
14546
14515
|
// no attachments, labeled binary but no binary data to follow
|
|
@@ -14629,7 +14598,7 @@
|
|
|
14629
14598
|
}
|
|
14630
14599
|
// look up json data
|
|
14631
14600
|
if (str.charAt(++i)) {
|
|
14632
|
-
const payload = tryParse(str.substr(i));
|
|
14601
|
+
const payload = this.tryParse(str.substr(i));
|
|
14633
14602
|
if (Decoder.isPayloadValid(p.type, payload)) {
|
|
14634
14603
|
p.data = payload;
|
|
14635
14604
|
}
|
|
@@ -14639,6 +14608,14 @@
|
|
|
14639
14608
|
}
|
|
14640
14609
|
return p;
|
|
14641
14610
|
}
|
|
14611
|
+
tryParse(str) {
|
|
14612
|
+
try {
|
|
14613
|
+
return JSON.parse(str, this.reviver);
|
|
14614
|
+
}
|
|
14615
|
+
catch (e) {
|
|
14616
|
+
return false;
|
|
14617
|
+
}
|
|
14618
|
+
}
|
|
14642
14619
|
static isPayloadValid(type, payload) {
|
|
14643
14620
|
switch (type) {
|
|
14644
14621
|
case PacketType.CONNECT:
|
|
@@ -14661,17 +14638,10 @@
|
|
|
14661
14638
|
destroy() {
|
|
14662
14639
|
if (this.reconstructor) {
|
|
14663
14640
|
this.reconstructor.finishedReconstruction();
|
|
14641
|
+
this.reconstructor = null;
|
|
14664
14642
|
}
|
|
14665
14643
|
}
|
|
14666
14644
|
}
|
|
14667
|
-
function tryParse(str) {
|
|
14668
|
-
try {
|
|
14669
|
-
return JSON.parse(str);
|
|
14670
|
-
}
|
|
14671
|
-
catch (e) {
|
|
14672
|
-
return false;
|
|
14673
|
-
}
|
|
14674
|
-
}
|
|
14675
14645
|
/**
|
|
14676
14646
|
* A manager of a binary event's 'buffer sequence'. Should
|
|
14677
14647
|
* be constructed whenever a packet of type BINARY_EVENT is
|
|
@@ -14741,18 +14711,76 @@
|
|
|
14741
14711
|
newListener: 1,
|
|
14742
14712
|
removeListener: 1,
|
|
14743
14713
|
});
|
|
14744
|
-
|
|
14714
|
+
/**
|
|
14715
|
+
* A Socket is the fundamental class for interacting with the server.
|
|
14716
|
+
*
|
|
14717
|
+
* A Socket belongs to a certain Namespace (by default /) and uses an underlying {@link Manager} to communicate.
|
|
14718
|
+
*
|
|
14719
|
+
* @example
|
|
14720
|
+
* const socket = io();
|
|
14721
|
+
*
|
|
14722
|
+
* socket.on("connect", () => {
|
|
14723
|
+
* console.log("connected");
|
|
14724
|
+
* });
|
|
14725
|
+
*
|
|
14726
|
+
* // send an event to the server
|
|
14727
|
+
* socket.emit("foo", "bar");
|
|
14728
|
+
*
|
|
14729
|
+
* socket.on("foobar", () => {
|
|
14730
|
+
* // an event was received from the server
|
|
14731
|
+
* });
|
|
14732
|
+
*
|
|
14733
|
+
* // upon disconnection
|
|
14734
|
+
* socket.on("disconnect", (reason) => {
|
|
14735
|
+
* console.log(`disconnected due to ${reason}`);
|
|
14736
|
+
* });
|
|
14737
|
+
*/
|
|
14738
|
+
class Socket extends Emitter {
|
|
14745
14739
|
/**
|
|
14746
14740
|
* `Socket` constructor.
|
|
14747
|
-
*
|
|
14748
|
-
* @public
|
|
14749
14741
|
*/
|
|
14750
14742
|
constructor(io, nsp, opts) {
|
|
14751
14743
|
super();
|
|
14744
|
+
/**
|
|
14745
|
+
* Whether the socket is currently connected to the server.
|
|
14746
|
+
*
|
|
14747
|
+
* @example
|
|
14748
|
+
* const socket = io();
|
|
14749
|
+
*
|
|
14750
|
+
* socket.on("connect", () => {
|
|
14751
|
+
* console.log(socket.connected); // true
|
|
14752
|
+
* });
|
|
14753
|
+
*
|
|
14754
|
+
* socket.on("disconnect", () => {
|
|
14755
|
+
* console.log(socket.connected); // false
|
|
14756
|
+
* });
|
|
14757
|
+
*/
|
|
14752
14758
|
this.connected = false;
|
|
14753
|
-
|
|
14759
|
+
/**
|
|
14760
|
+
* Whether the connection state was recovered after a temporary disconnection. In that case, any missed packets will
|
|
14761
|
+
* be transmitted by the server.
|
|
14762
|
+
*/
|
|
14763
|
+
this.recovered = false;
|
|
14764
|
+
/**
|
|
14765
|
+
* Buffer for packets received before the CONNECT packet
|
|
14766
|
+
*/
|
|
14754
14767
|
this.receiveBuffer = [];
|
|
14768
|
+
/**
|
|
14769
|
+
* Buffer for packets that will be sent once the socket is connected
|
|
14770
|
+
*/
|
|
14755
14771
|
this.sendBuffer = [];
|
|
14772
|
+
/**
|
|
14773
|
+
* The queue of packets to be sent with retry in case of failure.
|
|
14774
|
+
*
|
|
14775
|
+
* Packets are sent one by one, each waiting for the server acknowledgement, in order to guarantee the delivery order.
|
|
14776
|
+
* @private
|
|
14777
|
+
*/
|
|
14778
|
+
this._queue = [];
|
|
14779
|
+
/**
|
|
14780
|
+
* A sequence to generate the ID of the {@link QueuedPacket}.
|
|
14781
|
+
* @private
|
|
14782
|
+
*/
|
|
14783
|
+
this._queueSeq = 0;
|
|
14756
14784
|
this.ids = 0;
|
|
14757
14785
|
this.acks = {};
|
|
14758
14786
|
this.flags = {};
|
|
@@ -14761,9 +14789,27 @@
|
|
|
14761
14789
|
if (opts && opts.auth) {
|
|
14762
14790
|
this.auth = opts.auth;
|
|
14763
14791
|
}
|
|
14792
|
+
this._opts = Object.assign({}, opts);
|
|
14764
14793
|
if (this.io._autoConnect)
|
|
14765
14794
|
this.open();
|
|
14766
14795
|
}
|
|
14796
|
+
/**
|
|
14797
|
+
* Whether the socket is currently disconnected
|
|
14798
|
+
*
|
|
14799
|
+
* @example
|
|
14800
|
+
* const socket = io();
|
|
14801
|
+
*
|
|
14802
|
+
* socket.on("connect", () => {
|
|
14803
|
+
* console.log(socket.disconnected); // false
|
|
14804
|
+
* });
|
|
14805
|
+
*
|
|
14806
|
+
* socket.on("disconnect", () => {
|
|
14807
|
+
* console.log(socket.disconnected); // true
|
|
14808
|
+
* });
|
|
14809
|
+
*/
|
|
14810
|
+
get disconnected() {
|
|
14811
|
+
return !this.connected;
|
|
14812
|
+
}
|
|
14767
14813
|
/**
|
|
14768
14814
|
* Subscribe to open, close and packet events
|
|
14769
14815
|
*
|
|
@@ -14781,7 +14827,21 @@
|
|
|
14781
14827
|
];
|
|
14782
14828
|
}
|
|
14783
14829
|
/**
|
|
14784
|
-
* Whether the Socket will try to reconnect when its Manager connects or reconnects
|
|
14830
|
+
* Whether the Socket will try to reconnect when its Manager connects or reconnects.
|
|
14831
|
+
*
|
|
14832
|
+
* @example
|
|
14833
|
+
* const socket = io();
|
|
14834
|
+
*
|
|
14835
|
+
* console.log(socket.active); // true
|
|
14836
|
+
*
|
|
14837
|
+
* socket.on("disconnect", (reason) => {
|
|
14838
|
+
* if (reason === "io server disconnect") {
|
|
14839
|
+
* // the disconnection was initiated by the server, you need to manually reconnect
|
|
14840
|
+
* console.log(socket.active); // false
|
|
14841
|
+
* }
|
|
14842
|
+
* // else the socket will automatically try to reconnect
|
|
14843
|
+
* console.log(socket.active); // true
|
|
14844
|
+
* });
|
|
14785
14845
|
*/
|
|
14786
14846
|
get active() {
|
|
14787
14847
|
return !!this.subs;
|
|
@@ -14789,7 +14849,12 @@
|
|
|
14789
14849
|
/**
|
|
14790
14850
|
* "Opens" the socket.
|
|
14791
14851
|
*
|
|
14792
|
-
* @
|
|
14852
|
+
* @example
|
|
14853
|
+
* const socket = io({
|
|
14854
|
+
* autoConnect: false
|
|
14855
|
+
* });
|
|
14856
|
+
*
|
|
14857
|
+
* socket.connect();
|
|
14793
14858
|
*/
|
|
14794
14859
|
connect() {
|
|
14795
14860
|
if (this.connected)
|
|
@@ -14802,7 +14867,7 @@
|
|
|
14802
14867
|
return this;
|
|
14803
14868
|
}
|
|
14804
14869
|
/**
|
|
14805
|
-
* Alias for connect()
|
|
14870
|
+
* Alias for {@link connect()}.
|
|
14806
14871
|
*/
|
|
14807
14872
|
open() {
|
|
14808
14873
|
return this.connect();
|
|
@@ -14810,8 +14875,17 @@
|
|
|
14810
14875
|
/**
|
|
14811
14876
|
* Sends a `message` event.
|
|
14812
14877
|
*
|
|
14878
|
+
* This method mimics the WebSocket.send() method.
|
|
14879
|
+
*
|
|
14880
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
|
|
14881
|
+
*
|
|
14882
|
+
* @example
|
|
14883
|
+
* socket.send("hello");
|
|
14884
|
+
*
|
|
14885
|
+
* // this is equivalent to
|
|
14886
|
+
* socket.emit("message", "hello");
|
|
14887
|
+
*
|
|
14813
14888
|
* @return self
|
|
14814
|
-
* @public
|
|
14815
14889
|
*/
|
|
14816
14890
|
send(...args) {
|
|
14817
14891
|
args.unshift("message");
|
|
@@ -14822,14 +14896,28 @@
|
|
|
14822
14896
|
* Override `emit`.
|
|
14823
14897
|
* If the event is in `events`, it's emitted normally.
|
|
14824
14898
|
*
|
|
14899
|
+
* @example
|
|
14900
|
+
* socket.emit("hello", "world");
|
|
14901
|
+
*
|
|
14902
|
+
* // all serializable datastructures are supported (no need to call JSON.stringify)
|
|
14903
|
+
* socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
|
|
14904
|
+
*
|
|
14905
|
+
* // with an acknowledgement from the server
|
|
14906
|
+
* socket.emit("hello", "world", (val) => {
|
|
14907
|
+
* // ...
|
|
14908
|
+
* });
|
|
14909
|
+
*
|
|
14825
14910
|
* @return self
|
|
14826
|
-
* @public
|
|
14827
14911
|
*/
|
|
14828
14912
|
emit(ev, ...args) {
|
|
14829
14913
|
if (RESERVED_EVENTS.hasOwnProperty(ev)) {
|
|
14830
|
-
throw new Error('"' + ev + '" is a reserved event name');
|
|
14914
|
+
throw new Error('"' + ev.toString() + '" is a reserved event name');
|
|
14831
14915
|
}
|
|
14832
14916
|
args.unshift(ev);
|
|
14917
|
+
if (this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) {
|
|
14918
|
+
this._addToQueue(args);
|
|
14919
|
+
return this;
|
|
14920
|
+
}
|
|
14833
14921
|
const packet = {
|
|
14834
14922
|
type: PacketType.EVENT,
|
|
14835
14923
|
data: args,
|
|
@@ -14849,6 +14937,7 @@
|
|
|
14849
14937
|
const discardPacket = this.flags.volatile && (!isTransportWritable || !this.connected);
|
|
14850
14938
|
if (discardPacket) ;
|
|
14851
14939
|
else if (this.connected) {
|
|
14940
|
+
this.notifyOutgoingListeners(packet);
|
|
14852
14941
|
this.packet(packet);
|
|
14853
14942
|
}
|
|
14854
14943
|
else {
|
|
@@ -14861,7 +14950,8 @@
|
|
|
14861
14950
|
* @private
|
|
14862
14951
|
*/
|
|
14863
14952
|
_registerAckCallback(id, ack) {
|
|
14864
|
-
|
|
14953
|
+
var _a;
|
|
14954
|
+
const timeout = (_a = this.flags.timeout) !== null && _a !== void 0 ? _a : this._opts.ackTimeout;
|
|
14865
14955
|
if (timeout === undefined) {
|
|
14866
14956
|
this.acks[id] = ack;
|
|
14867
14957
|
return;
|
|
@@ -14882,6 +14972,99 @@
|
|
|
14882
14972
|
ack.apply(this, [null, ...args]);
|
|
14883
14973
|
};
|
|
14884
14974
|
}
|
|
14975
|
+
/**
|
|
14976
|
+
* Emits an event and waits for an acknowledgement
|
|
14977
|
+
*
|
|
14978
|
+
* @example
|
|
14979
|
+
* // without timeout
|
|
14980
|
+
* const response = await socket.emitWithAck("hello", "world");
|
|
14981
|
+
*
|
|
14982
|
+
* // with a specific timeout
|
|
14983
|
+
* try {
|
|
14984
|
+
* const response = await socket.timeout(1000).emitWithAck("hello", "world");
|
|
14985
|
+
* } catch (err) {
|
|
14986
|
+
* // the server did not acknowledge the event in the given delay
|
|
14987
|
+
* }
|
|
14988
|
+
*
|
|
14989
|
+
* @return a Promise that will be fulfilled when the server acknowledges the event
|
|
14990
|
+
*/
|
|
14991
|
+
emitWithAck(ev, ...args) {
|
|
14992
|
+
// the timeout flag is optional
|
|
14993
|
+
const withErr = this.flags.timeout !== undefined || this._opts.ackTimeout !== undefined;
|
|
14994
|
+
return new Promise((resolve, reject) => {
|
|
14995
|
+
args.push((arg1, arg2) => {
|
|
14996
|
+
if (withErr) {
|
|
14997
|
+
return arg1 ? reject(arg1) : resolve(arg2);
|
|
14998
|
+
}
|
|
14999
|
+
else {
|
|
15000
|
+
return resolve(arg1);
|
|
15001
|
+
}
|
|
15002
|
+
});
|
|
15003
|
+
this.emit(ev, ...args);
|
|
15004
|
+
});
|
|
15005
|
+
}
|
|
15006
|
+
/**
|
|
15007
|
+
* Add the packet to the queue.
|
|
15008
|
+
* @param args
|
|
15009
|
+
* @private
|
|
15010
|
+
*/
|
|
15011
|
+
_addToQueue(args) {
|
|
15012
|
+
let ack;
|
|
15013
|
+
if (typeof args[args.length - 1] === "function") {
|
|
15014
|
+
ack = args.pop();
|
|
15015
|
+
}
|
|
15016
|
+
const packet = {
|
|
15017
|
+
id: this._queueSeq++,
|
|
15018
|
+
tryCount: 0,
|
|
15019
|
+
pending: false,
|
|
15020
|
+
args,
|
|
15021
|
+
flags: Object.assign({ fromQueue: true }, this.flags),
|
|
15022
|
+
};
|
|
15023
|
+
args.push((err, ...responseArgs) => {
|
|
15024
|
+
if (packet !== this._queue[0]) {
|
|
15025
|
+
// the packet has already been acknowledged
|
|
15026
|
+
return;
|
|
15027
|
+
}
|
|
15028
|
+
const hasError = err !== null;
|
|
15029
|
+
if (hasError) {
|
|
15030
|
+
if (packet.tryCount > this._opts.retries) {
|
|
15031
|
+
this._queue.shift();
|
|
15032
|
+
if (ack) {
|
|
15033
|
+
ack(err);
|
|
15034
|
+
}
|
|
15035
|
+
}
|
|
15036
|
+
}
|
|
15037
|
+
else {
|
|
15038
|
+
this._queue.shift();
|
|
15039
|
+
if (ack) {
|
|
15040
|
+
ack(null, ...responseArgs);
|
|
15041
|
+
}
|
|
15042
|
+
}
|
|
15043
|
+
packet.pending = false;
|
|
15044
|
+
return this._drainQueue();
|
|
15045
|
+
});
|
|
15046
|
+
this._queue.push(packet);
|
|
15047
|
+
this._drainQueue();
|
|
15048
|
+
}
|
|
15049
|
+
/**
|
|
15050
|
+
* Send the first packet of the queue, and wait for an acknowledgement from the server.
|
|
15051
|
+
* @param force - whether to resend a packet that has not been acknowledged yet
|
|
15052
|
+
*
|
|
15053
|
+
* @private
|
|
15054
|
+
*/
|
|
15055
|
+
_drainQueue(force = false) {
|
|
15056
|
+
if (!this.connected || this._queue.length === 0) {
|
|
15057
|
+
return;
|
|
15058
|
+
}
|
|
15059
|
+
const packet = this._queue[0];
|
|
15060
|
+
if (packet.pending && !force) {
|
|
15061
|
+
return;
|
|
15062
|
+
}
|
|
15063
|
+
packet.pending = true;
|
|
15064
|
+
packet.tryCount++;
|
|
15065
|
+
this.flags = packet.flags;
|
|
15066
|
+
this.emit.apply(this, packet.args);
|
|
15067
|
+
}
|
|
14885
15068
|
/**
|
|
14886
15069
|
* Sends a packet.
|
|
14887
15070
|
*
|
|
@@ -14900,13 +15083,27 @@
|
|
|
14900
15083
|
onopen() {
|
|
14901
15084
|
if (typeof this.auth == "function") {
|
|
14902
15085
|
this.auth((data) => {
|
|
14903
|
-
this.
|
|
15086
|
+
this._sendConnectPacket(data);
|
|
14904
15087
|
});
|
|
14905
15088
|
}
|
|
14906
15089
|
else {
|
|
14907
|
-
this.
|
|
15090
|
+
this._sendConnectPacket(this.auth);
|
|
14908
15091
|
}
|
|
14909
15092
|
}
|
|
15093
|
+
/**
|
|
15094
|
+
* Sends a CONNECT packet to initiate the Socket.IO session.
|
|
15095
|
+
*
|
|
15096
|
+
* @param data
|
|
15097
|
+
* @private
|
|
15098
|
+
*/
|
|
15099
|
+
_sendConnectPacket(data) {
|
|
15100
|
+
this.packet({
|
|
15101
|
+
type: PacketType.CONNECT,
|
|
15102
|
+
data: this._pid
|
|
15103
|
+
? Object.assign({ pid: this._pid, offset: this._lastOffset }, data)
|
|
15104
|
+
: data,
|
|
15105
|
+
});
|
|
15106
|
+
}
|
|
14910
15107
|
/**
|
|
14911
15108
|
* Called upon engine or manager `error`.
|
|
14912
15109
|
*
|
|
@@ -14922,13 +15119,13 @@
|
|
|
14922
15119
|
* Called upon engine `close`.
|
|
14923
15120
|
*
|
|
14924
15121
|
* @param reason
|
|
15122
|
+
* @param description
|
|
14925
15123
|
* @private
|
|
14926
15124
|
*/
|
|
14927
|
-
onclose(reason) {
|
|
15125
|
+
onclose(reason, description) {
|
|
14928
15126
|
this.connected = false;
|
|
14929
|
-
this.disconnected = true;
|
|
14930
15127
|
delete this.id;
|
|
14931
|
-
this.emitReserved("disconnect", reason);
|
|
15128
|
+
this.emitReserved("disconnect", reason, description);
|
|
14932
15129
|
}
|
|
14933
15130
|
/**
|
|
14934
15131
|
* Called with socket packet.
|
|
@@ -14943,22 +15140,17 @@
|
|
|
14943
15140
|
switch (packet.type) {
|
|
14944
15141
|
case PacketType.CONNECT:
|
|
14945
15142
|
if (packet.data && packet.data.sid) {
|
|
14946
|
-
|
|
14947
|
-
this.onconnect(id);
|
|
15143
|
+
this.onconnect(packet.data.sid, packet.data.pid);
|
|
14948
15144
|
}
|
|
14949
15145
|
else {
|
|
14950
15146
|
this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
|
|
14951
15147
|
}
|
|
14952
15148
|
break;
|
|
14953
15149
|
case PacketType.EVENT:
|
|
14954
|
-
this.onevent(packet);
|
|
14955
|
-
break;
|
|
14956
15150
|
case PacketType.BINARY_EVENT:
|
|
14957
15151
|
this.onevent(packet);
|
|
14958
15152
|
break;
|
|
14959
15153
|
case PacketType.ACK:
|
|
14960
|
-
this.onack(packet);
|
|
14961
|
-
break;
|
|
14962
15154
|
case PacketType.BINARY_ACK:
|
|
14963
15155
|
this.onack(packet);
|
|
14964
15156
|
break;
|
|
@@ -15000,6 +15192,9 @@
|
|
|
15000
15192
|
}
|
|
15001
15193
|
}
|
|
15002
15194
|
super.emit.apply(this, args);
|
|
15195
|
+
if (this._pid && args.length && typeof args[args.length - 1] === "string") {
|
|
15196
|
+
this._lastOffset = args[args.length - 1];
|
|
15197
|
+
}
|
|
15003
15198
|
}
|
|
15004
15199
|
/**
|
|
15005
15200
|
* Produces an ack callback to emit with an event.
|
|
@@ -15039,12 +15234,14 @@
|
|
|
15039
15234
|
*
|
|
15040
15235
|
* @private
|
|
15041
15236
|
*/
|
|
15042
|
-
onconnect(id) {
|
|
15237
|
+
onconnect(id, pid) {
|
|
15043
15238
|
this.id = id;
|
|
15239
|
+
this.recovered = pid && this._pid === pid;
|
|
15240
|
+
this._pid = pid; // defined only if connection state recovery is enabled
|
|
15044
15241
|
this.connected = true;
|
|
15045
|
-
this.disconnected = false;
|
|
15046
15242
|
this.emitBuffered();
|
|
15047
15243
|
this.emitReserved("connect");
|
|
15244
|
+
this._drainQueue(true);
|
|
15048
15245
|
}
|
|
15049
15246
|
/**
|
|
15050
15247
|
* Emit buffered events (received and emitted).
|
|
@@ -15054,7 +15251,10 @@
|
|
|
15054
15251
|
emitBuffered() {
|
|
15055
15252
|
this.receiveBuffer.forEach((args) => this.emitEvent(args));
|
|
15056
15253
|
this.receiveBuffer = [];
|
|
15057
|
-
this.sendBuffer.forEach((packet) =>
|
|
15254
|
+
this.sendBuffer.forEach((packet) => {
|
|
15255
|
+
this.notifyOutgoingListeners(packet);
|
|
15256
|
+
this.packet(packet);
|
|
15257
|
+
});
|
|
15058
15258
|
this.sendBuffer = [];
|
|
15059
15259
|
}
|
|
15060
15260
|
/**
|
|
@@ -15082,10 +15282,20 @@
|
|
|
15082
15282
|
this.io["_destroy"](this);
|
|
15083
15283
|
}
|
|
15084
15284
|
/**
|
|
15085
|
-
* Disconnects the socket manually.
|
|
15285
|
+
* Disconnects the socket manually. In that case, the socket will not try to reconnect.
|
|
15286
|
+
*
|
|
15287
|
+
* If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
|
|
15288
|
+
*
|
|
15289
|
+
* @example
|
|
15290
|
+
* const socket = io();
|
|
15291
|
+
*
|
|
15292
|
+
* socket.on("disconnect", (reason) => {
|
|
15293
|
+
* // console.log(reason); prints "io client disconnect"
|
|
15294
|
+
* });
|
|
15295
|
+
*
|
|
15296
|
+
* socket.disconnect();
|
|
15086
15297
|
*
|
|
15087
15298
|
* @return self
|
|
15088
|
-
* @public
|
|
15089
15299
|
*/
|
|
15090
15300
|
disconnect() {
|
|
15091
15301
|
if (this.connected) {
|
|
@@ -15100,10 +15310,9 @@
|
|
|
15100
15310
|
return this;
|
|
15101
15311
|
}
|
|
15102
15312
|
/**
|
|
15103
|
-
* Alias for disconnect()
|
|
15313
|
+
* Alias for {@link disconnect()}.
|
|
15104
15314
|
*
|
|
15105
15315
|
* @return self
|
|
15106
|
-
* @public
|
|
15107
15316
|
*/
|
|
15108
15317
|
close() {
|
|
15109
15318
|
return this.disconnect();
|
|
@@ -15111,9 +15320,11 @@
|
|
|
15111
15320
|
/**
|
|
15112
15321
|
* Sets the compress flag.
|
|
15113
15322
|
*
|
|
15323
|
+
* @example
|
|
15324
|
+
* socket.compress(false).emit("hello");
|
|
15325
|
+
*
|
|
15114
15326
|
* @param compress - if `true`, compresses the sending data
|
|
15115
15327
|
* @return self
|
|
15116
|
-
* @public
|
|
15117
15328
|
*/
|
|
15118
15329
|
compress(compress) {
|
|
15119
15330
|
this.flags.compress = compress;
|
|
@@ -15123,8 +15334,10 @@
|
|
|
15123
15334
|
* Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
|
|
15124
15335
|
* ready to send messages.
|
|
15125
15336
|
*
|
|
15337
|
+
* @example
|
|
15338
|
+
* socket.volatile.emit("hello"); // the server may or may not receive it
|
|
15339
|
+
*
|
|
15126
15340
|
* @returns self
|
|
15127
|
-
* @public
|
|
15128
15341
|
*/
|
|
15129
15342
|
get volatile() {
|
|
15130
15343
|
this.flags.volatile = true;
|
|
@@ -15134,16 +15347,14 @@
|
|
|
15134
15347
|
* Sets a modifier for a subsequent event emission that the callback will be called with an error when the
|
|
15135
15348
|
* given number of milliseconds have elapsed without an acknowledgement from the server:
|
|
15136
15349
|
*
|
|
15137
|
-
*
|
|
15350
|
+
* @example
|
|
15138
15351
|
* socket.timeout(5000).emit("my-event", (err) => {
|
|
15139
15352
|
* if (err) {
|
|
15140
15353
|
* // the server did not acknowledge the event in the given delay
|
|
15141
15354
|
* }
|
|
15142
15355
|
* });
|
|
15143
|
-
* ```
|
|
15144
15356
|
*
|
|
15145
15357
|
* @returns self
|
|
15146
|
-
* @public
|
|
15147
15358
|
*/
|
|
15148
15359
|
timeout(timeout) {
|
|
15149
15360
|
this.flags.timeout = timeout;
|
|
@@ -15153,8 +15364,12 @@
|
|
|
15153
15364
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
15154
15365
|
* callback.
|
|
15155
15366
|
*
|
|
15367
|
+
* @example
|
|
15368
|
+
* socket.onAny((event, ...args) => {
|
|
15369
|
+
* console.log(`got ${event}`);
|
|
15370
|
+
* });
|
|
15371
|
+
*
|
|
15156
15372
|
* @param listener
|
|
15157
|
-
* @public
|
|
15158
15373
|
*/
|
|
15159
15374
|
onAny(listener) {
|
|
15160
15375
|
this._anyListeners = this._anyListeners || [];
|
|
@@ -15165,8 +15380,12 @@
|
|
|
15165
15380
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
15166
15381
|
* callback. The listener is added to the beginning of the listeners array.
|
|
15167
15382
|
*
|
|
15383
|
+
* @example
|
|
15384
|
+
* socket.prependAny((event, ...args) => {
|
|
15385
|
+
* console.log(`got event ${event}`);
|
|
15386
|
+
* });
|
|
15387
|
+
*
|
|
15168
15388
|
* @param listener
|
|
15169
|
-
* @public
|
|
15170
15389
|
*/
|
|
15171
15390
|
prependAny(listener) {
|
|
15172
15391
|
this._anyListeners = this._anyListeners || [];
|
|
@@ -15176,8 +15395,20 @@
|
|
|
15176
15395
|
/**
|
|
15177
15396
|
* Removes the listener that will be fired when any event is emitted.
|
|
15178
15397
|
*
|
|
15398
|
+
* @example
|
|
15399
|
+
* const catchAllListener = (event, ...args) => {
|
|
15400
|
+
* console.log(`got event ${event}`);
|
|
15401
|
+
* }
|
|
15402
|
+
*
|
|
15403
|
+
* socket.onAny(catchAllListener);
|
|
15404
|
+
*
|
|
15405
|
+
* // remove a specific listener
|
|
15406
|
+
* socket.offAny(catchAllListener);
|
|
15407
|
+
*
|
|
15408
|
+
* // or remove all listeners
|
|
15409
|
+
* socket.offAny();
|
|
15410
|
+
*
|
|
15179
15411
|
* @param listener
|
|
15180
|
-
* @public
|
|
15181
15412
|
*/
|
|
15182
15413
|
offAny(listener) {
|
|
15183
15414
|
if (!this._anyListeners) {
|
|
@@ -15200,20 +15431,106 @@
|
|
|
15200
15431
|
/**
|
|
15201
15432
|
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
15202
15433
|
* e.g. to remove listeners.
|
|
15203
|
-
*
|
|
15204
|
-
* @public
|
|
15205
15434
|
*/
|
|
15206
15435
|
listenersAny() {
|
|
15207
15436
|
return this._anyListeners || [];
|
|
15208
15437
|
}
|
|
15438
|
+
/**
|
|
15439
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
15440
|
+
* callback.
|
|
15441
|
+
*
|
|
15442
|
+
* Note: acknowledgements sent to the server are not included.
|
|
15443
|
+
*
|
|
15444
|
+
* @example
|
|
15445
|
+
* socket.onAnyOutgoing((event, ...args) => {
|
|
15446
|
+
* console.log(`sent event ${event}`);
|
|
15447
|
+
* });
|
|
15448
|
+
*
|
|
15449
|
+
* @param listener
|
|
15450
|
+
*/
|
|
15451
|
+
onAnyOutgoing(listener) {
|
|
15452
|
+
this._anyOutgoingListeners = this._anyOutgoingListeners || [];
|
|
15453
|
+
this._anyOutgoingListeners.push(listener);
|
|
15454
|
+
return this;
|
|
15455
|
+
}
|
|
15456
|
+
/**
|
|
15457
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
15458
|
+
* callback. The listener is added to the beginning of the listeners array.
|
|
15459
|
+
*
|
|
15460
|
+
* Note: acknowledgements sent to the server are not included.
|
|
15461
|
+
*
|
|
15462
|
+
* @example
|
|
15463
|
+
* socket.prependAnyOutgoing((event, ...args) => {
|
|
15464
|
+
* console.log(`sent event ${event}`);
|
|
15465
|
+
* });
|
|
15466
|
+
*
|
|
15467
|
+
* @param listener
|
|
15468
|
+
*/
|
|
15469
|
+
prependAnyOutgoing(listener) {
|
|
15470
|
+
this._anyOutgoingListeners = this._anyOutgoingListeners || [];
|
|
15471
|
+
this._anyOutgoingListeners.unshift(listener);
|
|
15472
|
+
return this;
|
|
15473
|
+
}
|
|
15474
|
+
/**
|
|
15475
|
+
* Removes the listener that will be fired when any event is emitted.
|
|
15476
|
+
*
|
|
15477
|
+
* @example
|
|
15478
|
+
* const catchAllListener = (event, ...args) => {
|
|
15479
|
+
* console.log(`sent event ${event}`);
|
|
15480
|
+
* }
|
|
15481
|
+
*
|
|
15482
|
+
* socket.onAnyOutgoing(catchAllListener);
|
|
15483
|
+
*
|
|
15484
|
+
* // remove a specific listener
|
|
15485
|
+
* socket.offAnyOutgoing(catchAllListener);
|
|
15486
|
+
*
|
|
15487
|
+
* // or remove all listeners
|
|
15488
|
+
* socket.offAnyOutgoing();
|
|
15489
|
+
*
|
|
15490
|
+
* @param [listener] - the catch-all listener (optional)
|
|
15491
|
+
*/
|
|
15492
|
+
offAnyOutgoing(listener) {
|
|
15493
|
+
if (!this._anyOutgoingListeners) {
|
|
15494
|
+
return this;
|
|
15495
|
+
}
|
|
15496
|
+
if (listener) {
|
|
15497
|
+
const listeners = this._anyOutgoingListeners;
|
|
15498
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
15499
|
+
if (listener === listeners[i]) {
|
|
15500
|
+
listeners.splice(i, 1);
|
|
15501
|
+
return this;
|
|
15502
|
+
}
|
|
15503
|
+
}
|
|
15504
|
+
}
|
|
15505
|
+
else {
|
|
15506
|
+
this._anyOutgoingListeners = [];
|
|
15507
|
+
}
|
|
15508
|
+
return this;
|
|
15509
|
+
}
|
|
15510
|
+
/**
|
|
15511
|
+
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
15512
|
+
* e.g. to remove listeners.
|
|
15513
|
+
*/
|
|
15514
|
+
listenersAnyOutgoing() {
|
|
15515
|
+
return this._anyOutgoingListeners || [];
|
|
15516
|
+
}
|
|
15517
|
+
/**
|
|
15518
|
+
* Notify the listeners for each packet sent
|
|
15519
|
+
*
|
|
15520
|
+
* @param packet
|
|
15521
|
+
*
|
|
15522
|
+
* @private
|
|
15523
|
+
*/
|
|
15524
|
+
notifyOutgoingListeners(packet) {
|
|
15525
|
+
if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
|
|
15526
|
+
const listeners = this._anyOutgoingListeners.slice();
|
|
15527
|
+
for (const listener of listeners) {
|
|
15528
|
+
listener.apply(this, packet.data);
|
|
15529
|
+
}
|
|
15530
|
+
}
|
|
15531
|
+
}
|
|
15209
15532
|
}
|
|
15210
15533
|
|
|
15211
|
-
/**
|
|
15212
|
-
* Expose `Backoff`.
|
|
15213
|
-
*/
|
|
15214
|
-
|
|
15215
|
-
var backo2 = Backoff;
|
|
15216
|
-
|
|
15217
15534
|
/**
|
|
15218
15535
|
* Initialize backoff timer with `opts`.
|
|
15219
15536
|
*
|
|
@@ -15225,74 +15542,63 @@
|
|
|
15225
15542
|
* @param {Object} opts
|
|
15226
15543
|
* @api public
|
|
15227
15544
|
*/
|
|
15228
|
-
|
|
15229
15545
|
function Backoff(opts) {
|
|
15230
|
-
|
|
15231
|
-
|
|
15232
|
-
|
|
15233
|
-
|
|
15234
|
-
|
|
15235
|
-
|
|
15546
|
+
opts = opts || {};
|
|
15547
|
+
this.ms = opts.min || 100;
|
|
15548
|
+
this.max = opts.max || 10000;
|
|
15549
|
+
this.factor = opts.factor || 2;
|
|
15550
|
+
this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
|
|
15551
|
+
this.attempts = 0;
|
|
15236
15552
|
}
|
|
15237
|
-
|
|
15238
15553
|
/**
|
|
15239
15554
|
* Return the backoff duration.
|
|
15240
15555
|
*
|
|
15241
15556
|
* @return {Number}
|
|
15242
15557
|
* @api public
|
|
15243
15558
|
*/
|
|
15244
|
-
|
|
15245
|
-
|
|
15246
|
-
|
|
15247
|
-
|
|
15248
|
-
|
|
15249
|
-
|
|
15250
|
-
|
|
15251
|
-
|
|
15252
|
-
return Math.min(ms, this.max) | 0;
|
|
15559
|
+
Backoff.prototype.duration = function () {
|
|
15560
|
+
var ms = this.ms * Math.pow(this.factor, this.attempts++);
|
|
15561
|
+
if (this.jitter) {
|
|
15562
|
+
var rand = Math.random();
|
|
15563
|
+
var deviation = Math.floor(rand * this.jitter * ms);
|
|
15564
|
+
ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
|
|
15565
|
+
}
|
|
15566
|
+
return Math.min(ms, this.max) | 0;
|
|
15253
15567
|
};
|
|
15254
|
-
|
|
15255
15568
|
/**
|
|
15256
15569
|
* Reset the number of attempts.
|
|
15257
15570
|
*
|
|
15258
15571
|
* @api public
|
|
15259
15572
|
*/
|
|
15260
|
-
|
|
15261
|
-
|
|
15262
|
-
this.attempts = 0;
|
|
15573
|
+
Backoff.prototype.reset = function () {
|
|
15574
|
+
this.attempts = 0;
|
|
15263
15575
|
};
|
|
15264
|
-
|
|
15265
15576
|
/**
|
|
15266
15577
|
* Set the minimum duration
|
|
15267
15578
|
*
|
|
15268
15579
|
* @api public
|
|
15269
15580
|
*/
|
|
15270
|
-
|
|
15271
|
-
|
|
15272
|
-
this.ms = min;
|
|
15581
|
+
Backoff.prototype.setMin = function (min) {
|
|
15582
|
+
this.ms = min;
|
|
15273
15583
|
};
|
|
15274
|
-
|
|
15275
15584
|
/**
|
|
15276
15585
|
* Set the maximum duration
|
|
15277
15586
|
*
|
|
15278
15587
|
* @api public
|
|
15279
15588
|
*/
|
|
15280
|
-
|
|
15281
|
-
|
|
15282
|
-
this.max = max;
|
|
15589
|
+
Backoff.prototype.setMax = function (max) {
|
|
15590
|
+
this.max = max;
|
|
15283
15591
|
};
|
|
15284
|
-
|
|
15285
15592
|
/**
|
|
15286
15593
|
* Set the jitter
|
|
15287
15594
|
*
|
|
15288
15595
|
* @api public
|
|
15289
15596
|
*/
|
|
15290
|
-
|
|
15291
|
-
|
|
15292
|
-
this.jitter = jitter;
|
|
15597
|
+
Backoff.prototype.setJitter = function (jitter) {
|
|
15598
|
+
this.jitter = jitter;
|
|
15293
15599
|
};
|
|
15294
15600
|
|
|
15295
|
-
class Manager extends
|
|
15601
|
+
class Manager extends Emitter {
|
|
15296
15602
|
constructor(uri, opts) {
|
|
15297
15603
|
var _a;
|
|
15298
15604
|
super();
|
|
@@ -15311,7 +15617,7 @@
|
|
|
15311
15617
|
this.reconnectionDelay(opts.reconnectionDelay || 1000);
|
|
15312
15618
|
this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
|
|
15313
15619
|
this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : 0.5);
|
|
15314
|
-
this.backoff = new
|
|
15620
|
+
this.backoff = new Backoff({
|
|
15315
15621
|
min: this.reconnectionDelay(),
|
|
15316
15622
|
max: this.reconnectionDelayMax(),
|
|
15317
15623
|
jitter: this.randomizationFactor(),
|
|
@@ -15477,7 +15783,12 @@
|
|
|
15477
15783
|
* @private
|
|
15478
15784
|
*/
|
|
15479
15785
|
ondata(data) {
|
|
15480
|
-
|
|
15786
|
+
try {
|
|
15787
|
+
this.decoder.add(data);
|
|
15788
|
+
}
|
|
15789
|
+
catch (e) {
|
|
15790
|
+
this.onclose("parse error", e);
|
|
15791
|
+
}
|
|
15481
15792
|
}
|
|
15482
15793
|
/**
|
|
15483
15794
|
* Called when parser fully decodes a packet.
|
|
@@ -15485,7 +15796,10 @@
|
|
|
15485
15796
|
* @private
|
|
15486
15797
|
*/
|
|
15487
15798
|
ondecoded(packet) {
|
|
15488
|
-
|
|
15799
|
+
// the nextTick call prevents an exception in a user-provided event listener from triggering a disconnection due to a "parse error"
|
|
15800
|
+
nextTick(() => {
|
|
15801
|
+
this.emitReserved("packet", packet);
|
|
15802
|
+
}, this.setTimeoutFn);
|
|
15489
15803
|
}
|
|
15490
15804
|
/**
|
|
15491
15805
|
* Called upon socket error.
|
|
@@ -15507,6 +15821,9 @@
|
|
|
15507
15821
|
socket = new Socket(this, nsp, opts);
|
|
15508
15822
|
this.nsps[nsp] = socket;
|
|
15509
15823
|
}
|
|
15824
|
+
else if (this._autoConnect && !socket.active) {
|
|
15825
|
+
socket.connect();
|
|
15826
|
+
}
|
|
15510
15827
|
return socket;
|
|
15511
15828
|
}
|
|
15512
15829
|
/**
|
|
@@ -15572,11 +15889,11 @@
|
|
|
15572
15889
|
*
|
|
15573
15890
|
* @private
|
|
15574
15891
|
*/
|
|
15575
|
-
onclose(reason) {
|
|
15892
|
+
onclose(reason, description) {
|
|
15576
15893
|
this.cleanup();
|
|
15577
15894
|
this.backoff.reset();
|
|
15578
15895
|
this._readyState = "closed";
|
|
15579
|
-
this.emitReserved("close", reason);
|
|
15896
|
+
this.emitReserved("close", reason, description);
|
|
15580
15897
|
if (this._reconnection && !this.skipReconnect) {
|
|
15581
15898
|
this.reconnect();
|
|
15582
15899
|
}
|