File size: 73,477 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 |
/*!
* Engine.IO v6.5.4
* (c) 2014-2024 Guillermo Rauch
* Released under the MIT License.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.eio = factory());
})(this, (function () { 'use strict';
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class);
};
return _wrapNativeSuper(Class);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _superPropBase(object, property) {
while (!Object.prototype.hasOwnProperty.call(object, property)) {
object = _getPrototypeOf(object);
if (object === null) break;
}
return object;
}
function _get(target, property, receiver) {
if (typeof Reflect !== "undefined" && Reflect.get) {
_get = Reflect.get;
} else {
_get = function _get(target, property, receiver) {
var base = _superPropBase(target, property);
if (!base) return;
var desc = Object.getOwnPropertyDescriptor(base, property);
if (desc.get) {
return desc.get.call(receiver);
}
return desc.value;
};
}
return _get(target, property, receiver || target);
}
var PACKET_TYPES = Object.create(null); // no Map = no polyfill
PACKET_TYPES["open"] = "0";
PACKET_TYPES["close"] = "1";
PACKET_TYPES["ping"] = "2";
PACKET_TYPES["pong"] = "3";
PACKET_TYPES["message"] = "4";
PACKET_TYPES["upgrade"] = "5";
PACKET_TYPES["noop"] = "6";
var PACKET_TYPES_REVERSE = Object.create(null);
Object.keys(PACKET_TYPES).forEach(function (key) {
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
});
var ERROR_PACKET = {
type: "error",
data: "parser error"
};
var withNativeBlob = typeof Blob === "function" || typeof Blob !== "undefined" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]";
var withNativeArrayBuffer$1 = typeof ArrayBuffer === "function";
// ArrayBuffer.isView method is not defined in IE10
var isView = function isView(obj) {
return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj && obj.buffer instanceof ArrayBuffer;
};
var encodePacket = function encodePacket(_ref, supportsBinary, callback) {
var type = _ref.type,
data = _ref.data;
if (withNativeBlob && data instanceof Blob) {
if (supportsBinary) {
return callback(data);
} else {
return encodeBlobAsBase64(data, callback);
}
} else if (withNativeArrayBuffer$1 && (data instanceof ArrayBuffer || isView(data))) {
if (supportsBinary) {
return callback(data);
} else {
return encodeBlobAsBase64(new Blob([data]), callback);
}
}
// plain string
return callback(PACKET_TYPES[type] + (data || ""));
};
var encodeBlobAsBase64 = function encodeBlobAsBase64(data, callback) {
var fileReader = new FileReader();
fileReader.onload = function () {
var content = fileReader.result.split(",")[1];
callback("b" + (content || ""));
};
return fileReader.readAsDataURL(data);
};
function toArray(data) {
if (data instanceof Uint8Array) {
return data;
} else if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
} else {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
}
var TEXT_ENCODER;
function encodePacketToBinary(packet, callback) {
if (withNativeBlob && packet.data instanceof Blob) {
return packet.data.arrayBuffer().then(toArray).then(callback);
} else if (withNativeArrayBuffer$1 && (packet.data instanceof ArrayBuffer || isView(packet.data))) {
return callback(toArray(packet.data));
}
encodePacket(packet, false, function (encoded) {
if (!TEXT_ENCODER) {
TEXT_ENCODER = new TextEncoder();
}
callback(TEXT_ENCODER.encode(encoded));
});
}
// imported from https://github.com/socketio/base64-arraybuffer
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i$1 = 0; i$1 < chars.length; i$1++) {
lookup[chars.charCodeAt(i$1)] = i$1;
}
var decode$1 = function decode(base64) {
var bufferLength = base64.length * 0.75,
len = base64.length,
i,
p = 0,
encoded1,
encoded2,
encoded3,
encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength),
bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = encoded1 << 2 | encoded2 >> 4;
bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
}
return arraybuffer;
};
var withNativeArrayBuffer = typeof ArrayBuffer === "function";
var decodePacket = function decodePacket(encodedPacket, binaryType) {
if (typeof encodedPacket !== "string") {
return {
type: "message",
data: mapBinary(encodedPacket, binaryType)
};
}
var type = encodedPacket.charAt(0);
if (type === "b") {
return {
type: "message",
data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
};
}
var packetType = PACKET_TYPES_REVERSE[type];
if (!packetType) {
return ERROR_PACKET;
}
return encodedPacket.length > 1 ? {
type: PACKET_TYPES_REVERSE[type],
data: encodedPacket.substring(1)
} : {
type: PACKET_TYPES_REVERSE[type]
};
};
var decodeBase64Packet = function decodeBase64Packet(data, binaryType) {
if (withNativeArrayBuffer) {
var decoded = decode$1(data);
return mapBinary(decoded, binaryType);
} else {
return {
base64: true,
data: data
}; // fallback for old browsers
}
};
var mapBinary = function mapBinary(data, binaryType) {
switch (binaryType) {
case "blob":
if (data instanceof Blob) {
// from WebSocket + binaryType "blob"
return data;
} else {
// from HTTP long-polling or WebTransport
return new Blob([data]);
}
case "arraybuffer":
default:
if (data instanceof ArrayBuffer) {
// from HTTP long-polling (base64) or WebSocket + binaryType "arraybuffer"
return data;
} else {
// from WebTransport (Uint8Array)
return data.buffer;
}
}
};
var SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
var encodePayload = function encodePayload(packets, callback) {
// some packets may be added to the array while encoding, so the initial length must be saved
var length = packets.length;
var encodedPackets = new Array(length);
var count = 0;
packets.forEach(function (packet, i) {
// force base64 encoding for binary packets
encodePacket(packet, false, function (encodedPacket) {
encodedPackets[i] = encodedPacket;
if (++count === length) {
callback(encodedPackets.join(SEPARATOR));
}
});
});
};
var decodePayload = function decodePayload(encodedPayload, binaryType) {
var encodedPackets = encodedPayload.split(SEPARATOR);
var packets = [];
for (var i = 0; i < encodedPackets.length; i++) {
var decodedPacket = decodePacket(encodedPackets[i], binaryType);
packets.push(decodedPacket);
if (decodedPacket.type === "error") {
break;
}
}
return packets;
};
function createPacketEncoderStream() {
return new TransformStream({
transform: function transform(packet, controller) {
encodePacketToBinary(packet, function (encodedPacket) {
var payloadLength = encodedPacket.length;
var header;
// inspired by the WebSocket format: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#decoding_payload_length
if (payloadLength < 126) {
header = new Uint8Array(1);
new DataView(header.buffer).setUint8(0, payloadLength);
} else if (payloadLength < 65536) {
header = new Uint8Array(3);
var view = new DataView(header.buffer);
view.setUint8(0, 126);
view.setUint16(1, payloadLength);
} else {
header = new Uint8Array(9);
var _view = new DataView(header.buffer);
_view.setUint8(0, 127);
_view.setBigUint64(1, BigInt(payloadLength));
}
// first bit indicates whether the payload is plain text (0) or binary (1)
if (packet.data && typeof packet.data !== "string") {
header[0] |= 0x80;
}
controller.enqueue(header);
controller.enqueue(encodedPacket);
});
}
});
}
var TEXT_DECODER;
function totalLength(chunks) {
return chunks.reduce(function (acc, chunk) {
return acc + chunk.length;
}, 0);
}
function concatChunks(chunks, size) {
if (chunks[0].length === size) {
return chunks.shift();
}
var buffer = new Uint8Array(size);
var j = 0;
for (var i = 0; i < size; i++) {
buffer[i] = chunks[0][j++];
if (j === chunks[0].length) {
chunks.shift();
j = 0;
}
}
if (chunks.length && j < chunks[0].length) {
chunks[0] = chunks[0].slice(j);
}
return buffer;
}
function createPacketDecoderStream(maxPayload, binaryType) {
if (!TEXT_DECODER) {
TEXT_DECODER = new TextDecoder();
}
var chunks = [];
var state = 0 /* READ_HEADER */;
var expectedLength = -1;
var isBinary = false;
return new TransformStream({
transform: function transform(chunk, controller) {
chunks.push(chunk);
while (true) {
if (state === 0 /* READ_HEADER */) {
if (totalLength(chunks) < 1) {
break;
}
var header = concatChunks(chunks, 1);
isBinary = (header[0] & 0x80) === 0x80;
expectedLength = header[0] & 0x7f;
if (expectedLength < 126) {
state = 3 /* READ_PAYLOAD */;
} else if (expectedLength === 126) {
state = 1 /* READ_EXTENDED_LENGTH_16 */;
} else {
state = 2 /* READ_EXTENDED_LENGTH_64 */;
}
} else if (state === 1 /* READ_EXTENDED_LENGTH_16 */) {
if (totalLength(chunks) < 2) {
break;
}
var headerArray = concatChunks(chunks, 2);
expectedLength = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length).getUint16(0);
state = 3 /* READ_PAYLOAD */;
} else if (state === 2 /* READ_EXTENDED_LENGTH_64 */) {
if (totalLength(chunks) < 8) {
break;
}
var _headerArray = concatChunks(chunks, 8);
var view = new DataView(_headerArray.buffer, _headerArray.byteOffset, _headerArray.length);
var n = view.getUint32(0);
if (n > Math.pow(2, 53 - 32) - 1) {
// the maximum safe integer in JavaScript is 2^53 - 1
controller.enqueue(ERROR_PACKET);
break;
}
expectedLength = n * Math.pow(2, 32) + view.getUint32(4);
state = 3 /* READ_PAYLOAD */;
} else {
if (totalLength(chunks) < expectedLength) {
break;
}
var data = concatChunks(chunks, expectedLength);
controller.enqueue(decodePacket(isBinary ? data : TEXT_DECODER.decode(data), binaryType));
state = 0 /* READ_HEADER */;
}
if (expectedLength === 0 || expectedLength > maxPayload) {
controller.enqueue(ERROR_PACKET);
break;
}
}
}
});
}
var protocol = 4;
/**
* Initialize a new `Emitter`.
*
* @api public
*/
function Emitter(obj) {
if (obj) return mixin(obj);
}
/**
* Mixin the emitter properties.
*
* @param {Object} obj
* @return {Object}
* @api private
*/
function mixin(obj) {
for (var key in Emitter.prototype) {
obj[key] = Emitter.prototype[key];
}
return obj;
}
/**
* Listen on the given `event` with `fn`.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
this._callbacks = this._callbacks || {};
(this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
return this;
};
/**
* Adds an `event` listener that will be invoked a single
* time then automatically removed.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.once = function (event, fn) {
function on() {
this.off(event, on);
fn.apply(this, arguments);
}
on.fn = fn;
this.on(event, on);
return this;
};
/**
* Remove the given callback for `event` or all
* registered callbacks.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
this._callbacks = this._callbacks || {};
// all
if (0 == arguments.length) {
this._callbacks = {};
return this;
}
// specific event
var callbacks = this._callbacks['$' + event];
if (!callbacks) return this;
// remove all handlers
if (1 == arguments.length) {
delete this._callbacks['$' + event];
return this;
}
// remove specific handler
var cb;
for (var i = 0; i < callbacks.length; i++) {
cb = callbacks[i];
if (cb === fn || cb.fn === fn) {
callbacks.splice(i, 1);
break;
}
}
// Remove event specific arrays for event types that no
// one is subscribed for to avoid memory leak.
if (callbacks.length === 0) {
delete this._callbacks['$' + event];
}
return this;
};
/**
* Emit `event` with the given args.
*
* @param {String} event
* @param {Mixed} ...
* @return {Emitter}
*/
Emitter.prototype.emit = function (event) {
this._callbacks = this._callbacks || {};
var args = new Array(arguments.length - 1),
callbacks = this._callbacks['$' + event];
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
if (callbacks) {
callbacks = callbacks.slice(0);
for (var i = 0, len = callbacks.length; i < len; ++i) {
callbacks[i].apply(this, args);
}
}
return this;
};
// alias used for reserved events (protected method)
Emitter.prototype.emitReserved = Emitter.prototype.emit;
/**
* Return array of callbacks for `event`.
*
* @param {String} event
* @return {Array}
* @api public
*/
Emitter.prototype.listeners = function (event) {
this._callbacks = this._callbacks || {};
return this._callbacks['$' + event] || [];
};
/**
* Check if this emitter has `event` handlers.
*
* @param {String} event
* @return {Boolean}
* @api public
*/
Emitter.prototype.hasListeners = function (event) {
return !!this.listeners(event).length;
};
var globalThisShim = function () {
if (typeof self !== "undefined") {
return self;
} else if (typeof window !== "undefined") {
return window;
} else {
return Function("return this")();
}
}();
function pick(obj) {
for (var _len = arguments.length, attr = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
attr[_key - 1] = arguments[_key];
}
return attr.reduce(function (acc, k) {
if (obj.hasOwnProperty(k)) {
acc[k] = obj[k];
}
return acc;
}, {});
}
// Keep a reference to the real timeout functions so they can be used when overridden
var NATIVE_SET_TIMEOUT = globalThisShim.setTimeout;
var NATIVE_CLEAR_TIMEOUT = globalThisShim.clearTimeout;
function installTimerFunctions(obj, opts) {
if (opts.useNativeTimers) {
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThisShim);
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThisShim);
} else {
obj.setTimeoutFn = globalThisShim.setTimeout.bind(globalThisShim);
obj.clearTimeoutFn = globalThisShim.clearTimeout.bind(globalThisShim);
}
}
// base64 encoded buffers are about 33% bigger (https://en.wikipedia.org/wiki/Base64)
var BASE64_OVERHEAD = 1.33;
// we could also have used `new Blob([obj]).size`, but it isn't supported in IE9
function byteLength(obj) {
if (typeof obj === "string") {
return utf8Length(obj);
}
// arraybuffer or blob
return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
}
function utf8Length(str) {
var c = 0,
length = 0;
for (var i = 0, l = str.length; i < l; i++) {
c = str.charCodeAt(i);
if (c < 0x80) {
length += 1;
} else if (c < 0x800) {
length += 2;
} else if (c < 0xd800 || c >= 0xe000) {
length += 3;
} else {
i++;
length += 4;
}
}
return length;
}
// imported from https://github.com/galkn/querystring
/**
* Compiles a querystring
* Returns string representation of the object
*
* @param {Object}
* @api private
*/
function encode$1(obj) {
var str = '';
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
if (str.length) str += '&';
str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
}
}
return str;
}
/**
* Parses a simple querystring into an object
*
* @param {String} qs
* @api private
*/
function decode(qs) {
var qry = {};
var pairs = qs.split('&');
for (var i = 0, l = pairs.length; i < l; i++) {
var pair = pairs[i].split('=');
qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
return qry;
}
var TransportError = /*#__PURE__*/function (_Error) {
_inherits(TransportError, _Error);
var _super = _createSuper(TransportError);
function TransportError(reason, description, context) {
var _this;
_classCallCheck(this, TransportError);
_this = _super.call(this, reason);
_this.description = description;
_this.context = context;
_this.type = "TransportError";
return _this;
}
return TransportError;
}( /*#__PURE__*/_wrapNativeSuper(Error));
var Transport = /*#__PURE__*/function (_Emitter) {
_inherits(Transport, _Emitter);
var _super2 = _createSuper(Transport);
/**
* Transport abstract constructor.
*
* @param {Object} opts - options
* @protected
*/
function Transport(opts) {
var _this2;
_classCallCheck(this, Transport);
_this2 = _super2.call(this);
_this2.writable = false;
installTimerFunctions(_assertThisInitialized(_this2), opts);
_this2.opts = opts;
_this2.query = opts.query;
_this2.socket = opts.socket;
return _this2;
}
/**
* Emits an error.
*
* @param {String} reason
* @param description
* @param context - the error context
* @return {Transport} for chaining
* @protected
*/
_createClass(Transport, [{
key: "onError",
value: function onError(reason, description, context) {
_get(_getPrototypeOf(Transport.prototype), "emitReserved", this).call(this, "error", new TransportError(reason, description, context));
return this;
}
/**
* Opens the transport.
*/
}, {
key: "open",
value: function open() {
this.readyState = "opening";
this.doOpen();
return this;
}
/**
* Closes the transport.
*/
}, {
key: "close",
value: function close() {
if (this.readyState === "opening" || this.readyState === "open") {
this.doClose();
this.onClose();
}
return this;
}
/**
* Sends multiple packets.
*
* @param {Array} packets
*/
}, {
key: "send",
value: function send(packets) {
if (this.readyState === "open") {
this.write(packets);
}
}
/**
* Called upon open
*
* @protected
*/
}, {
key: "onOpen",
value: function onOpen() {
this.readyState = "open";
this.writable = true;
_get(_getPrototypeOf(Transport.prototype), "emitReserved", this).call(this, "open");
}
/**
* Called with data.
*
* @param {String} data
* @protected
*/
}, {
key: "onData",
value: function onData(data) {
var packet = decodePacket(data, this.socket.binaryType);
this.onPacket(packet);
}
/**
* Called with a decoded packet.
*
* @protected
*/
}, {
key: "onPacket",
value: function onPacket(packet) {
_get(_getPrototypeOf(Transport.prototype), "emitReserved", this).call(this, "packet", packet);
}
/**
* Called upon close.
*
* @protected
*/
}, {
key: "onClose",
value: function onClose(details) {
this.readyState = "closed";
_get(_getPrototypeOf(Transport.prototype), "emitReserved", this).call(this, "close", details);
}
/**
* Pauses the transport, in order not to lose packets during an upgrade.
*
* @param onPause
*/
}, {
key: "pause",
value: function pause(onPause) {}
}, {
key: "createUri",
value: function createUri(schema) {
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return schema + "://" + this._hostname() + this._port() + this.opts.path + this._query(query);
}
}, {
key: "_hostname",
value: function _hostname() {
var hostname = this.opts.hostname;
return hostname.indexOf(":") === -1 ? hostname : "[" + hostname + "]";
}
}, {
key: "_port",
value: function _port() {
if (this.opts.port && (this.opts.secure && Number(this.opts.port !== 443) || !this.opts.secure && Number(this.opts.port) !== 80)) {
return ":" + this.opts.port;
} else {
return "";
}
}
}, {
key: "_query",
value: function _query(query) {
var encodedQuery = encode$1(query);
return encodedQuery.length ? "?" + encodedQuery : "";
}
}]);
return Transport;
}(Emitter);
// imported from https://github.com/unshiftio/yeast
var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split(''),
length = 64,
map = {};
var seed = 0,
i = 0,
prev;
/**
* Return a string representing the specified number.
*
* @param {Number} num The number to convert.
* @returns {String} The string representation of the number.
* @api public
*/
function encode(num) {
var encoded = '';
do {
encoded = alphabet[num % length] + encoded;
num = Math.floor(num / length);
} while (num > 0);
return encoded;
}
/**
* Yeast: A tiny growing id generator.
*
* @returns {String} A unique id.
* @api public
*/
function yeast() {
var now = encode(+new Date());
if (now !== prev) return seed = 0, prev = now;
return now + '.' + encode(seed++);
}
//
// Map each character to its index.
//
for (; i < length; i++) {
map[alphabet[i]] = i;
}
// imported from https://github.com/component/has-cors
var value = false;
try {
value = typeof XMLHttpRequest !== 'undefined' && 'withCredentials' in new XMLHttpRequest();
} catch (err) {
// if XMLHttp support is disabled in IE then it will throw
// when trying to create
}
var hasCORS = value;
// browser shim for xmlhttprequest module
function XHR(opts) {
var xdomain = opts.xdomain;
// XMLHttpRequest can be disabled on IE
try {
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
return new XMLHttpRequest();
}
} catch (e) {}
if (!xdomain) {
try {
return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
} catch (e) {}
}
}
function createCookieJar() {}
function empty() {}
var hasXHR2 = function () {
var xhr = new XHR({
xdomain: false
});
return null != xhr.responseType;
}();
var Polling = /*#__PURE__*/function (_Transport) {
_inherits(Polling, _Transport);
var _super = _createSuper(Polling);
/**
* XHR Polling constructor.
*
* @param {Object} opts
* @package
*/
function Polling(opts) {
var _this;
_classCallCheck(this, Polling);
_this = _super.call(this, opts);
_this.polling = false;
if (typeof location !== "undefined") {
var isSSL = "https:" === location.protocol;
var port = location.port;
// some user agents have empty `location.port`
if (!port) {
port = isSSL ? "443" : "80";
}
_this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port;
}
/**
* XHR supports binary
*/
var forceBase64 = opts && opts.forceBase64;
_this.supportsBinary = hasXHR2 && !forceBase64;
if (_this.opts.withCredentials) {
_this.cookieJar = createCookieJar();
}
return _this;
}
_createClass(Polling, [{
key: "doOpen",
/**
* Opens the socket (triggers polling). We write a PING message to determine
* when the transport is open.
*
* @protected
*/
value: function doOpen() {
this.poll();
}
/**
* Pauses polling.
*
* @param {Function} onPause - callback upon buffers are flushed and transport is paused
* @package
*/
}, {
key: "pause",
value: function pause(onPause) {
var _this2 = this;
this.readyState = "pausing";
var pause = function pause() {
_this2.readyState = "paused";
onPause();
};
if (this.polling || !this.writable) {
var total = 0;
if (this.polling) {
total++;
this.once("pollComplete", function () {
--total || pause();
});
}
if (!this.writable) {
total++;
this.once("drain", function () {
--total || pause();
});
}
} else {
pause();
}
}
/**
* Starts polling cycle.
*
* @private
*/
}, {
key: "poll",
value: function poll() {
this.polling = true;
this.doPoll();
this.emitReserved("poll");
}
/**
* Overloads onData to detect payloads.
*
* @protected
*/
}, {
key: "onData",
value: function onData(data) {
var _this3 = this;
var callback = function callback(packet) {
// if its the first message we consider the transport open
if ("opening" === _this3.readyState && packet.type === "open") {
_this3.onOpen();
}
// if its a close packet, we close the ongoing requests
if ("close" === packet.type) {
_this3.onClose({
description: "transport closed by the server"
});
return false;
}
// otherwise bypass onData and handle the message
_this3.onPacket(packet);
};
// decode payload
decodePayload(data, this.socket.binaryType).forEach(callback);
// if an event did not trigger closing
if ("closed" !== this.readyState) {
// if we got data we're not polling
this.polling = false;
this.emitReserved("pollComplete");
if ("open" === this.readyState) {
this.poll();
}
}
}
/**
* For polling, send a close packet.
*
* @protected
*/
}, {
key: "doClose",
value: function doClose() {
var _this4 = this;
var close = function close() {
_this4.write([{
type: "close"
}]);
};
if ("open" === this.readyState) {
close();
} else {
// in case we're trying to close while
// handshaking is in progress (GH-164)
this.once("open", close);
}
}
/**
* Writes a packets payload.
*
* @param {Array} packets - data packets
* @protected
*/
}, {
key: "write",
value: function write(packets) {
var _this5 = this;
this.writable = false;
encodePayload(packets, function (data) {
_this5.doWrite(data, function () {
_this5.writable = true;
_this5.emitReserved("drain");
});
});
}
/**
* Generates uri for connection.
*
* @private
*/
}, {
key: "uri",
value: function uri() {
var schema = this.opts.secure ? "https" : "http";
var query = this.query || {};
// cache busting is forced
if (false !== this.opts.timestampRequests) {
query[this.opts.timestampParam] = yeast();
}
if (!this.supportsBinary && !query.sid) {
query.b64 = 1;
}
return this.createUri(schema, query);
}
/**
* Creates a request.
*
* @param {String} method
* @private
*/
}, {
key: "request",
value: function request() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_extends(opts, {
xd: this.xd,
cookieJar: this.cookieJar
}, this.opts);
return new Request(this.uri(), opts);
}
/**
* Sends data.
*
* @param {String} data to send.
* @param {Function} called upon flush.
* @private
*/
}, {
key: "doWrite",
value: function doWrite(data, fn) {
var _this6 = this;
var req = this.request({
method: "POST",
data: data
});
req.on("success", fn);
req.on("error", function (xhrStatus, context) {
_this6.onError("xhr post error", xhrStatus, context);
});
}
/**
* Starts a poll cycle.
*
* @private
*/
}, {
key: "doPoll",
value: function doPoll() {
var _this7 = this;
var req = this.request();
req.on("data", this.onData.bind(this));
req.on("error", function (xhrStatus, context) {
_this7.onError("xhr poll error", xhrStatus, context);
});
this.pollXhr = req;
}
}, {
key: "name",
get: function get() {
return "polling";
}
}]);
return Polling;
}(Transport);
var Request = /*#__PURE__*/function (_Emitter) {
_inherits(Request, _Emitter);
var _super2 = _createSuper(Request);
/**
* Request constructor
*
* @param {Object} options
* @package
*/
function Request(uri, opts) {
var _this8;
_classCallCheck(this, Request);
_this8 = _super2.call(this);
installTimerFunctions(_assertThisInitialized(_this8), opts);
_this8.opts = opts;
_this8.method = opts.method || "GET";
_this8.uri = uri;
_this8.data = undefined !== opts.data ? opts.data : null;
_this8.create();
return _this8;
}
/**
* Creates the XHR object and sends the request.
*
* @private
*/
_createClass(Request, [{
key: "create",
value: function create() {
var _this9 = this;
var _a;
var opts = pick(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
opts.xdomain = !!this.opts.xd;
var xhr = this.xhr = new XHR(opts);
try {
xhr.open(this.method, this.uri, true);
try {
if (this.opts.extraHeaders) {
xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
for (var i in this.opts.extraHeaders) {
if (this.opts.extraHeaders.hasOwnProperty(i)) {
xhr.setRequestHeader(i, this.opts.extraHeaders[i]);
}
}
}
} catch (e) {}
if ("POST" === this.method) {
try {
xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
} catch (e) {}
}
try {
xhr.setRequestHeader("Accept", "*/*");
} catch (e) {}
(_a = this.opts.cookieJar) === null || _a === void 0 ? void 0 : _a.addCookies(xhr);
// ie6 check
if ("withCredentials" in xhr) {
xhr.withCredentials = this.opts.withCredentials;
}
if (this.opts.requestTimeout) {
xhr.timeout = this.opts.requestTimeout;
}
xhr.onreadystatechange = function () {
var _a;
if (xhr.readyState === 3) {
(_a = _this9.opts.cookieJar) === null || _a === void 0 ? void 0 : _a.parseCookies(xhr);
}
if (4 !== xhr.readyState) return;
if (200 === xhr.status || 1223 === xhr.status) {
_this9.onLoad();
} else {
// make sure the `error` event handler that's user-set
// does not throw in the same tick and gets caught here
_this9.setTimeoutFn(function () {
_this9.onError(typeof xhr.status === "number" ? xhr.status : 0);
}, 0);
}
};
xhr.send(this.data);
} catch (e) {
// Need to defer since .create() is called directly from the constructor
// and thus the 'error' event can only be only bound *after* this exception
// occurs. Therefore, also, we cannot throw here at all.
this.setTimeoutFn(function () {
_this9.onError(e);
}, 0);
return;
}
if (typeof document !== "undefined") {
this.index = Request.requestsCount++;
Request.requests[this.index] = this;
}
}
/**
* Called upon error.
*
* @private
*/
}, {
key: "onError",
value: function onError(err) {
this.emitReserved("error", err, this.xhr);
this.cleanup(true);
}
/**
* Cleans up house.
*
* @private
*/
}, {
key: "cleanup",
value: function cleanup(fromError) {
if ("undefined" === typeof this.xhr || null === this.xhr) {
return;
}
this.xhr.onreadystatechange = empty;
if (fromError) {
try {
this.xhr.abort();
} catch (e) {}
}
if (typeof document !== "undefined") {
delete Request.requests[this.index];
}
this.xhr = null;
}
/**
* Called upon load.
*
* @private
*/
}, {
key: "onLoad",
value: function onLoad() {
var data = this.xhr.responseText;
if (data !== null) {
this.emitReserved("data", data);
this.emitReserved("success");
this.cleanup();
}
}
/**
* Aborts the request.
*
* @package
*/
}, {
key: "abort",
value: function abort() {
this.cleanup();
}
}]);
return Request;
}(Emitter);
Request.requestsCount = 0;
Request.requests = {};
/**
* Aborts pending requests when unloading the window. This is needed to prevent
* memory leaks (e.g. when using IE) and to ensure that no spurious error is
* emitted.
*/
if (typeof document !== "undefined") {
// @ts-ignore
if (typeof attachEvent === "function") {
// @ts-ignore
attachEvent("onunload", unloadHandler);
} else if (typeof addEventListener === "function") {
var terminationEvent = "onpagehide" in globalThisShim ? "pagehide" : "unload";
addEventListener(terminationEvent, unloadHandler, false);
}
}
function unloadHandler() {
for (var i in Request.requests) {
if (Request.requests.hasOwnProperty(i)) {
Request.requests[i].abort();
}
}
}
var nextTick = function () {
var isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
if (isPromiseAvailable) {
return function (cb) {
return Promise.resolve().then(cb);
};
} else {
return function (cb, setTimeoutFn) {
return setTimeoutFn(cb, 0);
};
}
}();
var WebSocket = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
var usingBrowserWebSocket = true;
var defaultBinaryType = "arraybuffer";
// detect ReactNative environment
var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
var WS = /*#__PURE__*/function (_Transport) {
_inherits(WS, _Transport);
var _super = _createSuper(WS);
/**
* WebSocket transport constructor.
*
* @param {Object} opts - connection options
* @protected
*/
function WS(opts) {
var _this;
_classCallCheck(this, WS);
_this = _super.call(this, opts);
_this.supportsBinary = !opts.forceBase64;
return _this;
}
_createClass(WS, [{
key: "doOpen",
value: function doOpen() {
if (!this.check()) {
// let probe timeout
return;
}
var uri = this.uri();
var protocols = this.opts.protocols;
// React Native only supports the 'headers' option, and will print a warning if anything else is passed
var opts = isReactNative ? {} : pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
if (this.opts.extraHeaders) {
opts.headers = this.opts.extraHeaders;
}
try {
this.ws = usingBrowserWebSocket && !isReactNative ? protocols ? new WebSocket(uri, protocols) : new WebSocket(uri) : new WebSocket(uri, protocols, opts);
} catch (err) {
return this.emitReserved("error", err);
}
this.ws.binaryType = this.socket.binaryType;
this.addEventListeners();
}
/**
* Adds event listeners to the socket
*
* @private
*/
}, {
key: "addEventListeners",
value: function addEventListeners() {
var _this2 = this;
this.ws.onopen = function () {
if (_this2.opts.autoUnref) {
_this2.ws._socket.unref();
}
_this2.onOpen();
};
this.ws.onclose = function (closeEvent) {
return _this2.onClose({
description: "websocket connection closed",
context: closeEvent
});
};
this.ws.onmessage = function (ev) {
return _this2.onData(ev.data);
};
this.ws.onerror = function (e) {
return _this2.onError("websocket error", e);
};
}
}, {
key: "write",
value: function write(packets) {
var _this3 = this;
this.writable = false;
// encodePacket efficient as it uses WS framing
// no need for encodePayload
var _loop = function _loop(i) {
var packet = packets[i];
var lastPacket = i === packets.length - 1;
encodePacket(packet, _this3.supportsBinary, function (data) {
// always create a new object (GH-437)
var opts = {};
// Sometimes the websocket has already been closed but the browser didn't
// have a chance of informing us about it yet, in that case send will
// throw an error
try {
if (usingBrowserWebSocket) {
// TypeError is thrown when passing the second argument on Safari
_this3.ws.send(data);
}
} catch (e) {}
if (lastPacket) {
// fake drain
// defer to next tick to allow Socket to clear writeBuffer
nextTick(function () {
_this3.writable = true;
_this3.emitReserved("drain");
}, _this3.setTimeoutFn);
}
});
};
for (var i = 0; i < packets.length; i++) {
_loop(i);
}
}
}, {
key: "doClose",
value: function doClose() {
if (typeof this.ws !== "undefined") {
this.ws.close();
this.ws = null;
}
}
/**
* Generates uri for connection.
*
* @private
*/
}, {
key: "uri",
value: function uri() {
var schema = this.opts.secure ? "wss" : "ws";
var query = this.query || {};
// append timestamp to URI
if (this.opts.timestampRequests) {
query[this.opts.timestampParam] = yeast();
}
// communicate binary support capabilities
if (!this.supportsBinary) {
query.b64 = 1;
}
return this.createUri(schema, query);
}
/**
* Feature detection for WebSocket.
*
* @return {Boolean} whether this transport is available.
* @private
*/
}, {
key: "check",
value: function check() {
return !!WebSocket;
}
}, {
key: "name",
get: function get() {
return "websocket";
}
}]);
return WS;
}(Transport);
var WT = /*#__PURE__*/function (_Transport) {
_inherits(WT, _Transport);
var _super = _createSuper(WT);
function WT() {
_classCallCheck(this, WT);
return _super.apply(this, arguments);
}
_createClass(WT, [{
key: "doOpen",
value: function doOpen() {
var _this = this;
// @ts-ignore
if (typeof WebTransport !== "function") {
return;
}
// @ts-ignore
this.transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
this.transport.closed.then(function () {
_this.onClose();
})["catch"](function (err) {
_this.onError("webtransport error", err);
});
// note: we could have used async/await, but that would require some additional polyfills
this.transport.ready.then(function () {
_this.transport.createBidirectionalStream().then(function (stream) {
var decoderStream = createPacketDecoderStream(Number.MAX_SAFE_INTEGER, _this.socket.binaryType);
var reader = stream.readable.pipeThrough(decoderStream).getReader();
var encoderStream = createPacketEncoderStream();
encoderStream.readable.pipeTo(stream.writable);
_this.writer = encoderStream.writable.getWriter();
var read = function read() {
reader.read().then(function (_ref) {
var done = _ref.done,
value = _ref.value;
if (done) {
return;
}
_this.onPacket(value);
read();
})["catch"](function (err) {});
};
read();
var packet = {
type: "open"
};
if (_this.query.sid) {
packet.data = "{\"sid\":\"".concat(_this.query.sid, "\"}");
}
_this.writer.write(packet).then(function () {
return _this.onOpen();
});
});
});
}
}, {
key: "write",
value: function write(packets) {
var _this2 = this;
this.writable = false;
var _loop = function _loop(i) {
var packet = packets[i];
var lastPacket = i === packets.length - 1;
_this2.writer.write(packet).then(function () {
if (lastPacket) {
nextTick(function () {
_this2.writable = true;
_this2.emitReserved("drain");
}, _this2.setTimeoutFn);
}
});
};
for (var i = 0; i < packets.length; i++) {
_loop(i);
}
}
}, {
key: "doClose",
value: function doClose() {
var _a;
(_a = this.transport) === null || _a === void 0 ? void 0 : _a.close();
}
}, {
key: "name",
get: function get() {
return "webtransport";
}
}]);
return WT;
}(Transport);
var transports = {
websocket: WS,
webtransport: WT,
polling: Polling
};
// imported from https://github.com/galkn/parseuri
/**
* Parses a URI
*
* Note: we could also have used the built-in URL object, but it isn't supported on all platforms.
*
* See:
* - https://developer.mozilla.org/en-US/docs/Web/API/URL
* - https://caniuse.com/url
* - https://www.rfc-editor.org/rfc/rfc3986#appendix-B
*
* History of the parse() method:
* - first commit: https://github.com/socketio/socket.io-client/commit/4ee1d5d94b3906a9c052b459f1a818b15f38f91c
* - export into its own module: https://github.com/socketio/engine.io-client/commit/de2c561e4564efeb78f1bdb1ba39ef81b2822cb3
* - reimport: https://github.com/socketio/engine.io-client/commit/df32277c3f6d622eec5ed09f493cae3f3391d242
*
* @author Steven Levithan <stevenlevithan.com> (MIT license)
* @api private
*/
var re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
var parts = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'];
function parse(str) {
if (str.length > 2000) {
throw "URI too long";
}
var src = str,
b = str.indexOf('['),
e = str.indexOf(']');
if (b != -1 && e != -1) {
str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
}
var m = re.exec(str || ''),
uri = {},
i = 14;
while (i--) {
uri[parts[i]] = m[i] || '';
}
if (b != -1 && e != -1) {
uri.source = src;
uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
uri.ipv6uri = true;
}
uri.pathNames = pathNames(uri, uri['path']);
uri.queryKey = queryKey(uri, uri['query']);
return uri;
}
function pathNames(obj, path) {
var regx = /\/{2,9}/g,
names = path.replace(regx, "/").split("/");
if (path.slice(0, 1) == '/' || path.length === 0) {
names.splice(0, 1);
}
if (path.slice(-1) == '/') {
names.splice(names.length - 1, 1);
}
return names;
}
function queryKey(uri, query) {
var data = {};
query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
if ($1) {
data[$1] = $2;
}
});
return data;
}
var Socket = /*#__PURE__*/function (_Emitter) {
_inherits(Socket, _Emitter);
var _super = _createSuper(Socket);
/**
* Socket constructor.
*
* @param {String|Object} uri - uri or options
* @param {Object} opts - options
*/
function Socket(uri) {
var _this;
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Socket);
_this = _super.call(this);
_this.binaryType = defaultBinaryType;
_this.writeBuffer = [];
if (uri && "object" === _typeof(uri)) {
opts = uri;
uri = null;
}
if (uri) {
uri = parse(uri);
opts.hostname = uri.host;
opts.secure = uri.protocol === "https" || uri.protocol === "wss";
opts.port = uri.port;
if (uri.query) opts.query = uri.query;
} else if (opts.host) {
opts.hostname = parse(opts.host).host;
}
installTimerFunctions(_assertThisInitialized(_this), opts);
_this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol;
if (opts.hostname && !opts.port) {
// if no port is specified manually, use the protocol default
opts.port = _this.secure ? "443" : "80";
}
_this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
_this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : _this.secure ? "443" : "80");
_this.transports = opts.transports || ["polling", "websocket", "webtransport"];
_this.writeBuffer = [];
_this.prevBufferLen = 0;
_this.opts = _extends({
path: "/engine.io",
agent: false,
withCredentials: false,
upgrade: true,
timestampParam: "t",
rememberUpgrade: false,
addTrailingSlash: true,
rejectUnauthorized: true,
perMessageDeflate: {
threshold: 1024
},
transportOptions: {},
closeOnBeforeunload: false
}, opts);
_this.opts.path = _this.opts.path.replace(/\/$/, "") + (_this.opts.addTrailingSlash ? "/" : "");
if (typeof _this.opts.query === "string") {
_this.opts.query = decode(_this.opts.query);
}
// set on handshake
_this.id = null;
_this.upgrades = null;
_this.pingInterval = null;
_this.pingTimeout = null;
// set on heartbeat
_this.pingTimeoutTimer = null;
if (typeof addEventListener === "function") {
if (_this.opts.closeOnBeforeunload) {
// Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
// ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
// closed/reloaded)
_this.beforeunloadEventListener = function () {
if (_this.transport) {
// silently close the transport
_this.transport.removeAllListeners();
_this.transport.close();
}
};
addEventListener("beforeunload", _this.beforeunloadEventListener, false);
}
if (_this.hostname !== "localhost") {
_this.offlineEventListener = function () {
_this.onClose("transport close", {
description: "network connection lost"
});
};
addEventListener("offline", _this.offlineEventListener, false);
}
}
_this.open();
return _this;
}
/**
* Creates transport of the given type.
*
* @param {String} name - transport name
* @return {Transport}
* @private
*/
_createClass(Socket, [{
key: "createTransport",
value: function createTransport(name) {
var query = _extends({}, this.opts.query);
// append engine.io protocol identifier
query.EIO = protocol;
// transport name
query.transport = name;
// session id if we already have one
if (this.id) query.sid = this.id;
var opts = _extends({}, this.opts, {
query: query,
socket: this,
hostname: this.hostname,
secure: this.secure,
port: this.port
}, this.opts.transportOptions[name]);
return new transports[name](opts);
}
/**
* Initializes transport to use and starts probe.
*
* @private
*/
}, {
key: "open",
value: function open() {
var _this2 = this;
var transport;
if (this.opts.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1) {
transport = "websocket";
} else if (0 === this.transports.length) {
// Emit error on next tick so it can be listened to
this.setTimeoutFn(function () {
_this2.emitReserved("error", "No transports available");
}, 0);
return;
} else {
transport = this.transports[0];
}
this.readyState = "opening";
// Retry with the next transport if the transport is disabled (jsonp: false)
try {
transport = this.createTransport(transport);
} catch (e) {
this.transports.shift();
this.open();
return;
}
transport.open();
this.setTransport(transport);
}
/**
* Sets the current transport. Disables the existing one (if any).
*
* @private
*/
}, {
key: "setTransport",
value: function setTransport(transport) {
var _this3 = this;
if (this.transport) {
this.transport.removeAllListeners();
}
// set up transport
this.transport = transport;
// set up transport listeners
transport.on("drain", this.onDrain.bind(this)).on("packet", this.onPacket.bind(this)).on("error", this.onError.bind(this)).on("close", function (reason) {
return _this3.onClose("transport close", reason);
});
}
/**
* Probes a transport.
*
* @param {String} name - transport name
* @private
*/
}, {
key: "probe",
value: function probe(name) {
var _this4 = this;
var transport = this.createTransport(name);
var failed = false;
Socket.priorWebsocketSuccess = false;
var onTransportOpen = function onTransportOpen() {
if (failed) return;
transport.send([{
type: "ping",
data: "probe"
}]);
transport.once("packet", function (msg) {
if (failed) return;
if ("pong" === msg.type && "probe" === msg.data) {
_this4.upgrading = true;
_this4.emitReserved("upgrading", transport);
if (!transport) return;
Socket.priorWebsocketSuccess = "websocket" === transport.name;
_this4.transport.pause(function () {
if (failed) return;
if ("closed" === _this4.readyState) return;
cleanup();
_this4.setTransport(transport);
transport.send([{
type: "upgrade"
}]);
_this4.emitReserved("upgrade", transport);
transport = null;
_this4.upgrading = false;
_this4.flush();
});
} else {
var err = new Error("probe error");
// @ts-ignore
err.transport = transport.name;
_this4.emitReserved("upgradeError", err);
}
});
};
function freezeTransport() {
if (failed) return;
// Any callback called by transport should be ignored since now
failed = true;
cleanup();
transport.close();
transport = null;
}
// Handle any error that happens while probing
var onerror = function onerror(err) {
var error = new Error("probe error: " + err);
// @ts-ignore
error.transport = transport.name;
freezeTransport();
_this4.emitReserved("upgradeError", error);
};
function onTransportClose() {
onerror("transport closed");
}
// When the socket is closed while we're probing
function onclose() {
onerror("socket closed");
}
// When the socket is upgraded while we're probing
function onupgrade(to) {
if (transport && to.name !== transport.name) {
freezeTransport();
}
}
// Remove all listeners on the transport and on self
var cleanup = function cleanup() {
transport.removeListener("open", onTransportOpen);
transport.removeListener("error", onerror);
transport.removeListener("close", onTransportClose);
_this4.off("close", onclose);
_this4.off("upgrading", onupgrade);
};
transport.once("open", onTransportOpen);
transport.once("error", onerror);
transport.once("close", onTransportClose);
this.once("close", onclose);
this.once("upgrading", onupgrade);
if (this.upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") {
// favor WebTransport
this.setTimeoutFn(function () {
if (!failed) {
transport.open();
}
}, 200);
} else {
transport.open();
}
}
/**
* Called when connection is deemed open.
*
* @private
*/
}, {
key: "onOpen",
value: function onOpen() {
this.readyState = "open";
Socket.priorWebsocketSuccess = "websocket" === this.transport.name;
this.emitReserved("open");
this.flush();
// we check for `readyState` in case an `open`
// listener already closed the socket
if ("open" === this.readyState && this.opts.upgrade) {
var i = 0;
var l = this.upgrades.length;
for (; i < l; i++) {
this.probe(this.upgrades[i]);
}
}
}
/**
* Handles a packet.
*
* @private
*/
}, {
key: "onPacket",
value: function onPacket(packet) {
if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
this.emitReserved("packet", packet);
// Socket is live - any packet counts
this.emitReserved("heartbeat");
this.resetPingTimeout();
switch (packet.type) {
case "open":
this.onHandshake(JSON.parse(packet.data));
break;
case "ping":
this.sendPacket("pong");
this.emitReserved("ping");
this.emitReserved("pong");
break;
case "error":
var err = new Error("server error");
// @ts-ignore
err.code = packet.data;
this.onError(err);
break;
case "message":
this.emitReserved("data", packet.data);
this.emitReserved("message", packet.data);
break;
}
}
}
/**
* Called upon handshake completion.
*
* @param {Object} data - handshake obj
* @private
*/
}, {
key: "onHandshake",
value: function onHandshake(data) {
this.emitReserved("handshake", data);
this.id = data.sid;
this.transport.query.sid = data.sid;
this.upgrades = this.filterUpgrades(data.upgrades);
this.pingInterval = data.pingInterval;
this.pingTimeout = data.pingTimeout;
this.maxPayload = data.maxPayload;
this.onOpen();
// In case open handler closes socket
if ("closed" === this.readyState) return;
this.resetPingTimeout();
}
/**
* Sets and resets ping timeout timer based on server pings.
*
* @private
*/
}, {
key: "resetPingTimeout",
value: function resetPingTimeout() {
var _this5 = this;
this.clearTimeoutFn(this.pingTimeoutTimer);
this.pingTimeoutTimer = this.setTimeoutFn(function () {
_this5.onClose("ping timeout");
}, this.pingInterval + this.pingTimeout);
if (this.opts.autoUnref) {
this.pingTimeoutTimer.unref();
}
}
/**
* Called on `drain` event
*
* @private
*/
}, {
key: "onDrain",
value: function onDrain() {
this.writeBuffer.splice(0, this.prevBufferLen);
// setting prevBufferLen = 0 is very important
// for example, when upgrading, upgrade packet is sent over,
// and a nonzero prevBufferLen could cause problems on `drain`
this.prevBufferLen = 0;
if (0 === this.writeBuffer.length) {
this.emitReserved("drain");
} else {
this.flush();
}
}
/**
* Flush write buffers.
*
* @private
*/
}, {
key: "flush",
value: function flush() {
if ("closed" !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
var packets = this.getWritablePackets();
this.transport.send(packets);
// keep track of current length of writeBuffer
// splice writeBuffer and callbackBuffer on `drain`
this.prevBufferLen = packets.length;
this.emitReserved("flush");
}
}
/**
* Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
* long-polling)
*
* @private
*/
}, {
key: "getWritablePackets",
value: function getWritablePackets() {
var shouldCheckPayloadSize = this.maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1;
if (!shouldCheckPayloadSize) {
return this.writeBuffer;
}
var payloadSize = 1; // first packet type
for (var i = 0; i < this.writeBuffer.length; i++) {
var data = this.writeBuffer[i].data;
if (data) {
payloadSize += byteLength(data);
}
if (i > 0 && payloadSize > this.maxPayload) {
return this.writeBuffer.slice(0, i);
}
payloadSize += 2; // separator + packet type
}
return this.writeBuffer;
}
/**
* Sends a message.
*
* @param {String} msg - message.
* @param {Object} options.
* @param {Function} callback function.
* @return {Socket} for chaining.
*/
}, {
key: "write",
value: function write(msg, options, fn) {
this.sendPacket("message", msg, options, fn);
return this;
}
}, {
key: "send",
value: function send(msg, options, fn) {
this.sendPacket("message", msg, options, fn);
return this;
}
/**
* Sends a packet.
*
* @param {String} type: packet type.
* @param {String} data.
* @param {Object} options.
* @param {Function} fn - callback function.
* @private
*/
}, {
key: "sendPacket",
value: function sendPacket(type, data, options, fn) {
if ("function" === typeof data) {
fn = data;
data = undefined;
}
if ("function" === typeof options) {
fn = options;
options = null;
}
if ("closing" === this.readyState || "closed" === this.readyState) {
return;
}
options = options || {};
options.compress = false !== options.compress;
var packet = {
type: type,
data: data,
options: options
};
this.emitReserved("packetCreate", packet);
this.writeBuffer.push(packet);
if (fn) this.once("flush", fn);
this.flush();
}
/**
* Closes the connection.
*/
}, {
key: "close",
value: function close() {
var _this6 = this;
var close = function close() {
_this6.onClose("forced close");
_this6.transport.close();
};
var cleanupAndClose = function cleanupAndClose() {
_this6.off("upgrade", cleanupAndClose);
_this6.off("upgradeError", cleanupAndClose);
close();
};
var waitForUpgrade = function waitForUpgrade() {
// wait for upgrade to finish since we can't send packets while pausing a transport
_this6.once("upgrade", cleanupAndClose);
_this6.once("upgradeError", cleanupAndClose);
};
if ("opening" === this.readyState || "open" === this.readyState) {
this.readyState = "closing";
if (this.writeBuffer.length) {
this.once("drain", function () {
if (_this6.upgrading) {
waitForUpgrade();
} else {
close();
}
});
} else if (this.upgrading) {
waitForUpgrade();
} else {
close();
}
}
return this;
}
/**
* Called upon transport error
*
* @private
*/
}, {
key: "onError",
value: function onError(err) {
Socket.priorWebsocketSuccess = false;
this.emitReserved("error", err);
this.onClose("transport error", err);
}
/**
* Called upon transport close.
*
* @private
*/
}, {
key: "onClose",
value: function onClose(reason, description) {
if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
// clear timers
this.clearTimeoutFn(this.pingTimeoutTimer);
// stop event from firing again for transport
this.transport.removeAllListeners("close");
// ensure transport won't stay open
this.transport.close();
// ignore further transport communication
this.transport.removeAllListeners();
if (typeof removeEventListener === "function") {
removeEventListener("beforeunload", this.beforeunloadEventListener, false);
removeEventListener("offline", this.offlineEventListener, false);
}
// set ready state
this.readyState = "closed";
// clear session id
this.id = null;
// emit close event
this.emitReserved("close", reason, description);
// clean buffers after, so users can still
// grab the buffers on `close` event
this.writeBuffer = [];
this.prevBufferLen = 0;
}
}
/**
* Filters upgrades, returning only those matching client transports.
*
* @param {Array} upgrades - server upgrades
* @private
*/
}, {
key: "filterUpgrades",
value: function filterUpgrades(upgrades) {
var filteredUpgrades = [];
var i = 0;
var j = upgrades.length;
for (; i < j; i++) {
if (~this.transports.indexOf(upgrades[i])) filteredUpgrades.push(upgrades[i]);
}
return filteredUpgrades;
}
}]);
return Socket;
}(Emitter);
Socket.protocol = protocol;
var browserEntrypoint = (function (uri, opts) {
return new Socket(uri, opts);
});
return browserEntrypoint;
}));
//# sourceMappingURL=engine.io.js.map
|