@stacks/blockchain-api-client 7.1.1 → 7.2.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/FaucetsApi.js.map +1 -1
- 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/apis/StackingApi.d.ts +61 -0
- package/lib/generated/apis/StackingApi.js +63 -0
- package/lib/generated/apis/StackingApi.js.map +1 -0
- package/lib/generated/apis/index.d.ts +1 -0
- package/lib/generated/apis/index.js +1 -0
- package/lib/generated/apis/index.js.map +1 -1
- package/lib/generated/models/InlineResponse403.d.ts +33 -0
- package/lib/generated/models/InlineResponse403.js +45 -0
- package/lib/generated/models/InlineResponse403.js.map +1 -0
- package/lib/generated/models/PoolDelegation.d.ts +57 -0
- package/lib/generated/models/PoolDelegation.js +53 -0
- package/lib/generated/models/PoolDelegation.js.map +1 -0
- package/lib/generated/models/PoolDelegationsResponse.d.ts +46 -0
- package/lib/generated/models/PoolDelegationsResponse.js +49 -0
- package/lib/generated/models/PoolDelegationsResponse.js.map +1 -0
- package/lib/generated/models/index.d.ts +3 -0
- package/lib/generated/models/index.js +3 -0
- package/lib/generated/models/index.js.map +1 -1
- package/lib/generated/runtime.js +1 -1
- package/lib/generated/runtime.js.map +1 -1
- package/lib/index.umd.js +1271 -766
- package/lib/index.umd.js.map +1 -1
- package/package.json +6 -6
- package/src/generated/.openapi-generator/FILES +4 -0
- package/src/generated/apis/FaucetsApi.ts +7 -4
- package/src/generated/apis/FungibleTokensApi.ts +8 -8
- package/src/generated/apis/NonFungibleTokensApi.ts +8 -8
- package/src/generated/apis/StackingApi.ts +113 -0
- package/src/generated/apis/index.ts +1 -0
- package/src/generated/models/InlineResponse403.ts +64 -0
- package/src/generated/models/PoolDelegation.ts +96 -0
- package/src/generated/models/PoolDelegationsResponse.ts +87 -0
- package/src/generated/models/index.ts +3 -0
- 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;
|
|
@@ -2674,6 +2674,35 @@
|
|
|
2674
2674
|
};
|
|
2675
2675
|
}
|
|
2676
2676
|
|
|
2677
|
+
/* tslint:disable */
|
|
2678
|
+
function InlineResponse403FromJSON(json) {
|
|
2679
|
+
return InlineResponse403FromJSONTyped(json);
|
|
2680
|
+
}
|
|
2681
|
+
function InlineResponse403FromJSONTyped(json, ignoreDiscriminator) {
|
|
2682
|
+
if (json === undefined || json === null) {
|
|
2683
|
+
return json;
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
return {
|
|
2687
|
+
'error': !exists(json, 'error') ? undefined : json['error'],
|
|
2688
|
+
'success': !exists(json, 'success') ? undefined : json['success']
|
|
2689
|
+
};
|
|
2690
|
+
}
|
|
2691
|
+
function InlineResponse403ToJSON(value) {
|
|
2692
|
+
if (value === undefined) {
|
|
2693
|
+
return undefined;
|
|
2694
|
+
}
|
|
2695
|
+
|
|
2696
|
+
if (value === null) {
|
|
2697
|
+
return null;
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
return {
|
|
2701
|
+
'error': value.error,
|
|
2702
|
+
'success': value.success
|
|
2703
|
+
};
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2677
2706
|
/* tslint:disable */
|
|
2678
2707
|
function MapEntryResponseFromJSON(json) {
|
|
2679
2708
|
return MapEntryResponseFromJSONTyped(json);
|
|
@@ -3488,6 +3517,76 @@
|
|
|
3488
3517
|
};
|
|
3489
3518
|
}
|
|
3490
3519
|
|
|
3520
|
+
/* tslint:disable */
|
|
3521
|
+
function PoolDelegationFromJSON(json) {
|
|
3522
|
+
return PoolDelegationFromJSONTyped(json);
|
|
3523
|
+
}
|
|
3524
|
+
function PoolDelegationFromJSONTyped(json, ignoreDiscriminator) {
|
|
3525
|
+
if (json === undefined || json === null) {
|
|
3526
|
+
return json;
|
|
3527
|
+
}
|
|
3528
|
+
|
|
3529
|
+
return {
|
|
3530
|
+
'stacker': json['stacker'],
|
|
3531
|
+
'pox_addr': !exists(json, 'pox_addr') ? undefined : json['pox_addr'],
|
|
3532
|
+
'amount_ustx': json['amount_ustx'],
|
|
3533
|
+
'burn_block_unlock_height': !exists(json, 'burn_block_unlock_height') ? undefined : json['burn_block_unlock_height'],
|
|
3534
|
+
'block_height': json['block_height'],
|
|
3535
|
+
'tx_id': json['tx_id']
|
|
3536
|
+
};
|
|
3537
|
+
}
|
|
3538
|
+
function PoolDelegationToJSON(value) {
|
|
3539
|
+
if (value === undefined) {
|
|
3540
|
+
return undefined;
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
if (value === null) {
|
|
3544
|
+
return null;
|
|
3545
|
+
}
|
|
3546
|
+
|
|
3547
|
+
return {
|
|
3548
|
+
'stacker': value.stacker,
|
|
3549
|
+
'pox_addr': value.pox_addr,
|
|
3550
|
+
'amount_ustx': value.amount_ustx,
|
|
3551
|
+
'burn_block_unlock_height': value.burn_block_unlock_height,
|
|
3552
|
+
'block_height': value.block_height,
|
|
3553
|
+
'tx_id': value.tx_id
|
|
3554
|
+
};
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
/* tslint:disable */
|
|
3558
|
+
function PoolDelegationsResponseFromJSON(json) {
|
|
3559
|
+
return PoolDelegationsResponseFromJSONTyped(json);
|
|
3560
|
+
}
|
|
3561
|
+
function PoolDelegationsResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
3562
|
+
if (json === undefined || json === null) {
|
|
3563
|
+
return json;
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
return {
|
|
3567
|
+
'limit': json['limit'],
|
|
3568
|
+
'offset': json['offset'],
|
|
3569
|
+
'total': json['total'],
|
|
3570
|
+
'results': json['results'].map(PoolDelegationFromJSON)
|
|
3571
|
+
};
|
|
3572
|
+
}
|
|
3573
|
+
function PoolDelegationsResponseToJSON(value) {
|
|
3574
|
+
if (value === undefined) {
|
|
3575
|
+
return undefined;
|
|
3576
|
+
}
|
|
3577
|
+
|
|
3578
|
+
if (value === null) {
|
|
3579
|
+
return null;
|
|
3580
|
+
}
|
|
3581
|
+
|
|
3582
|
+
return {
|
|
3583
|
+
'limit': value.limit,
|
|
3584
|
+
'offset': value.offset,
|
|
3585
|
+
'total': value.total,
|
|
3586
|
+
'results': value.results.map(PoolDelegationToJSON)
|
|
3587
|
+
};
|
|
3588
|
+
}
|
|
3589
|
+
|
|
3491
3590
|
/* tslint:disable */
|
|
3492
3591
|
|
|
3493
3592
|
/* eslint-disable */
|
|
@@ -7325,7 +7424,7 @@
|
|
|
7325
7424
|
}
|
|
7326
7425
|
}
|
|
7327
7426
|
/**
|
|
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.
|
|
7427
|
+
* 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
7428
|
* Get STX testnet tokens
|
|
7330
7429
|
*/
|
|
7331
7430
|
;
|
|
@@ -7366,7 +7465,7 @@
|
|
|
7366
7465
|
}
|
|
7367
7466
|
}
|
|
7368
7467
|
/**
|
|
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.
|
|
7468
|
+
* 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
7469
|
* Get STX testnet tokens
|
|
7371
7470
|
*/
|
|
7372
7471
|
;
|
|
@@ -7550,7 +7649,7 @@
|
|
|
7550
7649
|
var _proto = FungibleTokensApi.prototype;
|
|
7551
7650
|
|
|
7552
7651
|
/**
|
|
7553
|
-
* Retrieves the metadata for fungible tokens for a given contract id
|
|
7652
|
+
* **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
7653
|
* Fungible tokens metadata for contract id
|
|
7555
7654
|
*/
|
|
7556
7655
|
_proto.getContractFtMetadataRaw = function getContractFtMetadataRaw(requestParameters, initOverrides) {
|
|
@@ -7578,7 +7677,7 @@
|
|
|
7578
7677
|
}
|
|
7579
7678
|
}
|
|
7580
7679
|
/**
|
|
7581
|
-
* Retrieves the metadata for fungible tokens for a given contract id
|
|
7680
|
+
* **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
7681
|
* Fungible tokens metadata for contract id
|
|
7583
7682
|
*/
|
|
7584
7683
|
;
|
|
@@ -7595,7 +7694,7 @@
|
|
|
7595
7694
|
}
|
|
7596
7695
|
}
|
|
7597
7696
|
/**
|
|
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).
|
|
7697
|
+
* **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
7698
|
* Fungible tokens metadata list
|
|
7600
7699
|
*/
|
|
7601
7700
|
;
|
|
@@ -7630,7 +7729,7 @@
|
|
|
7630
7729
|
}
|
|
7631
7730
|
}
|
|
7632
7731
|
/**
|
|
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).
|
|
7732
|
+
* **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
7733
|
* Fungible tokens metadata list
|
|
7635
7734
|
*/
|
|
7636
7735
|
;
|
|
@@ -8729,7 +8828,7 @@
|
|
|
8729
8828
|
var _proto = NonFungibleTokensApi.prototype;
|
|
8730
8829
|
|
|
8731
8830
|
/**
|
|
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).
|
|
8831
|
+
* **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
8832
|
* Non fungible tokens metadata for contract ID
|
|
8734
8833
|
*/
|
|
8735
8834
|
_proto.getContractNftMetadataRaw = function getContractNftMetadataRaw(requestParameters, initOverrides) {
|
|
@@ -8757,7 +8856,7 @@
|
|
|
8757
8856
|
}
|
|
8758
8857
|
}
|
|
8759
8858
|
/**
|
|
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).
|
|
8859
|
+
* **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
8860
|
* Non fungible tokens metadata for contract ID
|
|
8762
8861
|
*/
|
|
8763
8862
|
;
|
|
@@ -8922,7 +9021,7 @@
|
|
|
8922
9021
|
}
|
|
8923
9022
|
}
|
|
8924
9023
|
/**
|
|
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).
|
|
9024
|
+
* **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
9025
|
* Non fungible tokens metadata list
|
|
8927
9026
|
*/
|
|
8928
9027
|
;
|
|
@@ -8957,7 +9056,7 @@
|
|
|
8957
9056
|
}
|
|
8958
9057
|
}
|
|
8959
9058
|
/**
|
|
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).
|
|
9059
|
+
* **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
9060
|
* Non fungible tokens metadata list
|
|
8962
9061
|
*/
|
|
8963
9062
|
;
|
|
@@ -10340,6 +10439,85 @@
|
|
|
10340
10439
|
return SmartContractsApi;
|
|
10341
10440
|
}(BaseAPI);
|
|
10342
10441
|
|
|
10442
|
+
/**
|
|
10443
|
+
*
|
|
10444
|
+
*/
|
|
10445
|
+
|
|
10446
|
+
var StackingApi = /*#__PURE__*/function (_runtime$BaseAPI) {
|
|
10447
|
+
_inheritsLoose(StackingApi, _runtime$BaseAPI);
|
|
10448
|
+
|
|
10449
|
+
function StackingApi() {
|
|
10450
|
+
return _runtime$BaseAPI.apply(this, arguments) || this;
|
|
10451
|
+
}
|
|
10452
|
+
|
|
10453
|
+
var _proto = StackingApi.prototype;
|
|
10454
|
+
|
|
10455
|
+
/**
|
|
10456
|
+
* Retrieves the list of stacking pool members for a given delegator principal.
|
|
10457
|
+
* Stacking pool members
|
|
10458
|
+
*/
|
|
10459
|
+
_proto.getPoolDelegationsRaw = function getPoolDelegationsRaw(requestParameters, initOverrides) {
|
|
10460
|
+
try {
|
|
10461
|
+
var _this2 = this;
|
|
10462
|
+
|
|
10463
|
+
if (requestParameters.poolPrincipal === null || requestParameters.poolPrincipal === undefined) {
|
|
10464
|
+
throw new RequiredError('poolPrincipal', 'Required parameter requestParameters.poolPrincipal was null or undefined when calling getPoolDelegations.');
|
|
10465
|
+
}
|
|
10466
|
+
|
|
10467
|
+
var queryParameters = {};
|
|
10468
|
+
|
|
10469
|
+
if (requestParameters.afterBlock !== undefined) {
|
|
10470
|
+
queryParameters['after_block'] = requestParameters.afterBlock;
|
|
10471
|
+
}
|
|
10472
|
+
|
|
10473
|
+
if (requestParameters.unanchored !== undefined) {
|
|
10474
|
+
queryParameters['unanchored'] = requestParameters.unanchored;
|
|
10475
|
+
}
|
|
10476
|
+
|
|
10477
|
+
if (requestParameters.limit !== undefined) {
|
|
10478
|
+
queryParameters['limit'] = requestParameters.limit;
|
|
10479
|
+
}
|
|
10480
|
+
|
|
10481
|
+
if (requestParameters.offset !== undefined) {
|
|
10482
|
+
queryParameters['offset'] = requestParameters.offset;
|
|
10483
|
+
}
|
|
10484
|
+
|
|
10485
|
+
var headerParameters = {};
|
|
10486
|
+
return Promise.resolve(_this2.request({
|
|
10487
|
+
path: "/extended/beta/stacking/{pool_principal}/delegations".replace("{" + "pool_principal" + "}", encodeURIComponent(String(requestParameters.poolPrincipal))),
|
|
10488
|
+
method: 'GET',
|
|
10489
|
+
headers: headerParameters,
|
|
10490
|
+
query: queryParameters
|
|
10491
|
+
}, initOverrides)).then(function (response) {
|
|
10492
|
+
return new JSONApiResponse(response, function (jsonValue) {
|
|
10493
|
+
return PoolDelegationsResponseFromJSON(jsonValue);
|
|
10494
|
+
});
|
|
10495
|
+
});
|
|
10496
|
+
} catch (e) {
|
|
10497
|
+
return Promise.reject(e);
|
|
10498
|
+
}
|
|
10499
|
+
}
|
|
10500
|
+
/**
|
|
10501
|
+
* Retrieves the list of stacking pool members for a given delegator principal.
|
|
10502
|
+
* Stacking pool members
|
|
10503
|
+
*/
|
|
10504
|
+
;
|
|
10505
|
+
|
|
10506
|
+
_proto.getPoolDelegations = function getPoolDelegations(requestParameters, initOverrides) {
|
|
10507
|
+
try {
|
|
10508
|
+
var _this4 = this;
|
|
10509
|
+
|
|
10510
|
+
return Promise.resolve(_this4.getPoolDelegationsRaw(requestParameters, initOverrides)).then(function (response) {
|
|
10511
|
+
return Promise.resolve(response.value());
|
|
10512
|
+
});
|
|
10513
|
+
} catch (e) {
|
|
10514
|
+
return Promise.reject(e);
|
|
10515
|
+
}
|
|
10516
|
+
};
|
|
10517
|
+
|
|
10518
|
+
return StackingApi;
|
|
10519
|
+
}(BaseAPI);
|
|
10520
|
+
|
|
10343
10521
|
/**
|
|
10344
10522
|
*
|
|
10345
10523
|
*/
|
|
@@ -11441,7 +11619,7 @@
|
|
|
11441
11619
|
validateMessage(object, true);
|
|
11442
11620
|
return object;
|
|
11443
11621
|
}
|
|
11444
|
-
function parse(message) {
|
|
11622
|
+
function parse$1(message) {
|
|
11445
11623
|
if (!isString(message)) {
|
|
11446
11624
|
return new JsonRpcParsed(JsonRpcError.invalidRequest(message), "invalid" /* invalid */);
|
|
11447
11625
|
}
|
|
@@ -12043,7 +12221,7 @@
|
|
|
12043
12221
|
this.eventEmitter = new eventemitter3.EventEmitter();
|
|
12044
12222
|
this.webSocket = webSocket;
|
|
12045
12223
|
webSocket.addEventListener('message', function (event) {
|
|
12046
|
-
var parsed = parse(event.data);
|
|
12224
|
+
var parsed = parse$1(event.data);
|
|
12047
12225
|
var rpcObjects = Array.isArray(parsed) ? parsed : [parsed];
|
|
12048
12226
|
rpcObjects.forEach(function (obj) {
|
|
12049
12227
|
if (obj.type === "notification"
|
|
@@ -12410,209 +12588,164 @@
|
|
|
12410
12588
|
}
|
|
12411
12589
|
}
|
|
12412
12590
|
|
|
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(']');
|
|
12591
|
+
const PACKET_TYPES = Object.create(null); // no Map = no polyfill
|
|
12592
|
+
PACKET_TYPES["open"] = "0";
|
|
12593
|
+
PACKET_TYPES["close"] = "1";
|
|
12594
|
+
PACKET_TYPES["ping"] = "2";
|
|
12595
|
+
PACKET_TYPES["pong"] = "3";
|
|
12596
|
+
PACKET_TYPES["message"] = "4";
|
|
12597
|
+
PACKET_TYPES["upgrade"] = "5";
|
|
12598
|
+
PACKET_TYPES["noop"] = "6";
|
|
12599
|
+
const PACKET_TYPES_REVERSE = Object.create(null);
|
|
12600
|
+
Object.keys(PACKET_TYPES).forEach(key => {
|
|
12601
|
+
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
|
|
12602
|
+
});
|
|
12603
|
+
const ERROR_PACKET = { type: "error", data: "parser error" };
|
|
12429
12604
|
|
|
12430
|
-
|
|
12431
|
-
|
|
12605
|
+
const withNativeBlob$1 = typeof Blob === "function" ||
|
|
12606
|
+
(typeof Blob !== "undefined" &&
|
|
12607
|
+
Object.prototype.toString.call(Blob) === "[object BlobConstructor]");
|
|
12608
|
+
const withNativeArrayBuffer$2 = typeof ArrayBuffer === "function";
|
|
12609
|
+
// ArrayBuffer.isView method is not defined in IE10
|
|
12610
|
+
const isView$1 = obj => {
|
|
12611
|
+
return typeof ArrayBuffer.isView === "function"
|
|
12612
|
+
? ArrayBuffer.isView(obj)
|
|
12613
|
+
: obj && obj.buffer instanceof ArrayBuffer;
|
|
12614
|
+
};
|
|
12615
|
+
const encodePacket = ({ type, data }, supportsBinary, callback) => {
|
|
12616
|
+
if (withNativeBlob$1 && data instanceof Blob) {
|
|
12617
|
+
if (supportsBinary) {
|
|
12618
|
+
return callback(data);
|
|
12619
|
+
}
|
|
12620
|
+
else {
|
|
12621
|
+
return encodeBlobAsBase64(data, callback);
|
|
12622
|
+
}
|
|
12432
12623
|
}
|
|
12433
|
-
|
|
12434
|
-
|
|
12435
|
-
|
|
12436
|
-
|
|
12437
|
-
|
|
12438
|
-
|
|
12439
|
-
|
|
12624
|
+
else if (withNativeArrayBuffer$2 &&
|
|
12625
|
+
(data instanceof ArrayBuffer || isView$1(data))) {
|
|
12626
|
+
if (supportsBinary) {
|
|
12627
|
+
return callback(data);
|
|
12628
|
+
}
|
|
12629
|
+
else {
|
|
12630
|
+
return encodeBlobAsBase64(new Blob([data]), callback);
|
|
12631
|
+
}
|
|
12440
12632
|
}
|
|
12633
|
+
// plain string
|
|
12634
|
+
return callback(PACKET_TYPES[type] + (data || ""));
|
|
12635
|
+
};
|
|
12636
|
+
const encodeBlobAsBase64 = (data, callback) => {
|
|
12637
|
+
const fileReader = new FileReader();
|
|
12638
|
+
fileReader.onload = function () {
|
|
12639
|
+
const content = fileReader.result.split(",")[1];
|
|
12640
|
+
callback("b" + (content || ""));
|
|
12641
|
+
};
|
|
12642
|
+
return fileReader.readAsDataURL(data);
|
|
12643
|
+
};
|
|
12441
12644
|
|
|
12442
|
-
|
|
12443
|
-
|
|
12444
|
-
|
|
12445
|
-
|
|
12446
|
-
|
|
12645
|
+
// imported from https://github.com/socketio/base64-arraybuffer
|
|
12646
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
12647
|
+
// Use a lookup table to find the index.
|
|
12648
|
+
const lookup$1 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
|
|
12649
|
+
for (let i = 0; i < chars.length; i++) {
|
|
12650
|
+
lookup$1[chars.charCodeAt(i)] = i;
|
|
12651
|
+
}
|
|
12652
|
+
const decode$1 = (base64) => {
|
|
12653
|
+
let bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
|
|
12654
|
+
if (base64[base64.length - 1] === '=') {
|
|
12655
|
+
bufferLength--;
|
|
12656
|
+
if (base64[base64.length - 2] === '=') {
|
|
12657
|
+
bufferLength--;
|
|
12658
|
+
}
|
|
12447
12659
|
}
|
|
12448
|
-
|
|
12449
|
-
|
|
12450
|
-
|
|
12451
|
-
|
|
12452
|
-
|
|
12660
|
+
const arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
|
|
12661
|
+
for (i = 0; i < len; i += 4) {
|
|
12662
|
+
encoded1 = lookup$1[base64.charCodeAt(i)];
|
|
12663
|
+
encoded2 = lookup$1[base64.charCodeAt(i + 1)];
|
|
12664
|
+
encoded3 = lookup$1[base64.charCodeAt(i + 2)];
|
|
12665
|
+
encoded4 = lookup$1[base64.charCodeAt(i + 3)];
|
|
12666
|
+
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
|
12667
|
+
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
12668
|
+
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
|
12669
|
+
}
|
|
12670
|
+
return arraybuffer;
|
|
12453
12671
|
};
|
|
12454
12672
|
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12673
|
+
const withNativeArrayBuffer$1 = typeof ArrayBuffer === "function";
|
|
12674
|
+
const decodePacket = (encodedPacket, binaryType) => {
|
|
12675
|
+
if (typeof encodedPacket !== "string") {
|
|
12676
|
+
return {
|
|
12677
|
+
type: "message",
|
|
12678
|
+
data: mapBinary(encodedPacket, binaryType)
|
|
12679
|
+
};
|
|
12461
12680
|
}
|
|
12462
|
-
|
|
12463
|
-
|
|
12681
|
+
const type = encodedPacket.charAt(0);
|
|
12682
|
+
if (type === "b") {
|
|
12683
|
+
return {
|
|
12684
|
+
type: "message",
|
|
12685
|
+
data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
|
|
12686
|
+
};
|
|
12464
12687
|
}
|
|
12465
|
-
|
|
12466
|
-
|
|
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
|
-
}
|
|
12505
|
-
}
|
|
12506
|
-
if (!/^(https?|wss?):\/\//.test(uri)) {
|
|
12507
|
-
if ("undefined" !== typeof loc) {
|
|
12508
|
-
uri = loc.protocol + "//" + uri;
|
|
12509
|
-
}
|
|
12510
|
-
else {
|
|
12511
|
-
uri = "https://" + uri;
|
|
12512
|
-
}
|
|
12513
|
-
}
|
|
12514
|
-
// parse
|
|
12515
|
-
obj = parseuri(uri);
|
|
12688
|
+
const packetType = PACKET_TYPES_REVERSE[type];
|
|
12689
|
+
if (!packetType) {
|
|
12690
|
+
return ERROR_PACKET;
|
|
12516
12691
|
}
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
}
|
|
12522
|
-
else if (/^(http|ws)s$/.test(obj.protocol)) {
|
|
12523
|
-
obj.port = "443";
|
|
12692
|
+
return encodedPacket.length > 1
|
|
12693
|
+
? {
|
|
12694
|
+
type: PACKET_TYPES_REVERSE[type],
|
|
12695
|
+
data: encodedPacket.substring(1)
|
|
12524
12696
|
}
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
obj.protocol +
|
|
12534
|
-
"://" +
|
|
12535
|
-
host +
|
|
12536
|
-
(loc && loc.port === obj.port ? "" : ":" + obj.port);
|
|
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
|
-
*/
|
|
12548
|
-
|
|
12549
|
-
try {
|
|
12550
|
-
module.exports = typeof XMLHttpRequest !== 'undefined' &&
|
|
12551
|
-
'withCredentials' in new XMLHttpRequest();
|
|
12552
|
-
} catch (err) {
|
|
12553
|
-
// if XMLHttp support is disabled in IE then it will throw
|
|
12554
|
-
// when trying to create
|
|
12555
|
-
module.exports = false;
|
|
12556
|
-
}
|
|
12557
|
-
});
|
|
12558
|
-
|
|
12559
|
-
var globalThis = (() => {
|
|
12560
|
-
if (typeof self !== "undefined") {
|
|
12561
|
-
return self;
|
|
12562
|
-
}
|
|
12563
|
-
else if (typeof window !== "undefined") {
|
|
12564
|
-
return window;
|
|
12697
|
+
: {
|
|
12698
|
+
type: PACKET_TYPES_REVERSE[type]
|
|
12699
|
+
};
|
|
12700
|
+
};
|
|
12701
|
+
const decodeBase64Packet = (data, binaryType) => {
|
|
12702
|
+
if (withNativeArrayBuffer$1) {
|
|
12703
|
+
const decoded = decode$1(data);
|
|
12704
|
+
return mapBinary(decoded, binaryType);
|
|
12565
12705
|
}
|
|
12566
12706
|
else {
|
|
12567
|
-
return
|
|
12568
|
-
}
|
|
12569
|
-
})();
|
|
12570
|
-
|
|
12571
|
-
// browser shim for xmlhttprequest module
|
|
12572
|
-
function XMLHttpRequest$1 (opts) {
|
|
12573
|
-
const xdomain = opts.xdomain;
|
|
12574
|
-
// XMLHttpRequest can be disabled on IE
|
|
12575
|
-
try {
|
|
12576
|
-
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCors)) {
|
|
12577
|
-
return new XMLHttpRequest();
|
|
12578
|
-
}
|
|
12707
|
+
return { base64: true, data }; // fallback for old browsers
|
|
12579
12708
|
}
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12709
|
+
};
|
|
12710
|
+
const mapBinary = (data, binaryType) => {
|
|
12711
|
+
switch (binaryType) {
|
|
12712
|
+
case "blob":
|
|
12713
|
+
return data instanceof ArrayBuffer ? new Blob([data]) : data;
|
|
12714
|
+
case "arraybuffer":
|
|
12715
|
+
default:
|
|
12716
|
+
return data; // assuming the data is already an ArrayBuffer
|
|
12586
12717
|
}
|
|
12587
|
-
}
|
|
12718
|
+
};
|
|
12588
12719
|
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
|
|
12592
|
-
|
|
12720
|
+
const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
|
|
12721
|
+
const encodePayload = (packets, callback) => {
|
|
12722
|
+
// some packets may be added to the array while encoding, so the initial length must be saved
|
|
12723
|
+
const length = packets.length;
|
|
12724
|
+
const encodedPackets = new Array(length);
|
|
12725
|
+
let count = 0;
|
|
12726
|
+
packets.forEach((packet, i) => {
|
|
12727
|
+
// force base64 encoding for binary packets
|
|
12728
|
+
encodePacket(packet, false, encodedPacket => {
|
|
12729
|
+
encodedPackets[i] = encodedPacket;
|
|
12730
|
+
if (++count === length) {
|
|
12731
|
+
callback(encodedPackets.join(SEPARATOR));
|
|
12732
|
+
}
|
|
12733
|
+
});
|
|
12734
|
+
});
|
|
12735
|
+
};
|
|
12736
|
+
const decodePayload = (encodedPayload, binaryType) => {
|
|
12737
|
+
const encodedPackets = encodedPayload.split(SEPARATOR);
|
|
12738
|
+
const packets = [];
|
|
12739
|
+
for (let i = 0; i < encodedPackets.length; i++) {
|
|
12740
|
+
const decodedPacket = decodePacket(encodedPackets[i], binaryType);
|
|
12741
|
+
packets.push(decodedPacket);
|
|
12742
|
+
if (decodedPacket.type === "error") {
|
|
12743
|
+
break;
|
|
12593
12744
|
}
|
|
12594
|
-
return acc;
|
|
12595
|
-
}, {});
|
|
12596
|
-
}
|
|
12597
|
-
// Keep a reference to the real timeout functions so they can be used when overridden
|
|
12598
|
-
const NATIVE_SET_TIMEOUT = setTimeout;
|
|
12599
|
-
const NATIVE_CLEAR_TIMEOUT = clearTimeout;
|
|
12600
|
-
function installTimerFunctions(obj, opts) {
|
|
12601
|
-
if (opts.useNativeTimers) {
|
|
12602
|
-
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThis);
|
|
12603
|
-
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThis);
|
|
12604
|
-
}
|
|
12605
|
-
else {
|
|
12606
|
-
obj.setTimeoutFn = setTimeout.bind(globalThis);
|
|
12607
|
-
obj.clearTimeoutFn = clearTimeout.bind(globalThis);
|
|
12608
12745
|
}
|
|
12609
|
-
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
* Expose `Emitter`.
|
|
12613
|
-
*/
|
|
12614
|
-
|
|
12615
|
-
var Emitter_1 = Emitter;
|
|
12746
|
+
return packets;
|
|
12747
|
+
};
|
|
12748
|
+
const protocol$1 = 4;
|
|
12616
12749
|
|
|
12617
12750
|
/**
|
|
12618
12751
|
* Initialize a new `Emitter`.
|
|
@@ -12784,175 +12917,84 @@
|
|
|
12784
12917
|
return !! this.listeners(event).length;
|
|
12785
12918
|
};
|
|
12786
12919
|
|
|
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
|
-
}
|
|
12920
|
+
const globalThisShim = (() => {
|
|
12921
|
+
if (typeof self !== "undefined") {
|
|
12922
|
+
return self;
|
|
12828
12923
|
}
|
|
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
|
-
}
|
|
12924
|
+
else if (typeof window !== "undefined") {
|
|
12925
|
+
return window;
|
|
12859
12926
|
}
|
|
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);
|
|
12927
|
+
else {
|
|
12928
|
+
return Function("return this")();
|
|
12869
12929
|
}
|
|
12870
|
-
|
|
12871
|
-
};
|
|
12930
|
+
})();
|
|
12872
12931
|
|
|
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)
|
|
12932
|
+
function pick(obj, ...attr) {
|
|
12933
|
+
return attr.reduce((acc, k) => {
|
|
12934
|
+
if (obj.hasOwnProperty(k)) {
|
|
12935
|
+
acc[k] = obj[k];
|
|
12896
12936
|
}
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
const
|
|
12902
|
-
|
|
12903
|
-
|
|
12904
|
-
|
|
12937
|
+
return acc;
|
|
12938
|
+
}, {});
|
|
12939
|
+
}
|
|
12940
|
+
// Keep a reference to the real timeout functions so they can be used when overridden
|
|
12941
|
+
const NATIVE_SET_TIMEOUT = globalThisShim.setTimeout;
|
|
12942
|
+
const NATIVE_CLEAR_TIMEOUT = globalThisShim.clearTimeout;
|
|
12943
|
+
function installTimerFunctions(obj, opts) {
|
|
12944
|
+
if (opts.useNativeTimers) {
|
|
12945
|
+
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThisShim);
|
|
12946
|
+
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThisShim);
|
|
12905
12947
|
}
|
|
12906
12948
|
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;
|
|
12949
|
+
obj.setTimeoutFn = globalThisShim.setTimeout.bind(globalThisShim);
|
|
12950
|
+
obj.clearTimeoutFn = globalThisShim.clearTimeout.bind(globalThisShim);
|
|
12951
|
+
}
|
|
12952
|
+
}
|
|
12953
|
+
// base64 encoded buffers are about 33% bigger (https://en.wikipedia.org/wiki/Base64)
|
|
12954
|
+
const BASE64_OVERHEAD = 1.33;
|
|
12955
|
+
// we could also have used `new Blob([obj]).size`, but it isn't supported in IE9
|
|
12956
|
+
function byteLength(obj) {
|
|
12957
|
+
if (typeof obj === "string") {
|
|
12958
|
+
return utf8Length(obj);
|
|
12959
|
+
}
|
|
12960
|
+
// arraybuffer or blob
|
|
12961
|
+
return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
|
|
12962
|
+
}
|
|
12963
|
+
function utf8Length(str) {
|
|
12964
|
+
let c = 0, length = 0;
|
|
12965
|
+
for (let i = 0, l = str.length; i < l; i++) {
|
|
12966
|
+
c = str.charCodeAt(i);
|
|
12967
|
+
if (c < 0x80) {
|
|
12968
|
+
length += 1;
|
|
12969
|
+
}
|
|
12970
|
+
else if (c < 0x800) {
|
|
12971
|
+
length += 2;
|
|
12972
|
+
}
|
|
12973
|
+
else if (c < 0xd800 || c >= 0xe000) {
|
|
12974
|
+
length += 3;
|
|
12975
|
+
}
|
|
12976
|
+
else {
|
|
12977
|
+
i++;
|
|
12978
|
+
length += 4;
|
|
12944
12979
|
}
|
|
12945
12980
|
}
|
|
12946
|
-
return
|
|
12947
|
-
}
|
|
12948
|
-
const protocol$1 = 4;
|
|
12981
|
+
return length;
|
|
12982
|
+
}
|
|
12949
12983
|
|
|
12950
|
-
class
|
|
12984
|
+
class TransportError extends Error {
|
|
12985
|
+
constructor(reason, description, context) {
|
|
12986
|
+
super(reason);
|
|
12987
|
+
this.description = description;
|
|
12988
|
+
this.context = context;
|
|
12989
|
+
this.type = "TransportError";
|
|
12990
|
+
}
|
|
12991
|
+
}
|
|
12992
|
+
class Transport extends Emitter {
|
|
12951
12993
|
/**
|
|
12952
12994
|
* Transport abstract constructor.
|
|
12953
12995
|
*
|
|
12954
|
-
* @param {Object} options
|
|
12955
|
-
* @
|
|
12996
|
+
* @param {Object} opts - options
|
|
12997
|
+
* @protected
|
|
12956
12998
|
*/
|
|
12957
12999
|
constructor(opts) {
|
|
12958
13000
|
super();
|
|
@@ -12960,44 +13002,34 @@
|
|
|
12960
13002
|
installTimerFunctions(this, opts);
|
|
12961
13003
|
this.opts = opts;
|
|
12962
13004
|
this.query = opts.query;
|
|
12963
|
-
this.readyState = "";
|
|
12964
13005
|
this.socket = opts.socket;
|
|
12965
13006
|
}
|
|
12966
13007
|
/**
|
|
12967
13008
|
* Emits an error.
|
|
12968
13009
|
*
|
|
12969
|
-
* @param {String}
|
|
13010
|
+
* @param {String} reason
|
|
13011
|
+
* @param description
|
|
13012
|
+
* @param context - the error context
|
|
12970
13013
|
* @return {Transport} for chaining
|
|
12971
|
-
* @
|
|
13014
|
+
* @protected
|
|
12972
13015
|
*/
|
|
12973
|
-
onError(
|
|
12974
|
-
|
|
12975
|
-
// @ts-ignore
|
|
12976
|
-
err.type = "TransportError";
|
|
12977
|
-
// @ts-ignore
|
|
12978
|
-
err.description = desc;
|
|
12979
|
-
super.emit("error", err);
|
|
13016
|
+
onError(reason, description, context) {
|
|
13017
|
+
super.emitReserved("error", new TransportError(reason, description, context));
|
|
12980
13018
|
return this;
|
|
12981
13019
|
}
|
|
12982
13020
|
/**
|
|
12983
13021
|
* Opens the transport.
|
|
12984
|
-
*
|
|
12985
|
-
* @api public
|
|
12986
13022
|
*/
|
|
12987
13023
|
open() {
|
|
12988
|
-
|
|
12989
|
-
|
|
12990
|
-
this.doOpen();
|
|
12991
|
-
}
|
|
13024
|
+
this.readyState = "opening";
|
|
13025
|
+
this.doOpen();
|
|
12992
13026
|
return this;
|
|
12993
13027
|
}
|
|
12994
13028
|
/**
|
|
12995
13029
|
* Closes the transport.
|
|
12996
|
-
*
|
|
12997
|
-
* @api public
|
|
12998
13030
|
*/
|
|
12999
13031
|
close() {
|
|
13000
|
-
if ("opening"
|
|
13032
|
+
if (this.readyState === "opening" || this.readyState === "open") {
|
|
13001
13033
|
this.doClose();
|
|
13002
13034
|
this.onClose();
|
|
13003
13035
|
}
|
|
@@ -13007,28 +13039,27 @@
|
|
|
13007
13039
|
* Sends multiple packets.
|
|
13008
13040
|
*
|
|
13009
13041
|
* @param {Array} packets
|
|
13010
|
-
* @api public
|
|
13011
13042
|
*/
|
|
13012
13043
|
send(packets) {
|
|
13013
|
-
if ("open"
|
|
13044
|
+
if (this.readyState === "open") {
|
|
13014
13045
|
this.write(packets);
|
|
13015
13046
|
}
|
|
13016
13047
|
}
|
|
13017
13048
|
/**
|
|
13018
13049
|
* Called upon open
|
|
13019
13050
|
*
|
|
13020
|
-
* @
|
|
13051
|
+
* @protected
|
|
13021
13052
|
*/
|
|
13022
13053
|
onOpen() {
|
|
13023
13054
|
this.readyState = "open";
|
|
13024
13055
|
this.writable = true;
|
|
13025
|
-
super.
|
|
13056
|
+
super.emitReserved("open");
|
|
13026
13057
|
}
|
|
13027
13058
|
/**
|
|
13028
13059
|
* Called with data.
|
|
13029
13060
|
*
|
|
13030
13061
|
* @param {String} data
|
|
13031
|
-
* @
|
|
13062
|
+
* @protected
|
|
13032
13063
|
*/
|
|
13033
13064
|
onData(data) {
|
|
13034
13065
|
const packet = decodePacket(data, this.socket.binaryType);
|
|
@@ -13037,64 +13068,46 @@
|
|
|
13037
13068
|
/**
|
|
13038
13069
|
* Called with a decoded packet.
|
|
13039
13070
|
*
|
|
13040
|
-
* @
|
|
13071
|
+
* @protected
|
|
13041
13072
|
*/
|
|
13042
13073
|
onPacket(packet) {
|
|
13043
|
-
super.
|
|
13074
|
+
super.emitReserved("packet", packet);
|
|
13044
13075
|
}
|
|
13045
13076
|
/**
|
|
13046
13077
|
* Called upon close.
|
|
13047
13078
|
*
|
|
13048
|
-
* @
|
|
13079
|
+
* @protected
|
|
13049
13080
|
*/
|
|
13050
|
-
onClose() {
|
|
13081
|
+
onClose(details) {
|
|
13051
13082
|
this.readyState = "closed";
|
|
13052
|
-
super.
|
|
13083
|
+
super.emitReserved("close", details);
|
|
13053
13084
|
}
|
|
13085
|
+
/**
|
|
13086
|
+
* Pauses the transport, in order not to lose packets during an upgrade.
|
|
13087
|
+
*
|
|
13088
|
+
* @param onPause
|
|
13089
|
+
*/
|
|
13090
|
+
pause(onPause) { }
|
|
13054
13091
|
}
|
|
13055
13092
|
|
|
13056
|
-
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
, seed = 0
|
|
13060
|
-
, i = 0
|
|
13061
|
-
, prev;
|
|
13062
|
-
|
|
13093
|
+
// imported from https://github.com/unshiftio/yeast
|
|
13094
|
+
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split(''), length = 64, map = {};
|
|
13095
|
+
let seed = 0, i = 0, prev;
|
|
13063
13096
|
/**
|
|
13064
13097
|
* Return a string representing the specified number.
|
|
13065
13098
|
*
|
|
13066
13099
|
* @param {Number} num The number to convert.
|
|
13067
13100
|
* @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;
|
|
13101
|
+
* @api public
|
|
13102
|
+
*/
|
|
13103
|
+
function encode$1(num) {
|
|
13104
|
+
let encoded = '';
|
|
13105
|
+
do {
|
|
13106
|
+
encoded = alphabet[num % length] + encoded;
|
|
13107
|
+
num = Math.floor(num / length);
|
|
13108
|
+
} while (num > 0);
|
|
13109
|
+
return encoded;
|
|
13096
13110
|
}
|
|
13097
|
-
|
|
13098
13111
|
/**
|
|
13099
13112
|
* Yeast: A tiny growing id generator.
|
|
13100
13113
|
*
|
|
@@ -13102,24 +13115,18 @@
|
|
|
13102
13115
|
* @api public
|
|
13103
13116
|
*/
|
|
13104
13117
|
function yeast() {
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
|
|
13118
|
+
const now = encode$1(+new Date());
|
|
13119
|
+
if (now !== prev)
|
|
13120
|
+
return seed = 0, prev = now;
|
|
13121
|
+
return now + '.' + encode$1(seed++);
|
|
13109
13122
|
}
|
|
13110
|
-
|
|
13111
13123
|
//
|
|
13112
13124
|
// Map each character to its index.
|
|
13113
13125
|
//
|
|
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;
|
|
13126
|
+
for (; i < length; i++)
|
|
13127
|
+
map[alphabet[i]] = i;
|
|
13122
13128
|
|
|
13129
|
+
// imported from https://github.com/galkn/querystring
|
|
13123
13130
|
/**
|
|
13124
13131
|
* Compiles a querystring
|
|
13125
13132
|
* Returns string representation of the object
|
|
@@ -13127,49 +13134,99 @@
|
|
|
13127
13134
|
* @param {Object}
|
|
13128
13135
|
* @api private
|
|
13129
13136
|
*/
|
|
13130
|
-
|
|
13131
|
-
|
|
13132
|
-
|
|
13133
|
-
|
|
13134
|
-
|
|
13135
|
-
|
|
13136
|
-
|
|
13137
|
+
function encode(obj) {
|
|
13138
|
+
let str = '';
|
|
13139
|
+
for (let i in obj) {
|
|
13140
|
+
if (obj.hasOwnProperty(i)) {
|
|
13141
|
+
if (str.length)
|
|
13142
|
+
str += '&';
|
|
13143
|
+
str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
|
|
13144
|
+
}
|
|
13137
13145
|
}
|
|
13138
|
-
|
|
13139
|
-
|
|
13140
|
-
return str;
|
|
13141
|
-
};
|
|
13142
|
-
|
|
13146
|
+
return str;
|
|
13147
|
+
}
|
|
13143
13148
|
/**
|
|
13144
13149
|
* Parses a simple querystring into an object
|
|
13145
13150
|
*
|
|
13146
13151
|
* @param {String} qs
|
|
13147
13152
|
* @api private
|
|
13148
13153
|
*/
|
|
13154
|
+
function decode(qs) {
|
|
13155
|
+
let qry = {};
|
|
13156
|
+
let pairs = qs.split('&');
|
|
13157
|
+
for (let i = 0, l = pairs.length; i < l; i++) {
|
|
13158
|
+
let pair = pairs[i].split('=');
|
|
13159
|
+
qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
|
|
13160
|
+
}
|
|
13161
|
+
return qry;
|
|
13162
|
+
}
|
|
13149
13163
|
|
|
13150
|
-
|
|
13151
|
-
|
|
13152
|
-
|
|
13153
|
-
|
|
13154
|
-
|
|
13155
|
-
|
|
13156
|
-
|
|
13157
|
-
|
|
13158
|
-
|
|
13164
|
+
// imported from https://github.com/component/has-cors
|
|
13165
|
+
let value = false;
|
|
13166
|
+
try {
|
|
13167
|
+
value = typeof XMLHttpRequest !== 'undefined' &&
|
|
13168
|
+
'withCredentials' in new XMLHttpRequest();
|
|
13169
|
+
}
|
|
13170
|
+
catch (err) {
|
|
13171
|
+
// if XMLHttp support is disabled in IE then it will throw
|
|
13172
|
+
// when trying to create
|
|
13173
|
+
}
|
|
13174
|
+
const hasCORS = value;
|
|
13159
13175
|
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
|
|
13176
|
+
// browser shim for xmlhttprequest module
|
|
13177
|
+
function XHR(opts) {
|
|
13178
|
+
const xdomain = opts.xdomain;
|
|
13179
|
+
// XMLHttpRequest can be disabled on IE
|
|
13180
|
+
try {
|
|
13181
|
+
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
|
|
13182
|
+
return new XMLHttpRequest();
|
|
13183
|
+
}
|
|
13184
|
+
}
|
|
13185
|
+
catch (e) { }
|
|
13186
|
+
if (!xdomain) {
|
|
13187
|
+
try {
|
|
13188
|
+
return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
13189
|
+
}
|
|
13190
|
+
catch (e) { }
|
|
13191
|
+
}
|
|
13192
|
+
}
|
|
13164
13193
|
|
|
13194
|
+
function empty() { }
|
|
13195
|
+
const hasXHR2 = (function () {
|
|
13196
|
+
const xhr = new XHR({
|
|
13197
|
+
xdomain: false,
|
|
13198
|
+
});
|
|
13199
|
+
return null != xhr.responseType;
|
|
13200
|
+
})();
|
|
13165
13201
|
class Polling extends Transport {
|
|
13166
|
-
constructor() {
|
|
13167
|
-
super(...arguments);
|
|
13168
|
-
this.polling = false;
|
|
13169
|
-
}
|
|
13170
13202
|
/**
|
|
13171
|
-
*
|
|
13203
|
+
* XHR Polling constructor.
|
|
13204
|
+
*
|
|
13205
|
+
* @param {Object} opts
|
|
13206
|
+
* @package
|
|
13172
13207
|
*/
|
|
13208
|
+
constructor(opts) {
|
|
13209
|
+
super(opts);
|
|
13210
|
+
this.polling = false;
|
|
13211
|
+
if (typeof location !== "undefined") {
|
|
13212
|
+
const isSSL = "https:" === location.protocol;
|
|
13213
|
+
let port = location.port;
|
|
13214
|
+
// some user agents have empty `location.port`
|
|
13215
|
+
if (!port) {
|
|
13216
|
+
port = isSSL ? "443" : "80";
|
|
13217
|
+
}
|
|
13218
|
+
this.xd =
|
|
13219
|
+
(typeof location !== "undefined" &&
|
|
13220
|
+
opts.hostname !== location.hostname) ||
|
|
13221
|
+
port !== opts.port;
|
|
13222
|
+
this.xs = opts.secure !== isSSL;
|
|
13223
|
+
}
|
|
13224
|
+
/**
|
|
13225
|
+
* XHR supports binary
|
|
13226
|
+
*/
|
|
13227
|
+
const forceBase64 = opts && opts.forceBase64;
|
|
13228
|
+
this.supportsBinary = hasXHR2 && !forceBase64;
|
|
13229
|
+
}
|
|
13173
13230
|
get name() {
|
|
13174
13231
|
return "polling";
|
|
13175
13232
|
}
|
|
@@ -13177,7 +13234,7 @@
|
|
|
13177
13234
|
* Opens the socket (triggers polling). We write a PING message to determine
|
|
13178
13235
|
* when the transport is open.
|
|
13179
13236
|
*
|
|
13180
|
-
* @
|
|
13237
|
+
* @protected
|
|
13181
13238
|
*/
|
|
13182
13239
|
doOpen() {
|
|
13183
13240
|
this.poll();
|
|
@@ -13185,8 +13242,8 @@
|
|
|
13185
13242
|
/**
|
|
13186
13243
|
* Pauses polling.
|
|
13187
13244
|
*
|
|
13188
|
-
* @param {Function} callback upon buffers are flushed and transport is paused
|
|
13189
|
-
* @
|
|
13245
|
+
* @param {Function} onPause - callback upon buffers are flushed and transport is paused
|
|
13246
|
+
* @package
|
|
13190
13247
|
*/
|
|
13191
13248
|
pause(onPause) {
|
|
13192
13249
|
this.readyState = "pausing";
|
|
@@ -13216,27 +13273,27 @@
|
|
|
13216
13273
|
/**
|
|
13217
13274
|
* Starts polling cycle.
|
|
13218
13275
|
*
|
|
13219
|
-
* @
|
|
13276
|
+
* @private
|
|
13220
13277
|
*/
|
|
13221
13278
|
poll() {
|
|
13222
13279
|
this.polling = true;
|
|
13223
13280
|
this.doPoll();
|
|
13224
|
-
this.
|
|
13281
|
+
this.emitReserved("poll");
|
|
13225
13282
|
}
|
|
13226
13283
|
/**
|
|
13227
13284
|
* Overloads onData to detect payloads.
|
|
13228
13285
|
*
|
|
13229
|
-
* @
|
|
13286
|
+
* @protected
|
|
13230
13287
|
*/
|
|
13231
13288
|
onData(data) {
|
|
13232
|
-
const callback = packet => {
|
|
13289
|
+
const callback = (packet) => {
|
|
13233
13290
|
// if its the first message we consider the transport open
|
|
13234
13291
|
if ("opening" === this.readyState && packet.type === "open") {
|
|
13235
13292
|
this.onOpen();
|
|
13236
13293
|
}
|
|
13237
13294
|
// if its a close packet, we close the ongoing requests
|
|
13238
13295
|
if ("close" === packet.type) {
|
|
13239
|
-
this.onClose();
|
|
13296
|
+
this.onClose({ description: "transport closed by the server" });
|
|
13240
13297
|
return false;
|
|
13241
13298
|
}
|
|
13242
13299
|
// otherwise bypass onData and handle the message
|
|
@@ -13248,7 +13305,7 @@
|
|
|
13248
13305
|
if ("closed" !== this.readyState) {
|
|
13249
13306
|
// if we got data we're not polling
|
|
13250
13307
|
this.polling = false;
|
|
13251
|
-
this.
|
|
13308
|
+
this.emitReserved("pollComplete");
|
|
13252
13309
|
if ("open" === this.readyState) {
|
|
13253
13310
|
this.poll();
|
|
13254
13311
|
}
|
|
@@ -13257,7 +13314,7 @@
|
|
|
13257
13314
|
/**
|
|
13258
13315
|
* For polling, send a close packet.
|
|
13259
13316
|
*
|
|
13260
|
-
* @
|
|
13317
|
+
* @protected
|
|
13261
13318
|
*/
|
|
13262
13319
|
doClose() {
|
|
13263
13320
|
const close = () => {
|
|
@@ -13275,23 +13332,22 @@
|
|
|
13275
13332
|
/**
|
|
13276
13333
|
* Writes a packets payload.
|
|
13277
13334
|
*
|
|
13278
|
-
* @param {Array} data packets
|
|
13279
|
-
* @
|
|
13280
|
-
* @api private
|
|
13335
|
+
* @param {Array} packets - data packets
|
|
13336
|
+
* @protected
|
|
13281
13337
|
*/
|
|
13282
13338
|
write(packets) {
|
|
13283
13339
|
this.writable = false;
|
|
13284
|
-
encodePayload(packets, data => {
|
|
13340
|
+
encodePayload(packets, (data) => {
|
|
13285
13341
|
this.doWrite(data, () => {
|
|
13286
13342
|
this.writable = true;
|
|
13287
|
-
this.
|
|
13343
|
+
this.emitReserved("drain");
|
|
13288
13344
|
});
|
|
13289
13345
|
});
|
|
13290
13346
|
}
|
|
13291
13347
|
/**
|
|
13292
13348
|
* Generates uri for connection.
|
|
13293
13349
|
*
|
|
13294
|
-
* @
|
|
13350
|
+
* @private
|
|
13295
13351
|
*/
|
|
13296
13352
|
uri() {
|
|
13297
13353
|
let query = this.query || {};
|
|
@@ -13299,7 +13355,7 @@
|
|
|
13299
13355
|
let port = "";
|
|
13300
13356
|
// cache busting is forced
|
|
13301
13357
|
if (false !== this.opts.timestampRequests) {
|
|
13302
|
-
query[this.opts.timestampParam] =
|
|
13358
|
+
query[this.opts.timestampParam] = yeast();
|
|
13303
13359
|
}
|
|
13304
13360
|
if (!this.supportsBinary && !query.sid) {
|
|
13305
13361
|
query.b64 = 1;
|
|
@@ -13310,7 +13366,7 @@
|
|
|
13310
13366
|
("http" === schema && Number(this.opts.port) !== 80))) {
|
|
13311
13367
|
port = ":" + this.opts.port;
|
|
13312
13368
|
}
|
|
13313
|
-
const encodedQuery =
|
|
13369
|
+
const encodedQuery = encode(query);
|
|
13314
13370
|
const ipv6 = this.opts.hostname.indexOf(":") !== -1;
|
|
13315
13371
|
return (schema +
|
|
13316
13372
|
"://" +
|
|
@@ -13319,52 +13375,11 @@
|
|
|
13319
13375
|
this.opts.path +
|
|
13320
13376
|
(encodedQuery.length ? "?" + encodedQuery : ""));
|
|
13321
13377
|
}
|
|
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
13378
|
/**
|
|
13364
13379
|
* Creates a request.
|
|
13365
13380
|
*
|
|
13366
13381
|
* @param {String} method
|
|
13367
|
-
* @
|
|
13382
|
+
* @private
|
|
13368
13383
|
*/
|
|
13369
13384
|
request(opts = {}) {
|
|
13370
13385
|
Object.assign(opts, { xd: this.xd, xs: this.xs }, this.opts);
|
|
@@ -13375,38 +13390,38 @@
|
|
|
13375
13390
|
*
|
|
13376
13391
|
* @param {String} data to send.
|
|
13377
13392
|
* @param {Function} called upon flush.
|
|
13378
|
-
* @
|
|
13393
|
+
* @private
|
|
13379
13394
|
*/
|
|
13380
13395
|
doWrite(data, fn) {
|
|
13381
13396
|
const req = this.request({
|
|
13382
13397
|
method: "POST",
|
|
13383
|
-
data: data
|
|
13398
|
+
data: data,
|
|
13384
13399
|
});
|
|
13385
13400
|
req.on("success", fn);
|
|
13386
|
-
req.on("error",
|
|
13387
|
-
this.onError("xhr post error",
|
|
13401
|
+
req.on("error", (xhrStatus, context) => {
|
|
13402
|
+
this.onError("xhr post error", xhrStatus, context);
|
|
13388
13403
|
});
|
|
13389
13404
|
}
|
|
13390
13405
|
/**
|
|
13391
13406
|
* Starts a poll cycle.
|
|
13392
13407
|
*
|
|
13393
|
-
* @
|
|
13408
|
+
* @private
|
|
13394
13409
|
*/
|
|
13395
13410
|
doPoll() {
|
|
13396
13411
|
const req = this.request();
|
|
13397
13412
|
req.on("data", this.onData.bind(this));
|
|
13398
|
-
req.on("error",
|
|
13399
|
-
this.onError("xhr poll error",
|
|
13413
|
+
req.on("error", (xhrStatus, context) => {
|
|
13414
|
+
this.onError("xhr poll error", xhrStatus, context);
|
|
13400
13415
|
});
|
|
13401
13416
|
this.pollXhr = req;
|
|
13402
13417
|
}
|
|
13403
13418
|
}
|
|
13404
|
-
class Request extends
|
|
13419
|
+
class Request extends Emitter {
|
|
13405
13420
|
/**
|
|
13406
13421
|
* Request constructor
|
|
13407
13422
|
*
|
|
13408
13423
|
* @param {Object} options
|
|
13409
|
-
* @
|
|
13424
|
+
* @package
|
|
13410
13425
|
*/
|
|
13411
13426
|
constructor(uri, opts) {
|
|
13412
13427
|
super();
|
|
@@ -13421,13 +13436,13 @@
|
|
|
13421
13436
|
/**
|
|
13422
13437
|
* Creates the XHR object and sends the request.
|
|
13423
13438
|
*
|
|
13424
|
-
* @
|
|
13439
|
+
* @private
|
|
13425
13440
|
*/
|
|
13426
13441
|
create() {
|
|
13427
13442
|
const opts = pick(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
13428
13443
|
opts.xdomain = !!this.opts.xd;
|
|
13429
13444
|
opts.xscheme = !!this.opts.xs;
|
|
13430
|
-
const xhr = (this.xhr = new
|
|
13445
|
+
const xhr = (this.xhr = new XHR(opts));
|
|
13431
13446
|
try {
|
|
13432
13447
|
xhr.open(this.method, this.uri, this.async);
|
|
13433
13448
|
try {
|
|
@@ -13488,37 +13503,19 @@
|
|
|
13488
13503
|
Request.requests[this.index] = this;
|
|
13489
13504
|
}
|
|
13490
13505
|
}
|
|
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
13506
|
/**
|
|
13510
13507
|
* Called upon error.
|
|
13511
13508
|
*
|
|
13512
|
-
* @
|
|
13509
|
+
* @private
|
|
13513
13510
|
*/
|
|
13514
13511
|
onError(err) {
|
|
13515
|
-
this.
|
|
13512
|
+
this.emitReserved("error", err, this.xhr);
|
|
13516
13513
|
this.cleanup(true);
|
|
13517
13514
|
}
|
|
13518
13515
|
/**
|
|
13519
13516
|
* Cleans up house.
|
|
13520
13517
|
*
|
|
13521
|
-
* @
|
|
13518
|
+
* @private
|
|
13522
13519
|
*/
|
|
13523
13520
|
cleanup(fromError) {
|
|
13524
13521
|
if ("undefined" === typeof this.xhr || null === this.xhr) {
|
|
@@ -13539,18 +13536,20 @@
|
|
|
13539
13536
|
/**
|
|
13540
13537
|
* Called upon load.
|
|
13541
13538
|
*
|
|
13542
|
-
* @
|
|
13539
|
+
* @private
|
|
13543
13540
|
*/
|
|
13544
13541
|
onLoad() {
|
|
13545
13542
|
const data = this.xhr.responseText;
|
|
13546
13543
|
if (data !== null) {
|
|
13547
|
-
this.
|
|
13544
|
+
this.emitReserved("data", data);
|
|
13545
|
+
this.emitReserved("success");
|
|
13546
|
+
this.cleanup();
|
|
13548
13547
|
}
|
|
13549
13548
|
}
|
|
13550
13549
|
/**
|
|
13551
13550
|
* Aborts the request.
|
|
13552
13551
|
*
|
|
13553
|
-
* @
|
|
13552
|
+
* @package
|
|
13554
13553
|
*/
|
|
13555
13554
|
abort() {
|
|
13556
13555
|
this.cleanup();
|
|
@@ -13570,7 +13569,7 @@
|
|
|
13570
13569
|
attachEvent("onunload", unloadHandler);
|
|
13571
13570
|
}
|
|
13572
13571
|
else if (typeof addEventListener === "function") {
|
|
13573
|
-
const terminationEvent = "onpagehide" in
|
|
13572
|
+
const terminationEvent = "onpagehide" in globalThisShim ? "pagehide" : "unload";
|
|
13574
13573
|
addEventListener(terminationEvent, unloadHandler, false);
|
|
13575
13574
|
}
|
|
13576
13575
|
}
|
|
@@ -13585,13 +13584,13 @@
|
|
|
13585
13584
|
const nextTick = (() => {
|
|
13586
13585
|
const isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
|
|
13587
13586
|
if (isPromiseAvailable) {
|
|
13588
|
-
return cb => Promise.resolve().then(cb);
|
|
13587
|
+
return (cb) => Promise.resolve().then(cb);
|
|
13589
13588
|
}
|
|
13590
13589
|
else {
|
|
13591
13590
|
return (cb, setTimeoutFn) => setTimeoutFn(cb, 0);
|
|
13592
13591
|
}
|
|
13593
13592
|
})();
|
|
13594
|
-
const WebSocket$1 =
|
|
13593
|
+
const WebSocket$1 = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
|
|
13595
13594
|
const usingBrowserWebSocket = true;
|
|
13596
13595
|
const defaultBinaryType = "arraybuffer";
|
|
13597
13596
|
|
|
@@ -13603,26 +13602,16 @@
|
|
|
13603
13602
|
/**
|
|
13604
13603
|
* WebSocket transport constructor.
|
|
13605
13604
|
*
|
|
13606
|
-
* @
|
|
13607
|
-
* @
|
|
13605
|
+
* @param {Object} opts - connection options
|
|
13606
|
+
* @protected
|
|
13608
13607
|
*/
|
|
13609
13608
|
constructor(opts) {
|
|
13610
13609
|
super(opts);
|
|
13611
13610
|
this.supportsBinary = !opts.forceBase64;
|
|
13612
13611
|
}
|
|
13613
|
-
/**
|
|
13614
|
-
* Transport name.
|
|
13615
|
-
*
|
|
13616
|
-
* @api public
|
|
13617
|
-
*/
|
|
13618
13612
|
get name() {
|
|
13619
13613
|
return "websocket";
|
|
13620
13614
|
}
|
|
13621
|
-
/**
|
|
13622
|
-
* Opens socket.
|
|
13623
|
-
*
|
|
13624
|
-
* @api private
|
|
13625
|
-
*/
|
|
13626
13615
|
doOpen() {
|
|
13627
13616
|
if (!this.check()) {
|
|
13628
13617
|
// let probe timeout
|
|
@@ -13646,7 +13635,7 @@
|
|
|
13646
13635
|
: new WebSocket$1(uri, protocols, opts);
|
|
13647
13636
|
}
|
|
13648
13637
|
catch (err) {
|
|
13649
|
-
return this.
|
|
13638
|
+
return this.emitReserved("error", err);
|
|
13650
13639
|
}
|
|
13651
13640
|
this.ws.binaryType = this.socket.binaryType || defaultBinaryType;
|
|
13652
13641
|
this.addEventListeners();
|
|
@@ -13654,7 +13643,7 @@
|
|
|
13654
13643
|
/**
|
|
13655
13644
|
* Adds event listeners to the socket
|
|
13656
13645
|
*
|
|
13657
|
-
* @
|
|
13646
|
+
* @private
|
|
13658
13647
|
*/
|
|
13659
13648
|
addEventListeners() {
|
|
13660
13649
|
this.ws.onopen = () => {
|
|
@@ -13663,16 +13652,13 @@
|
|
|
13663
13652
|
}
|
|
13664
13653
|
this.onOpen();
|
|
13665
13654
|
};
|
|
13666
|
-
this.ws.onclose = this.onClose
|
|
13667
|
-
|
|
13668
|
-
|
|
13655
|
+
this.ws.onclose = (closeEvent) => this.onClose({
|
|
13656
|
+
description: "websocket connection closed",
|
|
13657
|
+
context: closeEvent,
|
|
13658
|
+
});
|
|
13659
|
+
this.ws.onmessage = (ev) => this.onData(ev.data);
|
|
13660
|
+
this.ws.onerror = (e) => this.onError("websocket error", e);
|
|
13669
13661
|
}
|
|
13670
|
-
/**
|
|
13671
|
-
* Writes data to socket.
|
|
13672
|
-
*
|
|
13673
|
-
* @param {Array} array of packets.
|
|
13674
|
-
* @api private
|
|
13675
|
-
*/
|
|
13676
13662
|
write(packets) {
|
|
13677
13663
|
this.writable = false;
|
|
13678
13664
|
// encodePacket efficient as it uses WS framing
|
|
@@ -13680,7 +13666,7 @@
|
|
|
13680
13666
|
for (let i = 0; i < packets.length; i++) {
|
|
13681
13667
|
const packet = packets[i];
|
|
13682
13668
|
const lastPacket = i === packets.length - 1;
|
|
13683
|
-
encodePacket(packet, this.supportsBinary, data => {
|
|
13669
|
+
encodePacket(packet, this.supportsBinary, (data) => {
|
|
13684
13670
|
// always create a new object (GH-437)
|
|
13685
13671
|
const opts = {};
|
|
13686
13672
|
// Sometimes the websocket has already been closed but the browser didn't
|
|
@@ -13699,17 +13685,12 @@
|
|
|
13699
13685
|
// defer to next tick to allow Socket to clear writeBuffer
|
|
13700
13686
|
nextTick(() => {
|
|
13701
13687
|
this.writable = true;
|
|
13702
|
-
this.
|
|
13688
|
+
this.emitReserved("drain");
|
|
13703
13689
|
}, this.setTimeoutFn);
|
|
13704
13690
|
}
|
|
13705
13691
|
});
|
|
13706
13692
|
}
|
|
13707
13693
|
}
|
|
13708
|
-
/**
|
|
13709
|
-
* Closes socket.
|
|
13710
|
-
*
|
|
13711
|
-
* @api private
|
|
13712
|
-
*/
|
|
13713
13694
|
doClose() {
|
|
13714
13695
|
if (typeof this.ws !== "undefined") {
|
|
13715
13696
|
this.ws.close();
|
|
@@ -13719,7 +13700,7 @@
|
|
|
13719
13700
|
/**
|
|
13720
13701
|
* Generates uri for connection.
|
|
13721
13702
|
*
|
|
13722
|
-
* @
|
|
13703
|
+
* @private
|
|
13723
13704
|
*/
|
|
13724
13705
|
uri() {
|
|
13725
13706
|
let query = this.query || {};
|
|
@@ -13733,13 +13714,13 @@
|
|
|
13733
13714
|
}
|
|
13734
13715
|
// append timestamp to URI
|
|
13735
13716
|
if (this.opts.timestampRequests) {
|
|
13736
|
-
query[this.opts.timestampParam] =
|
|
13717
|
+
query[this.opts.timestampParam] = yeast();
|
|
13737
13718
|
}
|
|
13738
13719
|
// communicate binary support capabilities
|
|
13739
13720
|
if (!this.supportsBinary) {
|
|
13740
13721
|
query.b64 = 1;
|
|
13741
13722
|
}
|
|
13742
|
-
const encodedQuery =
|
|
13723
|
+
const encodedQuery = encode(query);
|
|
13743
13724
|
const ipv6 = this.opts.hostname.indexOf(":") !== -1;
|
|
13744
13725
|
return (schema +
|
|
13745
13726
|
"://" +
|
|
@@ -13752,35 +13733,96 @@
|
|
|
13752
13733
|
* Feature detection for WebSocket.
|
|
13753
13734
|
*
|
|
13754
13735
|
* @return {Boolean} whether this transport is available.
|
|
13755
|
-
* @
|
|
13736
|
+
* @private
|
|
13756
13737
|
*/
|
|
13757
13738
|
check() {
|
|
13758
|
-
return
|
|
13759
|
-
!("__initialize" in WebSocket$1 && this.name === WS.prototype.name));
|
|
13739
|
+
return !!WebSocket$1;
|
|
13760
13740
|
}
|
|
13761
13741
|
}
|
|
13762
13742
|
|
|
13763
13743
|
const transports = {
|
|
13764
13744
|
websocket: WS,
|
|
13765
|
-
polling:
|
|
13745
|
+
polling: Polling,
|
|
13766
13746
|
};
|
|
13767
13747
|
|
|
13768
|
-
|
|
13748
|
+
// imported from https://github.com/galkn/parseuri
|
|
13749
|
+
/**
|
|
13750
|
+
* Parses a URI
|
|
13751
|
+
*
|
|
13752
|
+
* Note: we could also have used the built-in URL object, but it isn't supported on all platforms.
|
|
13753
|
+
*
|
|
13754
|
+
* See:
|
|
13755
|
+
* - https://developer.mozilla.org/en-US/docs/Web/API/URL
|
|
13756
|
+
* - https://caniuse.com/url
|
|
13757
|
+
* - https://www.rfc-editor.org/rfc/rfc3986#appendix-B
|
|
13758
|
+
*
|
|
13759
|
+
* History of the parse() method:
|
|
13760
|
+
* - first commit: https://github.com/socketio/socket.io-client/commit/4ee1d5d94b3906a9c052b459f1a818b15f38f91c
|
|
13761
|
+
* - export into its own module: https://github.com/socketio/engine.io-client/commit/de2c561e4564efeb78f1bdb1ba39ef81b2822cb3
|
|
13762
|
+
* - reimport: https://github.com/socketio/engine.io-client/commit/df32277c3f6d622eec5ed09f493cae3f3391d242
|
|
13763
|
+
*
|
|
13764
|
+
* @author Steven Levithan <stevenlevithan.com> (MIT license)
|
|
13765
|
+
* @api private
|
|
13766
|
+
*/
|
|
13767
|
+
const re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
|
13768
|
+
const parts = [
|
|
13769
|
+
'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
|
|
13770
|
+
];
|
|
13771
|
+
function parse(str) {
|
|
13772
|
+
const src = str, b = str.indexOf('['), e = str.indexOf(']');
|
|
13773
|
+
if (b != -1 && e != -1) {
|
|
13774
|
+
str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
|
|
13775
|
+
}
|
|
13776
|
+
let m = re.exec(str || ''), uri = {}, i = 14;
|
|
13777
|
+
while (i--) {
|
|
13778
|
+
uri[parts[i]] = m[i] || '';
|
|
13779
|
+
}
|
|
13780
|
+
if (b != -1 && e != -1) {
|
|
13781
|
+
uri.source = src;
|
|
13782
|
+
uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
|
|
13783
|
+
uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
|
|
13784
|
+
uri.ipv6uri = true;
|
|
13785
|
+
}
|
|
13786
|
+
uri.pathNames = pathNames(uri, uri['path']);
|
|
13787
|
+
uri.queryKey = queryKey(uri, uri['query']);
|
|
13788
|
+
return uri;
|
|
13789
|
+
}
|
|
13790
|
+
function pathNames(obj, path) {
|
|
13791
|
+
const regx = /\/{2,9}/g, names = path.replace(regx, "/").split("/");
|
|
13792
|
+
if (path.slice(0, 1) == '/' || path.length === 0) {
|
|
13793
|
+
names.splice(0, 1);
|
|
13794
|
+
}
|
|
13795
|
+
if (path.slice(-1) == '/') {
|
|
13796
|
+
names.splice(names.length - 1, 1);
|
|
13797
|
+
}
|
|
13798
|
+
return names;
|
|
13799
|
+
}
|
|
13800
|
+
function queryKey(uri, query) {
|
|
13801
|
+
const data = {};
|
|
13802
|
+
query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
|
|
13803
|
+
if ($1) {
|
|
13804
|
+
data[$1] = $2;
|
|
13805
|
+
}
|
|
13806
|
+
});
|
|
13807
|
+
return data;
|
|
13808
|
+
}
|
|
13809
|
+
|
|
13810
|
+
class Socket$1 extends Emitter {
|
|
13769
13811
|
/**
|
|
13770
13812
|
* Socket constructor.
|
|
13771
13813
|
*
|
|
13772
|
-
* @param {String|Object} uri or options
|
|
13814
|
+
* @param {String|Object} uri - uri or options
|
|
13773
13815
|
* @param {Object} opts - options
|
|
13774
|
-
* @api public
|
|
13775
13816
|
*/
|
|
13776
13817
|
constructor(uri, opts = {}) {
|
|
13777
13818
|
super();
|
|
13819
|
+
this.writeBuffer = [];
|
|
13778
13820
|
if (uri && "object" === typeof uri) {
|
|
13779
13821
|
opts = uri;
|
|
13780
13822
|
uri = null;
|
|
13781
13823
|
}
|
|
13782
13824
|
if (uri) {
|
|
13783
|
-
uri =
|
|
13825
|
+
uri = parse(uri);
|
|
13784
13826
|
opts.hostname = uri.host;
|
|
13785
13827
|
opts.secure = uri.protocol === "https" || uri.protocol === "wss";
|
|
13786
13828
|
opts.port = uri.port;
|
|
@@ -13788,7 +13830,7 @@
|
|
|
13788
13830
|
opts.query = uri.query;
|
|
13789
13831
|
}
|
|
13790
13832
|
else if (opts.host) {
|
|
13791
|
-
opts.hostname =
|
|
13833
|
+
opts.hostname = parse(opts.host).host;
|
|
13792
13834
|
}
|
|
13793
13835
|
installTimerFunctions(this, opts);
|
|
13794
13836
|
this.secure =
|
|
@@ -13810,7 +13852,6 @@
|
|
|
13810
13852
|
? "443"
|
|
13811
13853
|
: "80");
|
|
13812
13854
|
this.transports = opts.transports || ["polling", "websocket"];
|
|
13813
|
-
this.readyState = "";
|
|
13814
13855
|
this.writeBuffer = [];
|
|
13815
13856
|
this.prevBufferLen = 0;
|
|
13816
13857
|
this.opts = Object.assign({
|
|
@@ -13820,16 +13861,19 @@
|
|
|
13820
13861
|
upgrade: true,
|
|
13821
13862
|
timestampParam: "t",
|
|
13822
13863
|
rememberUpgrade: false,
|
|
13864
|
+
addTrailingSlash: true,
|
|
13823
13865
|
rejectUnauthorized: true,
|
|
13824
13866
|
perMessageDeflate: {
|
|
13825
|
-
threshold: 1024
|
|
13867
|
+
threshold: 1024,
|
|
13826
13868
|
},
|
|
13827
13869
|
transportOptions: {},
|
|
13828
|
-
closeOnBeforeunload: true
|
|
13870
|
+
closeOnBeforeunload: true,
|
|
13829
13871
|
}, opts);
|
|
13830
|
-
this.opts.path =
|
|
13872
|
+
this.opts.path =
|
|
13873
|
+
this.opts.path.replace(/\/$/, "") +
|
|
13874
|
+
(this.opts.addTrailingSlash ? "/" : "");
|
|
13831
13875
|
if (typeof this.opts.query === "string") {
|
|
13832
|
-
this.opts.query =
|
|
13876
|
+
this.opts.query = decode(this.opts.query);
|
|
13833
13877
|
}
|
|
13834
13878
|
// set on handshake
|
|
13835
13879
|
this.id = null;
|
|
@@ -13843,17 +13887,20 @@
|
|
|
13843
13887
|
// Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
|
|
13844
13888
|
// ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
|
|
13845
13889
|
// closed/reloaded)
|
|
13846
|
-
|
|
13890
|
+
this.beforeunloadEventListener = () => {
|
|
13847
13891
|
if (this.transport) {
|
|
13848
13892
|
// silently close the transport
|
|
13849
13893
|
this.transport.removeAllListeners();
|
|
13850
13894
|
this.transport.close();
|
|
13851
13895
|
}
|
|
13852
|
-
}
|
|
13896
|
+
};
|
|
13897
|
+
addEventListener("beforeunload", this.beforeunloadEventListener, false);
|
|
13853
13898
|
}
|
|
13854
13899
|
if (this.hostname !== "localhost") {
|
|
13855
13900
|
this.offlineEventListener = () => {
|
|
13856
|
-
this.onClose("transport close"
|
|
13901
|
+
this.onClose("transport close", {
|
|
13902
|
+
description: "network connection lost",
|
|
13903
|
+
});
|
|
13857
13904
|
};
|
|
13858
13905
|
addEventListener("offline", this.offlineEventListener, false);
|
|
13859
13906
|
}
|
|
@@ -13863,12 +13910,12 @@
|
|
|
13863
13910
|
/**
|
|
13864
13911
|
* Creates transport of the given type.
|
|
13865
13912
|
*
|
|
13866
|
-
* @param {String} transport name
|
|
13913
|
+
* @param {String} name - transport name
|
|
13867
13914
|
* @return {Transport}
|
|
13868
|
-
* @
|
|
13915
|
+
* @private
|
|
13869
13916
|
*/
|
|
13870
13917
|
createTransport(name) {
|
|
13871
|
-
const query =
|
|
13918
|
+
const query = Object.assign({}, this.opts.query);
|
|
13872
13919
|
// append engine.io protocol identifier
|
|
13873
13920
|
query.EIO = protocol$1;
|
|
13874
13921
|
// transport name
|
|
@@ -13881,14 +13928,14 @@
|
|
|
13881
13928
|
socket: this,
|
|
13882
13929
|
hostname: this.hostname,
|
|
13883
13930
|
secure: this.secure,
|
|
13884
|
-
port: this.port
|
|
13931
|
+
port: this.port,
|
|
13885
13932
|
});
|
|
13886
13933
|
return new transports[name](opts);
|
|
13887
13934
|
}
|
|
13888
13935
|
/**
|
|
13889
13936
|
* Initializes transport to use and starts probe.
|
|
13890
13937
|
*
|
|
13891
|
-
* @
|
|
13938
|
+
* @private
|
|
13892
13939
|
*/
|
|
13893
13940
|
open() {
|
|
13894
13941
|
let transport;
|
|
@@ -13923,7 +13970,7 @@
|
|
|
13923
13970
|
/**
|
|
13924
13971
|
* Sets the current transport. Disables the existing one (if any).
|
|
13925
13972
|
*
|
|
13926
|
-
* @
|
|
13973
|
+
* @private
|
|
13927
13974
|
*/
|
|
13928
13975
|
setTransport(transport) {
|
|
13929
13976
|
if (this.transport) {
|
|
@@ -13936,15 +13983,13 @@
|
|
|
13936
13983
|
.on("drain", this.onDrain.bind(this))
|
|
13937
13984
|
.on("packet", this.onPacket.bind(this))
|
|
13938
13985
|
.on("error", this.onError.bind(this))
|
|
13939
|
-
.on("close", () =>
|
|
13940
|
-
this.onClose("transport close");
|
|
13941
|
-
});
|
|
13986
|
+
.on("close", (reason) => this.onClose("transport close", reason));
|
|
13942
13987
|
}
|
|
13943
13988
|
/**
|
|
13944
13989
|
* Probes a transport.
|
|
13945
13990
|
*
|
|
13946
|
-
* @param {String} transport name
|
|
13947
|
-
* @
|
|
13991
|
+
* @param {String} name - transport name
|
|
13992
|
+
* @private
|
|
13948
13993
|
*/
|
|
13949
13994
|
probe(name) {
|
|
13950
13995
|
let transport = this.createTransport(name);
|
|
@@ -13954,7 +13999,7 @@
|
|
|
13954
13999
|
if (failed)
|
|
13955
14000
|
return;
|
|
13956
14001
|
transport.send([{ type: "ping", data: "probe" }]);
|
|
13957
|
-
transport.once("packet", msg => {
|
|
14002
|
+
transport.once("packet", (msg) => {
|
|
13958
14003
|
if (failed)
|
|
13959
14004
|
return;
|
|
13960
14005
|
if ("pong" === msg.type && "probe" === msg.data) {
|
|
@@ -13995,7 +14040,7 @@
|
|
|
13995
14040
|
transport = null;
|
|
13996
14041
|
}
|
|
13997
14042
|
// Handle any error that happens while probing
|
|
13998
|
-
const onerror = err => {
|
|
14043
|
+
const onerror = (err) => {
|
|
13999
14044
|
const error = new Error("probe error: " + err);
|
|
14000
14045
|
// @ts-ignore
|
|
14001
14046
|
error.transport = transport.name;
|
|
@@ -14033,7 +14078,7 @@
|
|
|
14033
14078
|
/**
|
|
14034
14079
|
* Called when connection is deemed open.
|
|
14035
14080
|
*
|
|
14036
|
-
* @
|
|
14081
|
+
* @private
|
|
14037
14082
|
*/
|
|
14038
14083
|
onOpen() {
|
|
14039
14084
|
this.readyState = "open";
|
|
@@ -14042,9 +14087,7 @@
|
|
|
14042
14087
|
this.flush();
|
|
14043
14088
|
// we check for `readyState` in case an `open`
|
|
14044
14089
|
// listener already closed the socket
|
|
14045
|
-
if ("open" === this.readyState &&
|
|
14046
|
-
this.opts.upgrade &&
|
|
14047
|
-
this.transport.pause) {
|
|
14090
|
+
if ("open" === this.readyState && this.opts.upgrade) {
|
|
14048
14091
|
let i = 0;
|
|
14049
14092
|
const l = this.upgrades.length;
|
|
14050
14093
|
for (; i < l; i++) {
|
|
@@ -14055,7 +14098,7 @@
|
|
|
14055
14098
|
/**
|
|
14056
14099
|
* Handles a packet.
|
|
14057
14100
|
*
|
|
14058
|
-
* @
|
|
14101
|
+
* @private
|
|
14059
14102
|
*/
|
|
14060
14103
|
onPacket(packet) {
|
|
14061
14104
|
if ("opening" === this.readyState ||
|
|
@@ -14091,7 +14134,7 @@
|
|
|
14091
14134
|
* Called upon handshake completion.
|
|
14092
14135
|
*
|
|
14093
14136
|
* @param {Object} data - handshake obj
|
|
14094
|
-
* @
|
|
14137
|
+
* @private
|
|
14095
14138
|
*/
|
|
14096
14139
|
onHandshake(data) {
|
|
14097
14140
|
this.emitReserved("handshake", data);
|
|
@@ -14100,6 +14143,7 @@
|
|
|
14100
14143
|
this.upgrades = this.filterUpgrades(data.upgrades);
|
|
14101
14144
|
this.pingInterval = data.pingInterval;
|
|
14102
14145
|
this.pingTimeout = data.pingTimeout;
|
|
14146
|
+
this.maxPayload = data.maxPayload;
|
|
14103
14147
|
this.onOpen();
|
|
14104
14148
|
// In case open handler closes socket
|
|
14105
14149
|
if ("closed" === this.readyState)
|
|
@@ -14109,7 +14153,7 @@
|
|
|
14109
14153
|
/**
|
|
14110
14154
|
* Sets and resets ping timeout timer based on server pings.
|
|
14111
14155
|
*
|
|
14112
|
-
* @
|
|
14156
|
+
* @private
|
|
14113
14157
|
*/
|
|
14114
14158
|
resetPingTimeout() {
|
|
14115
14159
|
this.clearTimeoutFn(this.pingTimeoutTimer);
|
|
@@ -14123,7 +14167,7 @@
|
|
|
14123
14167
|
/**
|
|
14124
14168
|
* Called on `drain` event
|
|
14125
14169
|
*
|
|
14126
|
-
* @
|
|
14170
|
+
* @private
|
|
14127
14171
|
*/
|
|
14128
14172
|
onDrain() {
|
|
14129
14173
|
this.writeBuffer.splice(0, this.prevBufferLen);
|
|
@@ -14141,28 +14185,54 @@
|
|
|
14141
14185
|
/**
|
|
14142
14186
|
* Flush write buffers.
|
|
14143
14187
|
*
|
|
14144
|
-
* @
|
|
14188
|
+
* @private
|
|
14145
14189
|
*/
|
|
14146
14190
|
flush() {
|
|
14147
14191
|
if ("closed" !== this.readyState &&
|
|
14148
14192
|
this.transport.writable &&
|
|
14149
14193
|
!this.upgrading &&
|
|
14150
14194
|
this.writeBuffer.length) {
|
|
14151
|
-
this.
|
|
14195
|
+
const packets = this.getWritablePackets();
|
|
14196
|
+
this.transport.send(packets);
|
|
14152
14197
|
// keep track of current length of writeBuffer
|
|
14153
14198
|
// splice writeBuffer and callbackBuffer on `drain`
|
|
14154
|
-
this.prevBufferLen =
|
|
14199
|
+
this.prevBufferLen = packets.length;
|
|
14155
14200
|
this.emitReserved("flush");
|
|
14156
14201
|
}
|
|
14157
14202
|
}
|
|
14203
|
+
/**
|
|
14204
|
+
* Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
|
|
14205
|
+
* long-polling)
|
|
14206
|
+
*
|
|
14207
|
+
* @private
|
|
14208
|
+
*/
|
|
14209
|
+
getWritablePackets() {
|
|
14210
|
+
const shouldCheckPayloadSize = this.maxPayload &&
|
|
14211
|
+
this.transport.name === "polling" &&
|
|
14212
|
+
this.writeBuffer.length > 1;
|
|
14213
|
+
if (!shouldCheckPayloadSize) {
|
|
14214
|
+
return this.writeBuffer;
|
|
14215
|
+
}
|
|
14216
|
+
let payloadSize = 1; // first packet type
|
|
14217
|
+
for (let i = 0; i < this.writeBuffer.length; i++) {
|
|
14218
|
+
const data = this.writeBuffer[i].data;
|
|
14219
|
+
if (data) {
|
|
14220
|
+
payloadSize += byteLength(data);
|
|
14221
|
+
}
|
|
14222
|
+
if (i > 0 && payloadSize > this.maxPayload) {
|
|
14223
|
+
return this.writeBuffer.slice(0, i);
|
|
14224
|
+
}
|
|
14225
|
+
payloadSize += 2; // separator + packet type
|
|
14226
|
+
}
|
|
14227
|
+
return this.writeBuffer;
|
|
14228
|
+
}
|
|
14158
14229
|
/**
|
|
14159
14230
|
* Sends a message.
|
|
14160
14231
|
*
|
|
14161
|
-
* @param {String} message.
|
|
14162
|
-
* @param {Function} callback function.
|
|
14232
|
+
* @param {String} msg - message.
|
|
14163
14233
|
* @param {Object} options.
|
|
14234
|
+
* @param {Function} callback function.
|
|
14164
14235
|
* @return {Socket} for chaining.
|
|
14165
|
-
* @api public
|
|
14166
14236
|
*/
|
|
14167
14237
|
write(msg, options, fn) {
|
|
14168
14238
|
this.sendPacket("message", msg, options, fn);
|
|
@@ -14175,11 +14245,11 @@
|
|
|
14175
14245
|
/**
|
|
14176
14246
|
* Sends a packet.
|
|
14177
14247
|
*
|
|
14178
|
-
* @param {String} packet type.
|
|
14248
|
+
* @param {String} type: packet type.
|
|
14179
14249
|
* @param {String} data.
|
|
14180
14250
|
* @param {Object} options.
|
|
14181
|
-
* @param {Function} callback function.
|
|
14182
|
-
* @
|
|
14251
|
+
* @param {Function} fn - callback function.
|
|
14252
|
+
* @private
|
|
14183
14253
|
*/
|
|
14184
14254
|
sendPacket(type, data, options, fn) {
|
|
14185
14255
|
if ("function" === typeof data) {
|
|
@@ -14198,7 +14268,7 @@
|
|
|
14198
14268
|
const packet = {
|
|
14199
14269
|
type: type,
|
|
14200
14270
|
data: data,
|
|
14201
|
-
options: options
|
|
14271
|
+
options: options,
|
|
14202
14272
|
};
|
|
14203
14273
|
this.emitReserved("packetCreate", packet);
|
|
14204
14274
|
this.writeBuffer.push(packet);
|
|
@@ -14208,8 +14278,6 @@
|
|
|
14208
14278
|
}
|
|
14209
14279
|
/**
|
|
14210
14280
|
* Closes the connection.
|
|
14211
|
-
*
|
|
14212
|
-
* @api public
|
|
14213
14281
|
*/
|
|
14214
14282
|
close() {
|
|
14215
14283
|
const close = () => {
|
|
@@ -14250,7 +14318,7 @@
|
|
|
14250
14318
|
/**
|
|
14251
14319
|
* Called upon transport error
|
|
14252
14320
|
*
|
|
14253
|
-
* @
|
|
14321
|
+
* @private
|
|
14254
14322
|
*/
|
|
14255
14323
|
onError(err) {
|
|
14256
14324
|
Socket$1.priorWebsocketSuccess = false;
|
|
@@ -14260,9 +14328,9 @@
|
|
|
14260
14328
|
/**
|
|
14261
14329
|
* Called upon transport close.
|
|
14262
14330
|
*
|
|
14263
|
-
* @
|
|
14331
|
+
* @private
|
|
14264
14332
|
*/
|
|
14265
|
-
onClose(reason,
|
|
14333
|
+
onClose(reason, description) {
|
|
14266
14334
|
if ("opening" === this.readyState ||
|
|
14267
14335
|
"open" === this.readyState ||
|
|
14268
14336
|
"closing" === this.readyState) {
|
|
@@ -14275,6 +14343,7 @@
|
|
|
14275
14343
|
// ignore further transport communication
|
|
14276
14344
|
this.transport.removeAllListeners();
|
|
14277
14345
|
if (typeof removeEventListener === "function") {
|
|
14346
|
+
removeEventListener("beforeunload", this.beforeunloadEventListener, false);
|
|
14278
14347
|
removeEventListener("offline", this.offlineEventListener, false);
|
|
14279
14348
|
}
|
|
14280
14349
|
// set ready state
|
|
@@ -14282,7 +14351,7 @@
|
|
|
14282
14351
|
// clear session id
|
|
14283
14352
|
this.id = null;
|
|
14284
14353
|
// emit close event
|
|
14285
|
-
this.emitReserved("close", reason,
|
|
14354
|
+
this.emitReserved("close", reason, description);
|
|
14286
14355
|
// clean buffers after, so users can still
|
|
14287
14356
|
// grab the buffers on `close` event
|
|
14288
14357
|
this.writeBuffer = [];
|
|
@@ -14292,9 +14361,8 @@
|
|
|
14292
14361
|
/**
|
|
14293
14362
|
* Filters upgrades, returning only those matching client transports.
|
|
14294
14363
|
*
|
|
14295
|
-
* @param {Array} server upgrades
|
|
14296
|
-
* @
|
|
14297
|
-
*
|
|
14364
|
+
* @param {Array} upgrades - server upgrades
|
|
14365
|
+
* @private
|
|
14298
14366
|
*/
|
|
14299
14367
|
filterUpgrades(upgrades) {
|
|
14300
14368
|
const filteredUpgrades = [];
|
|
@@ -14304,18 +14372,68 @@
|
|
|
14304
14372
|
if (~this.transports.indexOf(upgrades[i]))
|
|
14305
14373
|
filteredUpgrades.push(upgrades[i]);
|
|
14306
14374
|
}
|
|
14307
|
-
return filteredUpgrades;
|
|
14375
|
+
return filteredUpgrades;
|
|
14376
|
+
}
|
|
14377
|
+
}
|
|
14378
|
+
Socket$1.protocol = protocol$1;
|
|
14379
|
+
|
|
14380
|
+
/**
|
|
14381
|
+
* URL parser.
|
|
14382
|
+
*
|
|
14383
|
+
* @param uri - url
|
|
14384
|
+
* @param path - the request path of the connection
|
|
14385
|
+
* @param loc - An object meant to mimic window.location.
|
|
14386
|
+
* Defaults to window.location.
|
|
14387
|
+
* @public
|
|
14388
|
+
*/
|
|
14389
|
+
function url(uri, path = "", loc) {
|
|
14390
|
+
let obj = uri;
|
|
14391
|
+
// default to window.location
|
|
14392
|
+
loc = loc || (typeof location !== "undefined" && location);
|
|
14393
|
+
if (null == uri)
|
|
14394
|
+
uri = loc.protocol + "//" + loc.host;
|
|
14395
|
+
// relative path support
|
|
14396
|
+
if (typeof uri === "string") {
|
|
14397
|
+
if ("/" === uri.charAt(0)) {
|
|
14398
|
+
if ("/" === uri.charAt(1)) {
|
|
14399
|
+
uri = loc.protocol + uri;
|
|
14400
|
+
}
|
|
14401
|
+
else {
|
|
14402
|
+
uri = loc.host + uri;
|
|
14403
|
+
}
|
|
14404
|
+
}
|
|
14405
|
+
if (!/^(https?|wss?):\/\//.test(uri)) {
|
|
14406
|
+
if ("undefined" !== typeof loc) {
|
|
14407
|
+
uri = loc.protocol + "//" + uri;
|
|
14408
|
+
}
|
|
14409
|
+
else {
|
|
14410
|
+
uri = "https://" + uri;
|
|
14411
|
+
}
|
|
14412
|
+
}
|
|
14413
|
+
// parse
|
|
14414
|
+
obj = parse(uri);
|
|
14308
14415
|
}
|
|
14309
|
-
|
|
14310
|
-
|
|
14311
|
-
|
|
14312
|
-
|
|
14313
|
-
|
|
14314
|
-
if (obj.
|
|
14315
|
-
|
|
14416
|
+
// make sure we treat `localhost:80` and `localhost` equally
|
|
14417
|
+
if (!obj.port) {
|
|
14418
|
+
if (/^(http|ws)$/.test(obj.protocol)) {
|
|
14419
|
+
obj.port = "80";
|
|
14420
|
+
}
|
|
14421
|
+
else if (/^(http|ws)s$/.test(obj.protocol)) {
|
|
14422
|
+
obj.port = "443";
|
|
14316
14423
|
}
|
|
14317
14424
|
}
|
|
14318
|
-
|
|
14425
|
+
obj.path = obj.path || "/";
|
|
14426
|
+
const ipv6 = obj.host.indexOf(":") !== -1;
|
|
14427
|
+
const host = ipv6 ? "[" + obj.host + "]" : obj.host;
|
|
14428
|
+
// define unique id
|
|
14429
|
+
obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
|
|
14430
|
+
// define href
|
|
14431
|
+
obj.href =
|
|
14432
|
+
obj.protocol +
|
|
14433
|
+
"://" +
|
|
14434
|
+
host +
|
|
14435
|
+
(loc && loc.port === obj.port ? "" : ":" + obj.port);
|
|
14436
|
+
return obj;
|
|
14319
14437
|
}
|
|
14320
14438
|
|
|
14321
14439
|
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
|
|
@@ -14402,7 +14520,7 @@
|
|
|
14402
14520
|
else if (typeof data === "object" && !(data instanceof Date)) {
|
|
14403
14521
|
const newData = {};
|
|
14404
14522
|
for (const key in data) {
|
|
14405
|
-
if (
|
|
14523
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
14406
14524
|
newData[key] = _deconstructPacket(data[key], buffers);
|
|
14407
14525
|
}
|
|
14408
14526
|
}
|
|
@@ -14420,14 +14538,22 @@
|
|
|
14420
14538
|
*/
|
|
14421
14539
|
function reconstructPacket(packet, buffers) {
|
|
14422
14540
|
packet.data = _reconstructPacket(packet.data, buffers);
|
|
14423
|
-
packet.attachments
|
|
14541
|
+
delete packet.attachments; // no longer useful
|
|
14424
14542
|
return packet;
|
|
14425
14543
|
}
|
|
14426
14544
|
function _reconstructPacket(data, buffers) {
|
|
14427
14545
|
if (!data)
|
|
14428
14546
|
return data;
|
|
14429
|
-
if (data && data._placeholder) {
|
|
14430
|
-
|
|
14547
|
+
if (data && data._placeholder === true) {
|
|
14548
|
+
const isIndexValid = typeof data.num === "number" &&
|
|
14549
|
+
data.num >= 0 &&
|
|
14550
|
+
data.num < buffers.length;
|
|
14551
|
+
if (isIndexValid) {
|
|
14552
|
+
return buffers[data.num]; // appropriate buffer (should be natural order anyway)
|
|
14553
|
+
}
|
|
14554
|
+
else {
|
|
14555
|
+
throw new Error("illegal attachments");
|
|
14556
|
+
}
|
|
14431
14557
|
}
|
|
14432
14558
|
else if (Array.isArray(data)) {
|
|
14433
14559
|
for (let i = 0; i < data.length; i++) {
|
|
@@ -14436,7 +14562,7 @@
|
|
|
14436
14562
|
}
|
|
14437
14563
|
else if (typeof data === "object") {
|
|
14438
14564
|
for (const key in data) {
|
|
14439
|
-
if (
|
|
14565
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
14440
14566
|
data[key] = _reconstructPacket(data[key], buffers);
|
|
14441
14567
|
}
|
|
14442
14568
|
}
|
|
@@ -14464,6 +14590,14 @@
|
|
|
14464
14590
|
* A socket.io Encoder instance
|
|
14465
14591
|
*/
|
|
14466
14592
|
class Encoder {
|
|
14593
|
+
/**
|
|
14594
|
+
* Encoder constructor
|
|
14595
|
+
*
|
|
14596
|
+
* @param {function} replacer - custom replacer to pass down to JSON.parse
|
|
14597
|
+
*/
|
|
14598
|
+
constructor(replacer) {
|
|
14599
|
+
this.replacer = replacer;
|
|
14600
|
+
}
|
|
14467
14601
|
/**
|
|
14468
14602
|
* Encode a packet as a single string if non-binary, or as a
|
|
14469
14603
|
* buffer sequence, depending on packet type.
|
|
@@ -14473,11 +14607,14 @@
|
|
|
14473
14607
|
encode(obj) {
|
|
14474
14608
|
if (obj.type === PacketType.EVENT || obj.type === PacketType.ACK) {
|
|
14475
14609
|
if (hasBinary(obj)) {
|
|
14476
|
-
|
|
14477
|
-
obj.type === PacketType.EVENT
|
|
14610
|
+
return this.encodeAsBinary({
|
|
14611
|
+
type: obj.type === PacketType.EVENT
|
|
14478
14612
|
? PacketType.BINARY_EVENT
|
|
14479
|
-
: PacketType.BINARY_ACK
|
|
14480
|
-
|
|
14613
|
+
: PacketType.BINARY_ACK,
|
|
14614
|
+
nsp: obj.nsp,
|
|
14615
|
+
data: obj.data,
|
|
14616
|
+
id: obj.id,
|
|
14617
|
+
});
|
|
14481
14618
|
}
|
|
14482
14619
|
}
|
|
14483
14620
|
return [this.encodeAsString(obj)];
|
|
@@ -14504,7 +14641,7 @@
|
|
|
14504
14641
|
}
|
|
14505
14642
|
// json data
|
|
14506
14643
|
if (null != obj.data) {
|
|
14507
|
-
str += JSON.stringify(obj.data);
|
|
14644
|
+
str += JSON.stringify(obj.data, this.replacer);
|
|
14508
14645
|
}
|
|
14509
14646
|
return str;
|
|
14510
14647
|
}
|
|
@@ -14526,9 +14663,15 @@
|
|
|
14526
14663
|
*
|
|
14527
14664
|
* @return {Object} decoder
|
|
14528
14665
|
*/
|
|
14529
|
-
class Decoder extends
|
|
14530
|
-
|
|
14666
|
+
class Decoder extends Emitter {
|
|
14667
|
+
/**
|
|
14668
|
+
* Decoder constructor
|
|
14669
|
+
*
|
|
14670
|
+
* @param {function} reviver - custom reviver to pass down to JSON.stringify
|
|
14671
|
+
*/
|
|
14672
|
+
constructor(reviver) {
|
|
14531
14673
|
super();
|
|
14674
|
+
this.reviver = reviver;
|
|
14532
14675
|
}
|
|
14533
14676
|
/**
|
|
14534
14677
|
* Decodes an encoded packet string into packet JSON.
|
|
@@ -14538,9 +14681,13 @@
|
|
|
14538
14681
|
add(obj) {
|
|
14539
14682
|
let packet;
|
|
14540
14683
|
if (typeof obj === "string") {
|
|
14684
|
+
if (this.reconstructor) {
|
|
14685
|
+
throw new Error("got plaintext data when reconstructing a packet");
|
|
14686
|
+
}
|
|
14541
14687
|
packet = this.decodeString(obj);
|
|
14542
|
-
|
|
14543
|
-
|
|
14688
|
+
const isBinaryEvent = packet.type === PacketType.BINARY_EVENT;
|
|
14689
|
+
if (isBinaryEvent || packet.type === PacketType.BINARY_ACK) {
|
|
14690
|
+
packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK;
|
|
14544
14691
|
// binary packet's json
|
|
14545
14692
|
this.reconstructor = new BinaryReconstructor(packet);
|
|
14546
14693
|
// no attachments, labeled binary but no binary data to follow
|
|
@@ -14629,7 +14776,7 @@
|
|
|
14629
14776
|
}
|
|
14630
14777
|
// look up json data
|
|
14631
14778
|
if (str.charAt(++i)) {
|
|
14632
|
-
const payload = tryParse(str.substr(i));
|
|
14779
|
+
const payload = this.tryParse(str.substr(i));
|
|
14633
14780
|
if (Decoder.isPayloadValid(p.type, payload)) {
|
|
14634
14781
|
p.data = payload;
|
|
14635
14782
|
}
|
|
@@ -14639,6 +14786,14 @@
|
|
|
14639
14786
|
}
|
|
14640
14787
|
return p;
|
|
14641
14788
|
}
|
|
14789
|
+
tryParse(str) {
|
|
14790
|
+
try {
|
|
14791
|
+
return JSON.parse(str, this.reviver);
|
|
14792
|
+
}
|
|
14793
|
+
catch (e) {
|
|
14794
|
+
return false;
|
|
14795
|
+
}
|
|
14796
|
+
}
|
|
14642
14797
|
static isPayloadValid(type, payload) {
|
|
14643
14798
|
switch (type) {
|
|
14644
14799
|
case PacketType.CONNECT:
|
|
@@ -14661,17 +14816,10 @@
|
|
|
14661
14816
|
destroy() {
|
|
14662
14817
|
if (this.reconstructor) {
|
|
14663
14818
|
this.reconstructor.finishedReconstruction();
|
|
14819
|
+
this.reconstructor = null;
|
|
14664
14820
|
}
|
|
14665
14821
|
}
|
|
14666
14822
|
}
|
|
14667
|
-
function tryParse(str) {
|
|
14668
|
-
try {
|
|
14669
|
-
return JSON.parse(str);
|
|
14670
|
-
}
|
|
14671
|
-
catch (e) {
|
|
14672
|
-
return false;
|
|
14673
|
-
}
|
|
14674
|
-
}
|
|
14675
14823
|
/**
|
|
14676
14824
|
* A manager of a binary event's 'buffer sequence'. Should
|
|
14677
14825
|
* be constructed whenever a packet of type BINARY_EVENT is
|
|
@@ -14741,18 +14889,76 @@
|
|
|
14741
14889
|
newListener: 1,
|
|
14742
14890
|
removeListener: 1,
|
|
14743
14891
|
});
|
|
14744
|
-
|
|
14892
|
+
/**
|
|
14893
|
+
* A Socket is the fundamental class for interacting with the server.
|
|
14894
|
+
*
|
|
14895
|
+
* A Socket belongs to a certain Namespace (by default /) and uses an underlying {@link Manager} to communicate.
|
|
14896
|
+
*
|
|
14897
|
+
* @example
|
|
14898
|
+
* const socket = io();
|
|
14899
|
+
*
|
|
14900
|
+
* socket.on("connect", () => {
|
|
14901
|
+
* console.log("connected");
|
|
14902
|
+
* });
|
|
14903
|
+
*
|
|
14904
|
+
* // send an event to the server
|
|
14905
|
+
* socket.emit("foo", "bar");
|
|
14906
|
+
*
|
|
14907
|
+
* socket.on("foobar", () => {
|
|
14908
|
+
* // an event was received from the server
|
|
14909
|
+
* });
|
|
14910
|
+
*
|
|
14911
|
+
* // upon disconnection
|
|
14912
|
+
* socket.on("disconnect", (reason) => {
|
|
14913
|
+
* console.log(`disconnected due to ${reason}`);
|
|
14914
|
+
* });
|
|
14915
|
+
*/
|
|
14916
|
+
class Socket extends Emitter {
|
|
14745
14917
|
/**
|
|
14746
14918
|
* `Socket` constructor.
|
|
14747
|
-
*
|
|
14748
|
-
* @public
|
|
14749
14919
|
*/
|
|
14750
14920
|
constructor(io, nsp, opts) {
|
|
14751
14921
|
super();
|
|
14922
|
+
/**
|
|
14923
|
+
* Whether the socket is currently connected to the server.
|
|
14924
|
+
*
|
|
14925
|
+
* @example
|
|
14926
|
+
* const socket = io();
|
|
14927
|
+
*
|
|
14928
|
+
* socket.on("connect", () => {
|
|
14929
|
+
* console.log(socket.connected); // true
|
|
14930
|
+
* });
|
|
14931
|
+
*
|
|
14932
|
+
* socket.on("disconnect", () => {
|
|
14933
|
+
* console.log(socket.connected); // false
|
|
14934
|
+
* });
|
|
14935
|
+
*/
|
|
14752
14936
|
this.connected = false;
|
|
14753
|
-
|
|
14937
|
+
/**
|
|
14938
|
+
* Whether the connection state was recovered after a temporary disconnection. In that case, any missed packets will
|
|
14939
|
+
* be transmitted by the server.
|
|
14940
|
+
*/
|
|
14941
|
+
this.recovered = false;
|
|
14942
|
+
/**
|
|
14943
|
+
* Buffer for packets received before the CONNECT packet
|
|
14944
|
+
*/
|
|
14754
14945
|
this.receiveBuffer = [];
|
|
14946
|
+
/**
|
|
14947
|
+
* Buffer for packets that will be sent once the socket is connected
|
|
14948
|
+
*/
|
|
14755
14949
|
this.sendBuffer = [];
|
|
14950
|
+
/**
|
|
14951
|
+
* The queue of packets to be sent with retry in case of failure.
|
|
14952
|
+
*
|
|
14953
|
+
* Packets are sent one by one, each waiting for the server acknowledgement, in order to guarantee the delivery order.
|
|
14954
|
+
* @private
|
|
14955
|
+
*/
|
|
14956
|
+
this._queue = [];
|
|
14957
|
+
/**
|
|
14958
|
+
* A sequence to generate the ID of the {@link QueuedPacket}.
|
|
14959
|
+
* @private
|
|
14960
|
+
*/
|
|
14961
|
+
this._queueSeq = 0;
|
|
14756
14962
|
this.ids = 0;
|
|
14757
14963
|
this.acks = {};
|
|
14758
14964
|
this.flags = {};
|
|
@@ -14761,9 +14967,27 @@
|
|
|
14761
14967
|
if (opts && opts.auth) {
|
|
14762
14968
|
this.auth = opts.auth;
|
|
14763
14969
|
}
|
|
14970
|
+
this._opts = Object.assign({}, opts);
|
|
14764
14971
|
if (this.io._autoConnect)
|
|
14765
14972
|
this.open();
|
|
14766
14973
|
}
|
|
14974
|
+
/**
|
|
14975
|
+
* Whether the socket is currently disconnected
|
|
14976
|
+
*
|
|
14977
|
+
* @example
|
|
14978
|
+
* const socket = io();
|
|
14979
|
+
*
|
|
14980
|
+
* socket.on("connect", () => {
|
|
14981
|
+
* console.log(socket.disconnected); // false
|
|
14982
|
+
* });
|
|
14983
|
+
*
|
|
14984
|
+
* socket.on("disconnect", () => {
|
|
14985
|
+
* console.log(socket.disconnected); // true
|
|
14986
|
+
* });
|
|
14987
|
+
*/
|
|
14988
|
+
get disconnected() {
|
|
14989
|
+
return !this.connected;
|
|
14990
|
+
}
|
|
14767
14991
|
/**
|
|
14768
14992
|
* Subscribe to open, close and packet events
|
|
14769
14993
|
*
|
|
@@ -14781,7 +15005,21 @@
|
|
|
14781
15005
|
];
|
|
14782
15006
|
}
|
|
14783
15007
|
/**
|
|
14784
|
-
* Whether the Socket will try to reconnect when its Manager connects or reconnects
|
|
15008
|
+
* Whether the Socket will try to reconnect when its Manager connects or reconnects.
|
|
15009
|
+
*
|
|
15010
|
+
* @example
|
|
15011
|
+
* const socket = io();
|
|
15012
|
+
*
|
|
15013
|
+
* console.log(socket.active); // true
|
|
15014
|
+
*
|
|
15015
|
+
* socket.on("disconnect", (reason) => {
|
|
15016
|
+
* if (reason === "io server disconnect") {
|
|
15017
|
+
* // the disconnection was initiated by the server, you need to manually reconnect
|
|
15018
|
+
* console.log(socket.active); // false
|
|
15019
|
+
* }
|
|
15020
|
+
* // else the socket will automatically try to reconnect
|
|
15021
|
+
* console.log(socket.active); // true
|
|
15022
|
+
* });
|
|
14785
15023
|
*/
|
|
14786
15024
|
get active() {
|
|
14787
15025
|
return !!this.subs;
|
|
@@ -14789,7 +15027,12 @@
|
|
|
14789
15027
|
/**
|
|
14790
15028
|
* "Opens" the socket.
|
|
14791
15029
|
*
|
|
14792
|
-
* @
|
|
15030
|
+
* @example
|
|
15031
|
+
* const socket = io({
|
|
15032
|
+
* autoConnect: false
|
|
15033
|
+
* });
|
|
15034
|
+
*
|
|
15035
|
+
* socket.connect();
|
|
14793
15036
|
*/
|
|
14794
15037
|
connect() {
|
|
14795
15038
|
if (this.connected)
|
|
@@ -14802,7 +15045,7 @@
|
|
|
14802
15045
|
return this;
|
|
14803
15046
|
}
|
|
14804
15047
|
/**
|
|
14805
|
-
* Alias for connect()
|
|
15048
|
+
* Alias for {@link connect()}.
|
|
14806
15049
|
*/
|
|
14807
15050
|
open() {
|
|
14808
15051
|
return this.connect();
|
|
@@ -14810,8 +15053,17 @@
|
|
|
14810
15053
|
/**
|
|
14811
15054
|
* Sends a `message` event.
|
|
14812
15055
|
*
|
|
15056
|
+
* This method mimics the WebSocket.send() method.
|
|
15057
|
+
*
|
|
15058
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
|
|
15059
|
+
*
|
|
15060
|
+
* @example
|
|
15061
|
+
* socket.send("hello");
|
|
15062
|
+
*
|
|
15063
|
+
* // this is equivalent to
|
|
15064
|
+
* socket.emit("message", "hello");
|
|
15065
|
+
*
|
|
14813
15066
|
* @return self
|
|
14814
|
-
* @public
|
|
14815
15067
|
*/
|
|
14816
15068
|
send(...args) {
|
|
14817
15069
|
args.unshift("message");
|
|
@@ -14822,14 +15074,28 @@
|
|
|
14822
15074
|
* Override `emit`.
|
|
14823
15075
|
* If the event is in `events`, it's emitted normally.
|
|
14824
15076
|
*
|
|
15077
|
+
* @example
|
|
15078
|
+
* socket.emit("hello", "world");
|
|
15079
|
+
*
|
|
15080
|
+
* // all serializable datastructures are supported (no need to call JSON.stringify)
|
|
15081
|
+
* socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
|
|
15082
|
+
*
|
|
15083
|
+
* // with an acknowledgement from the server
|
|
15084
|
+
* socket.emit("hello", "world", (val) => {
|
|
15085
|
+
* // ...
|
|
15086
|
+
* });
|
|
15087
|
+
*
|
|
14825
15088
|
* @return self
|
|
14826
|
-
* @public
|
|
14827
15089
|
*/
|
|
14828
15090
|
emit(ev, ...args) {
|
|
14829
15091
|
if (RESERVED_EVENTS.hasOwnProperty(ev)) {
|
|
14830
|
-
throw new Error('"' + ev + '" is a reserved event name');
|
|
15092
|
+
throw new Error('"' + ev.toString() + '" is a reserved event name');
|
|
14831
15093
|
}
|
|
14832
15094
|
args.unshift(ev);
|
|
15095
|
+
if (this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) {
|
|
15096
|
+
this._addToQueue(args);
|
|
15097
|
+
return this;
|
|
15098
|
+
}
|
|
14833
15099
|
const packet = {
|
|
14834
15100
|
type: PacketType.EVENT,
|
|
14835
15101
|
data: args,
|
|
@@ -14849,6 +15115,7 @@
|
|
|
14849
15115
|
const discardPacket = this.flags.volatile && (!isTransportWritable || !this.connected);
|
|
14850
15116
|
if (discardPacket) ;
|
|
14851
15117
|
else if (this.connected) {
|
|
15118
|
+
this.notifyOutgoingListeners(packet);
|
|
14852
15119
|
this.packet(packet);
|
|
14853
15120
|
}
|
|
14854
15121
|
else {
|
|
@@ -14861,7 +15128,8 @@
|
|
|
14861
15128
|
* @private
|
|
14862
15129
|
*/
|
|
14863
15130
|
_registerAckCallback(id, ack) {
|
|
14864
|
-
|
|
15131
|
+
var _a;
|
|
15132
|
+
const timeout = (_a = this.flags.timeout) !== null && _a !== void 0 ? _a : this._opts.ackTimeout;
|
|
14865
15133
|
if (timeout === undefined) {
|
|
14866
15134
|
this.acks[id] = ack;
|
|
14867
15135
|
return;
|
|
@@ -14882,6 +15150,99 @@
|
|
|
14882
15150
|
ack.apply(this, [null, ...args]);
|
|
14883
15151
|
};
|
|
14884
15152
|
}
|
|
15153
|
+
/**
|
|
15154
|
+
* Emits an event and waits for an acknowledgement
|
|
15155
|
+
*
|
|
15156
|
+
* @example
|
|
15157
|
+
* // without timeout
|
|
15158
|
+
* const response = await socket.emitWithAck("hello", "world");
|
|
15159
|
+
*
|
|
15160
|
+
* // with a specific timeout
|
|
15161
|
+
* try {
|
|
15162
|
+
* const response = await socket.timeout(1000).emitWithAck("hello", "world");
|
|
15163
|
+
* } catch (err) {
|
|
15164
|
+
* // the server did not acknowledge the event in the given delay
|
|
15165
|
+
* }
|
|
15166
|
+
*
|
|
15167
|
+
* @return a Promise that will be fulfilled when the server acknowledges the event
|
|
15168
|
+
*/
|
|
15169
|
+
emitWithAck(ev, ...args) {
|
|
15170
|
+
// the timeout flag is optional
|
|
15171
|
+
const withErr = this.flags.timeout !== undefined || this._opts.ackTimeout !== undefined;
|
|
15172
|
+
return new Promise((resolve, reject) => {
|
|
15173
|
+
args.push((arg1, arg2) => {
|
|
15174
|
+
if (withErr) {
|
|
15175
|
+
return arg1 ? reject(arg1) : resolve(arg2);
|
|
15176
|
+
}
|
|
15177
|
+
else {
|
|
15178
|
+
return resolve(arg1);
|
|
15179
|
+
}
|
|
15180
|
+
});
|
|
15181
|
+
this.emit(ev, ...args);
|
|
15182
|
+
});
|
|
15183
|
+
}
|
|
15184
|
+
/**
|
|
15185
|
+
* Add the packet to the queue.
|
|
15186
|
+
* @param args
|
|
15187
|
+
* @private
|
|
15188
|
+
*/
|
|
15189
|
+
_addToQueue(args) {
|
|
15190
|
+
let ack;
|
|
15191
|
+
if (typeof args[args.length - 1] === "function") {
|
|
15192
|
+
ack = args.pop();
|
|
15193
|
+
}
|
|
15194
|
+
const packet = {
|
|
15195
|
+
id: this._queueSeq++,
|
|
15196
|
+
tryCount: 0,
|
|
15197
|
+
pending: false,
|
|
15198
|
+
args,
|
|
15199
|
+
flags: Object.assign({ fromQueue: true }, this.flags),
|
|
15200
|
+
};
|
|
15201
|
+
args.push((err, ...responseArgs) => {
|
|
15202
|
+
if (packet !== this._queue[0]) {
|
|
15203
|
+
// the packet has already been acknowledged
|
|
15204
|
+
return;
|
|
15205
|
+
}
|
|
15206
|
+
const hasError = err !== null;
|
|
15207
|
+
if (hasError) {
|
|
15208
|
+
if (packet.tryCount > this._opts.retries) {
|
|
15209
|
+
this._queue.shift();
|
|
15210
|
+
if (ack) {
|
|
15211
|
+
ack(err);
|
|
15212
|
+
}
|
|
15213
|
+
}
|
|
15214
|
+
}
|
|
15215
|
+
else {
|
|
15216
|
+
this._queue.shift();
|
|
15217
|
+
if (ack) {
|
|
15218
|
+
ack(null, ...responseArgs);
|
|
15219
|
+
}
|
|
15220
|
+
}
|
|
15221
|
+
packet.pending = false;
|
|
15222
|
+
return this._drainQueue();
|
|
15223
|
+
});
|
|
15224
|
+
this._queue.push(packet);
|
|
15225
|
+
this._drainQueue();
|
|
15226
|
+
}
|
|
15227
|
+
/**
|
|
15228
|
+
* Send the first packet of the queue, and wait for an acknowledgement from the server.
|
|
15229
|
+
* @param force - whether to resend a packet that has not been acknowledged yet
|
|
15230
|
+
*
|
|
15231
|
+
* @private
|
|
15232
|
+
*/
|
|
15233
|
+
_drainQueue(force = false) {
|
|
15234
|
+
if (!this.connected || this._queue.length === 0) {
|
|
15235
|
+
return;
|
|
15236
|
+
}
|
|
15237
|
+
const packet = this._queue[0];
|
|
15238
|
+
if (packet.pending && !force) {
|
|
15239
|
+
return;
|
|
15240
|
+
}
|
|
15241
|
+
packet.pending = true;
|
|
15242
|
+
packet.tryCount++;
|
|
15243
|
+
this.flags = packet.flags;
|
|
15244
|
+
this.emit.apply(this, packet.args);
|
|
15245
|
+
}
|
|
14885
15246
|
/**
|
|
14886
15247
|
* Sends a packet.
|
|
14887
15248
|
*
|
|
@@ -14900,13 +15261,27 @@
|
|
|
14900
15261
|
onopen() {
|
|
14901
15262
|
if (typeof this.auth == "function") {
|
|
14902
15263
|
this.auth((data) => {
|
|
14903
|
-
this.
|
|
15264
|
+
this._sendConnectPacket(data);
|
|
14904
15265
|
});
|
|
14905
15266
|
}
|
|
14906
15267
|
else {
|
|
14907
|
-
this.
|
|
15268
|
+
this._sendConnectPacket(this.auth);
|
|
14908
15269
|
}
|
|
14909
15270
|
}
|
|
15271
|
+
/**
|
|
15272
|
+
* Sends a CONNECT packet to initiate the Socket.IO session.
|
|
15273
|
+
*
|
|
15274
|
+
* @param data
|
|
15275
|
+
* @private
|
|
15276
|
+
*/
|
|
15277
|
+
_sendConnectPacket(data) {
|
|
15278
|
+
this.packet({
|
|
15279
|
+
type: PacketType.CONNECT,
|
|
15280
|
+
data: this._pid
|
|
15281
|
+
? Object.assign({ pid: this._pid, offset: this._lastOffset }, data)
|
|
15282
|
+
: data,
|
|
15283
|
+
});
|
|
15284
|
+
}
|
|
14910
15285
|
/**
|
|
14911
15286
|
* Called upon engine or manager `error`.
|
|
14912
15287
|
*
|
|
@@ -14922,13 +15297,13 @@
|
|
|
14922
15297
|
* Called upon engine `close`.
|
|
14923
15298
|
*
|
|
14924
15299
|
* @param reason
|
|
15300
|
+
* @param description
|
|
14925
15301
|
* @private
|
|
14926
15302
|
*/
|
|
14927
|
-
onclose(reason) {
|
|
15303
|
+
onclose(reason, description) {
|
|
14928
15304
|
this.connected = false;
|
|
14929
|
-
this.disconnected = true;
|
|
14930
15305
|
delete this.id;
|
|
14931
|
-
this.emitReserved("disconnect", reason);
|
|
15306
|
+
this.emitReserved("disconnect", reason, description);
|
|
14932
15307
|
}
|
|
14933
15308
|
/**
|
|
14934
15309
|
* Called with socket packet.
|
|
@@ -14943,22 +15318,17 @@
|
|
|
14943
15318
|
switch (packet.type) {
|
|
14944
15319
|
case PacketType.CONNECT:
|
|
14945
15320
|
if (packet.data && packet.data.sid) {
|
|
14946
|
-
|
|
14947
|
-
this.onconnect(id);
|
|
15321
|
+
this.onconnect(packet.data.sid, packet.data.pid);
|
|
14948
15322
|
}
|
|
14949
15323
|
else {
|
|
14950
15324
|
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
15325
|
}
|
|
14952
15326
|
break;
|
|
14953
15327
|
case PacketType.EVENT:
|
|
14954
|
-
this.onevent(packet);
|
|
14955
|
-
break;
|
|
14956
15328
|
case PacketType.BINARY_EVENT:
|
|
14957
15329
|
this.onevent(packet);
|
|
14958
15330
|
break;
|
|
14959
15331
|
case PacketType.ACK:
|
|
14960
|
-
this.onack(packet);
|
|
14961
|
-
break;
|
|
14962
15332
|
case PacketType.BINARY_ACK:
|
|
14963
15333
|
this.onack(packet);
|
|
14964
15334
|
break;
|
|
@@ -15000,6 +15370,9 @@
|
|
|
15000
15370
|
}
|
|
15001
15371
|
}
|
|
15002
15372
|
super.emit.apply(this, args);
|
|
15373
|
+
if (this._pid && args.length && typeof args[args.length - 1] === "string") {
|
|
15374
|
+
this._lastOffset = args[args.length - 1];
|
|
15375
|
+
}
|
|
15003
15376
|
}
|
|
15004
15377
|
/**
|
|
15005
15378
|
* Produces an ack callback to emit with an event.
|
|
@@ -15039,12 +15412,14 @@
|
|
|
15039
15412
|
*
|
|
15040
15413
|
* @private
|
|
15041
15414
|
*/
|
|
15042
|
-
onconnect(id) {
|
|
15415
|
+
onconnect(id, pid) {
|
|
15043
15416
|
this.id = id;
|
|
15417
|
+
this.recovered = pid && this._pid === pid;
|
|
15418
|
+
this._pid = pid; // defined only if connection state recovery is enabled
|
|
15044
15419
|
this.connected = true;
|
|
15045
|
-
this.disconnected = false;
|
|
15046
15420
|
this.emitBuffered();
|
|
15047
15421
|
this.emitReserved("connect");
|
|
15422
|
+
this._drainQueue(true);
|
|
15048
15423
|
}
|
|
15049
15424
|
/**
|
|
15050
15425
|
* Emit buffered events (received and emitted).
|
|
@@ -15054,7 +15429,10 @@
|
|
|
15054
15429
|
emitBuffered() {
|
|
15055
15430
|
this.receiveBuffer.forEach((args) => this.emitEvent(args));
|
|
15056
15431
|
this.receiveBuffer = [];
|
|
15057
|
-
this.sendBuffer.forEach((packet) =>
|
|
15432
|
+
this.sendBuffer.forEach((packet) => {
|
|
15433
|
+
this.notifyOutgoingListeners(packet);
|
|
15434
|
+
this.packet(packet);
|
|
15435
|
+
});
|
|
15058
15436
|
this.sendBuffer = [];
|
|
15059
15437
|
}
|
|
15060
15438
|
/**
|
|
@@ -15082,10 +15460,20 @@
|
|
|
15082
15460
|
this.io["_destroy"](this);
|
|
15083
15461
|
}
|
|
15084
15462
|
/**
|
|
15085
|
-
* Disconnects the socket manually.
|
|
15463
|
+
* Disconnects the socket manually. In that case, the socket will not try to reconnect.
|
|
15464
|
+
*
|
|
15465
|
+
* If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
|
|
15466
|
+
*
|
|
15467
|
+
* @example
|
|
15468
|
+
* const socket = io();
|
|
15469
|
+
*
|
|
15470
|
+
* socket.on("disconnect", (reason) => {
|
|
15471
|
+
* // console.log(reason); prints "io client disconnect"
|
|
15472
|
+
* });
|
|
15473
|
+
*
|
|
15474
|
+
* socket.disconnect();
|
|
15086
15475
|
*
|
|
15087
15476
|
* @return self
|
|
15088
|
-
* @public
|
|
15089
15477
|
*/
|
|
15090
15478
|
disconnect() {
|
|
15091
15479
|
if (this.connected) {
|
|
@@ -15100,10 +15488,9 @@
|
|
|
15100
15488
|
return this;
|
|
15101
15489
|
}
|
|
15102
15490
|
/**
|
|
15103
|
-
* Alias for disconnect()
|
|
15491
|
+
* Alias for {@link disconnect()}.
|
|
15104
15492
|
*
|
|
15105
15493
|
* @return self
|
|
15106
|
-
* @public
|
|
15107
15494
|
*/
|
|
15108
15495
|
close() {
|
|
15109
15496
|
return this.disconnect();
|
|
@@ -15111,9 +15498,11 @@
|
|
|
15111
15498
|
/**
|
|
15112
15499
|
* Sets the compress flag.
|
|
15113
15500
|
*
|
|
15501
|
+
* @example
|
|
15502
|
+
* socket.compress(false).emit("hello");
|
|
15503
|
+
*
|
|
15114
15504
|
* @param compress - if `true`, compresses the sending data
|
|
15115
15505
|
* @return self
|
|
15116
|
-
* @public
|
|
15117
15506
|
*/
|
|
15118
15507
|
compress(compress) {
|
|
15119
15508
|
this.flags.compress = compress;
|
|
@@ -15123,8 +15512,10 @@
|
|
|
15123
15512
|
* Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
|
|
15124
15513
|
* ready to send messages.
|
|
15125
15514
|
*
|
|
15515
|
+
* @example
|
|
15516
|
+
* socket.volatile.emit("hello"); // the server may or may not receive it
|
|
15517
|
+
*
|
|
15126
15518
|
* @returns self
|
|
15127
|
-
* @public
|
|
15128
15519
|
*/
|
|
15129
15520
|
get volatile() {
|
|
15130
15521
|
this.flags.volatile = true;
|
|
@@ -15134,16 +15525,14 @@
|
|
|
15134
15525
|
* Sets a modifier for a subsequent event emission that the callback will be called with an error when the
|
|
15135
15526
|
* given number of milliseconds have elapsed without an acknowledgement from the server:
|
|
15136
15527
|
*
|
|
15137
|
-
*
|
|
15528
|
+
* @example
|
|
15138
15529
|
* socket.timeout(5000).emit("my-event", (err) => {
|
|
15139
15530
|
* if (err) {
|
|
15140
15531
|
* // the server did not acknowledge the event in the given delay
|
|
15141
15532
|
* }
|
|
15142
15533
|
* });
|
|
15143
|
-
* ```
|
|
15144
15534
|
*
|
|
15145
15535
|
* @returns self
|
|
15146
|
-
* @public
|
|
15147
15536
|
*/
|
|
15148
15537
|
timeout(timeout) {
|
|
15149
15538
|
this.flags.timeout = timeout;
|
|
@@ -15153,8 +15542,12 @@
|
|
|
15153
15542
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
15154
15543
|
* callback.
|
|
15155
15544
|
*
|
|
15545
|
+
* @example
|
|
15546
|
+
* socket.onAny((event, ...args) => {
|
|
15547
|
+
* console.log(`got ${event}`);
|
|
15548
|
+
* });
|
|
15549
|
+
*
|
|
15156
15550
|
* @param listener
|
|
15157
|
-
* @public
|
|
15158
15551
|
*/
|
|
15159
15552
|
onAny(listener) {
|
|
15160
15553
|
this._anyListeners = this._anyListeners || [];
|
|
@@ -15165,8 +15558,12 @@
|
|
|
15165
15558
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
15166
15559
|
* callback. The listener is added to the beginning of the listeners array.
|
|
15167
15560
|
*
|
|
15561
|
+
* @example
|
|
15562
|
+
* socket.prependAny((event, ...args) => {
|
|
15563
|
+
* console.log(`got event ${event}`);
|
|
15564
|
+
* });
|
|
15565
|
+
*
|
|
15168
15566
|
* @param listener
|
|
15169
|
-
* @public
|
|
15170
15567
|
*/
|
|
15171
15568
|
prependAny(listener) {
|
|
15172
15569
|
this._anyListeners = this._anyListeners || [];
|
|
@@ -15176,8 +15573,20 @@
|
|
|
15176
15573
|
/**
|
|
15177
15574
|
* Removes the listener that will be fired when any event is emitted.
|
|
15178
15575
|
*
|
|
15576
|
+
* @example
|
|
15577
|
+
* const catchAllListener = (event, ...args) => {
|
|
15578
|
+
* console.log(`got event ${event}`);
|
|
15579
|
+
* }
|
|
15580
|
+
*
|
|
15581
|
+
* socket.onAny(catchAllListener);
|
|
15582
|
+
*
|
|
15583
|
+
* // remove a specific listener
|
|
15584
|
+
* socket.offAny(catchAllListener);
|
|
15585
|
+
*
|
|
15586
|
+
* // or remove all listeners
|
|
15587
|
+
* socket.offAny();
|
|
15588
|
+
*
|
|
15179
15589
|
* @param listener
|
|
15180
|
-
* @public
|
|
15181
15590
|
*/
|
|
15182
15591
|
offAny(listener) {
|
|
15183
15592
|
if (!this._anyListeners) {
|
|
@@ -15200,20 +15609,106 @@
|
|
|
15200
15609
|
/**
|
|
15201
15610
|
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
15202
15611
|
* e.g. to remove listeners.
|
|
15203
|
-
*
|
|
15204
|
-
* @public
|
|
15205
15612
|
*/
|
|
15206
15613
|
listenersAny() {
|
|
15207
15614
|
return this._anyListeners || [];
|
|
15208
15615
|
}
|
|
15616
|
+
/**
|
|
15617
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
15618
|
+
* callback.
|
|
15619
|
+
*
|
|
15620
|
+
* Note: acknowledgements sent to the server are not included.
|
|
15621
|
+
*
|
|
15622
|
+
* @example
|
|
15623
|
+
* socket.onAnyOutgoing((event, ...args) => {
|
|
15624
|
+
* console.log(`sent event ${event}`);
|
|
15625
|
+
* });
|
|
15626
|
+
*
|
|
15627
|
+
* @param listener
|
|
15628
|
+
*/
|
|
15629
|
+
onAnyOutgoing(listener) {
|
|
15630
|
+
this._anyOutgoingListeners = this._anyOutgoingListeners || [];
|
|
15631
|
+
this._anyOutgoingListeners.push(listener);
|
|
15632
|
+
return this;
|
|
15633
|
+
}
|
|
15634
|
+
/**
|
|
15635
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
15636
|
+
* callback. The listener is added to the beginning of the listeners array.
|
|
15637
|
+
*
|
|
15638
|
+
* Note: acknowledgements sent to the server are not included.
|
|
15639
|
+
*
|
|
15640
|
+
* @example
|
|
15641
|
+
* socket.prependAnyOutgoing((event, ...args) => {
|
|
15642
|
+
* console.log(`sent event ${event}`);
|
|
15643
|
+
* });
|
|
15644
|
+
*
|
|
15645
|
+
* @param listener
|
|
15646
|
+
*/
|
|
15647
|
+
prependAnyOutgoing(listener) {
|
|
15648
|
+
this._anyOutgoingListeners = this._anyOutgoingListeners || [];
|
|
15649
|
+
this._anyOutgoingListeners.unshift(listener);
|
|
15650
|
+
return this;
|
|
15651
|
+
}
|
|
15652
|
+
/**
|
|
15653
|
+
* Removes the listener that will be fired when any event is emitted.
|
|
15654
|
+
*
|
|
15655
|
+
* @example
|
|
15656
|
+
* const catchAllListener = (event, ...args) => {
|
|
15657
|
+
* console.log(`sent event ${event}`);
|
|
15658
|
+
* }
|
|
15659
|
+
*
|
|
15660
|
+
* socket.onAnyOutgoing(catchAllListener);
|
|
15661
|
+
*
|
|
15662
|
+
* // remove a specific listener
|
|
15663
|
+
* socket.offAnyOutgoing(catchAllListener);
|
|
15664
|
+
*
|
|
15665
|
+
* // or remove all listeners
|
|
15666
|
+
* socket.offAnyOutgoing();
|
|
15667
|
+
*
|
|
15668
|
+
* @param [listener] - the catch-all listener (optional)
|
|
15669
|
+
*/
|
|
15670
|
+
offAnyOutgoing(listener) {
|
|
15671
|
+
if (!this._anyOutgoingListeners) {
|
|
15672
|
+
return this;
|
|
15673
|
+
}
|
|
15674
|
+
if (listener) {
|
|
15675
|
+
const listeners = this._anyOutgoingListeners;
|
|
15676
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
15677
|
+
if (listener === listeners[i]) {
|
|
15678
|
+
listeners.splice(i, 1);
|
|
15679
|
+
return this;
|
|
15680
|
+
}
|
|
15681
|
+
}
|
|
15682
|
+
}
|
|
15683
|
+
else {
|
|
15684
|
+
this._anyOutgoingListeners = [];
|
|
15685
|
+
}
|
|
15686
|
+
return this;
|
|
15687
|
+
}
|
|
15688
|
+
/**
|
|
15689
|
+
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
15690
|
+
* e.g. to remove listeners.
|
|
15691
|
+
*/
|
|
15692
|
+
listenersAnyOutgoing() {
|
|
15693
|
+
return this._anyOutgoingListeners || [];
|
|
15694
|
+
}
|
|
15695
|
+
/**
|
|
15696
|
+
* Notify the listeners for each packet sent
|
|
15697
|
+
*
|
|
15698
|
+
* @param packet
|
|
15699
|
+
*
|
|
15700
|
+
* @private
|
|
15701
|
+
*/
|
|
15702
|
+
notifyOutgoingListeners(packet) {
|
|
15703
|
+
if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
|
|
15704
|
+
const listeners = this._anyOutgoingListeners.slice();
|
|
15705
|
+
for (const listener of listeners) {
|
|
15706
|
+
listener.apply(this, packet.data);
|
|
15707
|
+
}
|
|
15708
|
+
}
|
|
15709
|
+
}
|
|
15209
15710
|
}
|
|
15210
15711
|
|
|
15211
|
-
/**
|
|
15212
|
-
* Expose `Backoff`.
|
|
15213
|
-
*/
|
|
15214
|
-
|
|
15215
|
-
var backo2 = Backoff;
|
|
15216
|
-
|
|
15217
15712
|
/**
|
|
15218
15713
|
* Initialize backoff timer with `opts`.
|
|
15219
15714
|
*
|
|
@@ -15225,74 +15720,63 @@
|
|
|
15225
15720
|
* @param {Object} opts
|
|
15226
15721
|
* @api public
|
|
15227
15722
|
*/
|
|
15228
|
-
|
|
15229
15723
|
function Backoff(opts) {
|
|
15230
|
-
|
|
15231
|
-
|
|
15232
|
-
|
|
15233
|
-
|
|
15234
|
-
|
|
15235
|
-
|
|
15724
|
+
opts = opts || {};
|
|
15725
|
+
this.ms = opts.min || 100;
|
|
15726
|
+
this.max = opts.max || 10000;
|
|
15727
|
+
this.factor = opts.factor || 2;
|
|
15728
|
+
this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
|
|
15729
|
+
this.attempts = 0;
|
|
15236
15730
|
}
|
|
15237
|
-
|
|
15238
15731
|
/**
|
|
15239
15732
|
* Return the backoff duration.
|
|
15240
15733
|
*
|
|
15241
15734
|
* @return {Number}
|
|
15242
15735
|
* @api public
|
|
15243
15736
|
*/
|
|
15244
|
-
|
|
15245
|
-
|
|
15246
|
-
|
|
15247
|
-
|
|
15248
|
-
|
|
15249
|
-
|
|
15250
|
-
|
|
15251
|
-
|
|
15252
|
-
return Math.min(ms, this.max) | 0;
|
|
15737
|
+
Backoff.prototype.duration = function () {
|
|
15738
|
+
var ms = this.ms * Math.pow(this.factor, this.attempts++);
|
|
15739
|
+
if (this.jitter) {
|
|
15740
|
+
var rand = Math.random();
|
|
15741
|
+
var deviation = Math.floor(rand * this.jitter * ms);
|
|
15742
|
+
ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
|
|
15743
|
+
}
|
|
15744
|
+
return Math.min(ms, this.max) | 0;
|
|
15253
15745
|
};
|
|
15254
|
-
|
|
15255
15746
|
/**
|
|
15256
15747
|
* Reset the number of attempts.
|
|
15257
15748
|
*
|
|
15258
15749
|
* @api public
|
|
15259
15750
|
*/
|
|
15260
|
-
|
|
15261
|
-
|
|
15262
|
-
this.attempts = 0;
|
|
15751
|
+
Backoff.prototype.reset = function () {
|
|
15752
|
+
this.attempts = 0;
|
|
15263
15753
|
};
|
|
15264
|
-
|
|
15265
15754
|
/**
|
|
15266
15755
|
* Set the minimum duration
|
|
15267
15756
|
*
|
|
15268
15757
|
* @api public
|
|
15269
15758
|
*/
|
|
15270
|
-
|
|
15271
|
-
|
|
15272
|
-
this.ms = min;
|
|
15759
|
+
Backoff.prototype.setMin = function (min) {
|
|
15760
|
+
this.ms = min;
|
|
15273
15761
|
};
|
|
15274
|
-
|
|
15275
15762
|
/**
|
|
15276
15763
|
* Set the maximum duration
|
|
15277
15764
|
*
|
|
15278
15765
|
* @api public
|
|
15279
15766
|
*/
|
|
15280
|
-
|
|
15281
|
-
|
|
15282
|
-
this.max = max;
|
|
15767
|
+
Backoff.prototype.setMax = function (max) {
|
|
15768
|
+
this.max = max;
|
|
15283
15769
|
};
|
|
15284
|
-
|
|
15285
15770
|
/**
|
|
15286
15771
|
* Set the jitter
|
|
15287
15772
|
*
|
|
15288
15773
|
* @api public
|
|
15289
15774
|
*/
|
|
15290
|
-
|
|
15291
|
-
|
|
15292
|
-
this.jitter = jitter;
|
|
15775
|
+
Backoff.prototype.setJitter = function (jitter) {
|
|
15776
|
+
this.jitter = jitter;
|
|
15293
15777
|
};
|
|
15294
15778
|
|
|
15295
|
-
class Manager extends
|
|
15779
|
+
class Manager extends Emitter {
|
|
15296
15780
|
constructor(uri, opts) {
|
|
15297
15781
|
var _a;
|
|
15298
15782
|
super();
|
|
@@ -15311,7 +15795,7 @@
|
|
|
15311
15795
|
this.reconnectionDelay(opts.reconnectionDelay || 1000);
|
|
15312
15796
|
this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
|
|
15313
15797
|
this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : 0.5);
|
|
15314
|
-
this.backoff = new
|
|
15798
|
+
this.backoff = new Backoff({
|
|
15315
15799
|
min: this.reconnectionDelay(),
|
|
15316
15800
|
max: this.reconnectionDelayMax(),
|
|
15317
15801
|
jitter: this.randomizationFactor(),
|
|
@@ -15477,7 +15961,12 @@
|
|
|
15477
15961
|
* @private
|
|
15478
15962
|
*/
|
|
15479
15963
|
ondata(data) {
|
|
15480
|
-
|
|
15964
|
+
try {
|
|
15965
|
+
this.decoder.add(data);
|
|
15966
|
+
}
|
|
15967
|
+
catch (e) {
|
|
15968
|
+
this.onclose("parse error", e);
|
|
15969
|
+
}
|
|
15481
15970
|
}
|
|
15482
15971
|
/**
|
|
15483
15972
|
* Called when parser fully decodes a packet.
|
|
@@ -15485,7 +15974,10 @@
|
|
|
15485
15974
|
* @private
|
|
15486
15975
|
*/
|
|
15487
15976
|
ondecoded(packet) {
|
|
15488
|
-
|
|
15977
|
+
// the nextTick call prevents an exception in a user-provided event listener from triggering a disconnection due to a "parse error"
|
|
15978
|
+
nextTick(() => {
|
|
15979
|
+
this.emitReserved("packet", packet);
|
|
15980
|
+
}, this.setTimeoutFn);
|
|
15489
15981
|
}
|
|
15490
15982
|
/**
|
|
15491
15983
|
* Called upon socket error.
|
|
@@ -15507,6 +15999,9 @@
|
|
|
15507
15999
|
socket = new Socket(this, nsp, opts);
|
|
15508
16000
|
this.nsps[nsp] = socket;
|
|
15509
16001
|
}
|
|
16002
|
+
else if (this._autoConnect && !socket.active) {
|
|
16003
|
+
socket.connect();
|
|
16004
|
+
}
|
|
15510
16005
|
return socket;
|
|
15511
16006
|
}
|
|
15512
16007
|
/**
|
|
@@ -15572,11 +16067,11 @@
|
|
|
15572
16067
|
*
|
|
15573
16068
|
* @private
|
|
15574
16069
|
*/
|
|
15575
|
-
onclose(reason) {
|
|
16070
|
+
onclose(reason, description) {
|
|
15576
16071
|
this.cleanup();
|
|
15577
16072
|
this.backoff.reset();
|
|
15578
16073
|
this._readyState = "closed";
|
|
15579
|
-
this.emitReserved("close", reason);
|
|
16074
|
+
this.emitReserved("close", reason, description);
|
|
15580
16075
|
if (this._reconnection && !this.skipReconnect) {
|
|
15581
16076
|
this.reconnect();
|
|
15582
16077
|
}
|
|
@@ -16012,6 +16507,9 @@
|
|
|
16012
16507
|
exports.InlineObjectFromJSON = InlineObjectFromJSON;
|
|
16013
16508
|
exports.InlineObjectFromJSONTyped = InlineObjectFromJSONTyped;
|
|
16014
16509
|
exports.InlineObjectToJSON = InlineObjectToJSON;
|
|
16510
|
+
exports.InlineResponse403FromJSON = InlineResponse403FromJSON;
|
|
16511
|
+
exports.InlineResponse403FromJSONTyped = InlineResponse403FromJSONTyped;
|
|
16512
|
+
exports.InlineResponse403ToJSON = InlineResponse403ToJSON;
|
|
16015
16513
|
exports.JSONApiResponse = JSONApiResponse;
|
|
16016
16514
|
exports.MapEntryResponseFromJSON = MapEntryResponseFromJSON;
|
|
16017
16515
|
exports.MapEntryResponseFromJSONTyped = MapEntryResponseFromJSONTyped;
|
|
@@ -16076,6 +16574,12 @@
|
|
|
16076
16574
|
exports.OtherTransactionIdentifierFromJSON = OtherTransactionIdentifierFromJSON;
|
|
16077
16575
|
exports.OtherTransactionIdentifierFromJSONTyped = OtherTransactionIdentifierFromJSONTyped;
|
|
16078
16576
|
exports.OtherTransactionIdentifierToJSON = OtherTransactionIdentifierToJSON;
|
|
16577
|
+
exports.PoolDelegationFromJSON = PoolDelegationFromJSON;
|
|
16578
|
+
exports.PoolDelegationFromJSONTyped = PoolDelegationFromJSONTyped;
|
|
16579
|
+
exports.PoolDelegationToJSON = PoolDelegationToJSON;
|
|
16580
|
+
exports.PoolDelegationsResponseFromJSON = PoolDelegationsResponseFromJSON;
|
|
16581
|
+
exports.PoolDelegationsResponseFromJSONTyped = PoolDelegationsResponseFromJSONTyped;
|
|
16582
|
+
exports.PoolDelegationsResponseToJSON = PoolDelegationsResponseToJSON;
|
|
16079
16583
|
exports.PostCoreNodeTransactionsErrorFromJSON = PostCoreNodeTransactionsErrorFromJSON;
|
|
16080
16584
|
exports.PostCoreNodeTransactionsErrorFromJSONTyped = PostCoreNodeTransactionsErrorFromJSONTyped;
|
|
16081
16585
|
exports.PostCoreNodeTransactionsErrorToJSON = PostCoreNodeTransactionsErrorToJSON;
|
|
@@ -16296,6 +16800,7 @@
|
|
|
16296
16800
|
exports.SmartContractFromJSONTyped = SmartContractFromJSONTyped;
|
|
16297
16801
|
exports.SmartContractToJSON = SmartContractToJSON;
|
|
16298
16802
|
exports.SmartContractsApi = SmartContractsApi;
|
|
16803
|
+
exports.StackingApi = StackingApi;
|
|
16299
16804
|
exports.StackingRewardsApi = StackingRewardsApi;
|
|
16300
16805
|
exports.StacksApiSocketClient = StacksApiSocketClient;
|
|
16301
16806
|
exports.StacksApiWebSocketClient = StacksApiWebSocketClient;
|