@depup/socket.io 4.8.3-depup.81 → 4.8.4-depup.0
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 +3 -3
- package/changes.json +2 -2
- package/client-dist/socket.io.esm.min.js +3 -3
- package/client-dist/socket.io.esm.min.js.map +1 -1
- package/client-dist/socket.io.js +174 -242
- package/client-dist/socket.io.js.map +1 -1
- package/client-dist/socket.io.min.js +3 -3
- package/client-dist/socket.io.min.js.map +1 -1
- package/client-dist/socket.io.msgpack.min.js +3 -3
- package/client-dist/socket.io.msgpack.min.js.map +1 -1
- package/dist/broadcast-operator.js +14 -0
- package/dist/client.js +8 -1
- package/dist/contrib/base64id.d.ts +7 -0
- package/dist/contrib/base64id.js +89 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +57 -36
- package/dist/socket.js +3 -7
- package/dist/typed-events.d.ts +1 -3
- package/dist/uws.js +1 -0
- package/package.json +6 -7
package/client-dist/socket.io.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Socket.IO v4.8.
|
|
3
|
-
* (c) 2014-
|
|
2
|
+
* Socket.IO v4.8.4
|
|
3
|
+
* (c) 2014-2026 Guillermo Rauch
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
(function (global, factory) {
|
|
@@ -1101,8 +1101,8 @@
|
|
|
1101
1101
|
/**
|
|
1102
1102
|
* Sends data.
|
|
1103
1103
|
*
|
|
1104
|
-
* @param {String} data to send.
|
|
1105
|
-
* @param {Function} called upon flush.
|
|
1104
|
+
* @param {String} data - data to send.
|
|
1105
|
+
* @param {Function} fn - called upon flush.
|
|
1106
1106
|
* @private
|
|
1107
1107
|
*/
|
|
1108
1108
|
_inheritsLoose(BaseXHR, _Polling);
|
|
@@ -1664,40 +1664,31 @@
|
|
|
1664
1664
|
}
|
|
1665
1665
|
/**
|
|
1666
1666
|
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
1667
|
-
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
1667
|
+
* with one of the available low-level transports, like HTTP long-polling, WebSocket, or WebTransport.
|
|
1668
1668
|
*
|
|
1669
|
-
* This class comes
|
|
1670
|
-
*
|
|
1671
|
-
*
|
|
1672
|
-
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
1669
|
+
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
1670
|
+
* low-level transport, it will try to upgrade to a better transport.
|
|
1673
1671
|
*
|
|
1674
1672
|
* @example
|
|
1675
|
-
* import {
|
|
1673
|
+
* import { Socket } from "engine.io-client";
|
|
1676
1674
|
*
|
|
1677
|
-
* const socket = new
|
|
1678
|
-
* transports: [WebSocket]
|
|
1679
|
-
* });
|
|
1675
|
+
* const socket = new Socket();
|
|
1680
1676
|
*
|
|
1681
1677
|
* socket.on("open", () => {
|
|
1682
1678
|
* socket.send("hello");
|
|
1683
1679
|
* });
|
|
1684
1680
|
*
|
|
1685
|
-
* @see SocketWithUpgrade
|
|
1686
|
-
* @see Socket
|
|
1687
1681
|
*/
|
|
1688
|
-
var
|
|
1689
|
-
|
|
1690
|
-
* Socket constructor.
|
|
1691
|
-
*
|
|
1692
|
-
* @param {String|Object} uri - uri or options
|
|
1693
|
-
* @param {Object} opts - options
|
|
1694
|
-
*/
|
|
1695
|
-
function SocketWithoutUpgrade(uri, opts) {
|
|
1682
|
+
var Socket$1 = /*#__PURE__*/function (_Emitter) {
|
|
1683
|
+
function Socket(uri) {
|
|
1696
1684
|
var _this;
|
|
1685
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1686
|
+
var _a, _b;
|
|
1697
1687
|
_this = _Emitter.call(this) || this;
|
|
1698
1688
|
_this.binaryType = defaultBinaryType;
|
|
1699
1689
|
_this.writeBuffer = [];
|
|
1700
1690
|
_this._prevBufferLen = 0;
|
|
1691
|
+
_this._upgrades = [];
|
|
1701
1692
|
_this._pingInterval = -1;
|
|
1702
1693
|
_this._pingTimeout = -1;
|
|
1703
1694
|
_this._maxPayload = -1;
|
|
@@ -1727,13 +1718,22 @@
|
|
|
1727
1718
|
}
|
|
1728
1719
|
_this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
|
|
1729
1720
|
_this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : _this.secure ? "443" : "80");
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
_this.
|
|
1736
|
-
|
|
1721
|
+
if (opts.transportImplementations && opts.transports) {
|
|
1722
|
+
throw new Error("specifying both 'transportImplementations' and 'transports' options is not supported");
|
|
1723
|
+
}
|
|
1724
|
+
if (opts.transportImplementations || ((_a = opts.transports) === null || _a === void 0 ? void 0 : _a.length) && typeof opts.transports[0] === "function") {
|
|
1725
|
+
// 'transports' option as an array of transport implementations is kept for backward compatibility
|
|
1726
|
+
_this.transports = [];
|
|
1727
|
+
_this._transportsByName = Object.create(null);
|
|
1728
|
+
((_b = opts.transportImplementations) !== null && _b !== void 0 ? _b : opts.transports).forEach(function (t) {
|
|
1729
|
+
var transportName = t.prototype.name;
|
|
1730
|
+
_this.transports.push(transportName);
|
|
1731
|
+
_this._transportsByName[transportName] = t;
|
|
1732
|
+
});
|
|
1733
|
+
} else {
|
|
1734
|
+
_this.transports = opts.transports ? _toConsumableArray(opts.transports) : ["polling", "websocket", "webtransport"];
|
|
1735
|
+
_this._transportsByName = transports;
|
|
1736
|
+
}
|
|
1737
1737
|
_this.opts = _extends({
|
|
1738
1738
|
path: "/engine.io",
|
|
1739
1739
|
agent: false,
|
|
@@ -1789,8 +1789,8 @@
|
|
|
1789
1789
|
* @return {Transport}
|
|
1790
1790
|
* @private
|
|
1791
1791
|
*/
|
|
1792
|
-
_inheritsLoose(
|
|
1793
|
-
var _proto =
|
|
1792
|
+
_inheritsLoose(Socket, _Emitter);
|
|
1793
|
+
var _proto = Socket.prototype;
|
|
1794
1794
|
_proto.createTransport = function createTransport(name) {
|
|
1795
1795
|
var query = _extends({}, this.opts.query);
|
|
1796
1796
|
// append engine.io protocol identifier
|
|
@@ -1822,7 +1822,7 @@
|
|
|
1822
1822
|
}, 0);
|
|
1823
1823
|
return;
|
|
1824
1824
|
}
|
|
1825
|
-
var transportName = this.opts.rememberUpgrade &&
|
|
1825
|
+
var transportName = this.opts.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
|
|
1826
1826
|
this.readyState = "opening";
|
|
1827
1827
|
var transport = this.createTransport(transportName);
|
|
1828
1828
|
transport.open();
|
|
@@ -1845,6 +1845,104 @@
|
|
|
1845
1845
|
return _this3._onClose("transport close", reason);
|
|
1846
1846
|
});
|
|
1847
1847
|
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Probes a transport.
|
|
1850
|
+
*
|
|
1851
|
+
* @param {String} name - transport name
|
|
1852
|
+
* @private
|
|
1853
|
+
*/;
|
|
1854
|
+
_proto._probe = function _probe(name) {
|
|
1855
|
+
var _this4 = this;
|
|
1856
|
+
var transport = this.createTransport(name);
|
|
1857
|
+
var failed = false;
|
|
1858
|
+
Socket.priorWebsocketSuccess = false;
|
|
1859
|
+
var onTransportOpen = function onTransportOpen() {
|
|
1860
|
+
if (failed) return;
|
|
1861
|
+
transport.send([{
|
|
1862
|
+
type: "ping",
|
|
1863
|
+
data: "probe"
|
|
1864
|
+
}]);
|
|
1865
|
+
transport.once("packet", function (msg) {
|
|
1866
|
+
if (failed) return;
|
|
1867
|
+
if ("pong" === msg.type && "probe" === msg.data) {
|
|
1868
|
+
_this4.upgrading = true;
|
|
1869
|
+
_this4.emitReserved("upgrading", transport);
|
|
1870
|
+
if (!transport) return;
|
|
1871
|
+
Socket.priorWebsocketSuccess = "websocket" === transport.name;
|
|
1872
|
+
_this4.transport.pause(function () {
|
|
1873
|
+
if (failed) return;
|
|
1874
|
+
if ("closed" === _this4.readyState) return;
|
|
1875
|
+
cleanup();
|
|
1876
|
+
_this4.setTransport(transport);
|
|
1877
|
+
transport.send([{
|
|
1878
|
+
type: "upgrade"
|
|
1879
|
+
}]);
|
|
1880
|
+
_this4.emitReserved("upgrade", transport);
|
|
1881
|
+
transport = null;
|
|
1882
|
+
_this4.upgrading = false;
|
|
1883
|
+
_this4.flush();
|
|
1884
|
+
});
|
|
1885
|
+
} else {
|
|
1886
|
+
var err = new Error("probe error");
|
|
1887
|
+
// @ts-ignore
|
|
1888
|
+
err.transport = transport.name;
|
|
1889
|
+
_this4.emitReserved("upgradeError", err);
|
|
1890
|
+
}
|
|
1891
|
+
});
|
|
1892
|
+
};
|
|
1893
|
+
function freezeTransport() {
|
|
1894
|
+
if (failed) return;
|
|
1895
|
+
// Any callback called by transport should be ignored since now
|
|
1896
|
+
failed = true;
|
|
1897
|
+
cleanup();
|
|
1898
|
+
transport.close();
|
|
1899
|
+
transport = null;
|
|
1900
|
+
}
|
|
1901
|
+
// Handle any error that happens while probing
|
|
1902
|
+
var onerror = function onerror(err) {
|
|
1903
|
+
var error = new Error("probe error: " + err);
|
|
1904
|
+
// @ts-ignore
|
|
1905
|
+
error.transport = transport.name;
|
|
1906
|
+
freezeTransport();
|
|
1907
|
+
_this4.emitReserved("upgradeError", error);
|
|
1908
|
+
};
|
|
1909
|
+
function onTransportClose() {
|
|
1910
|
+
onerror("transport closed");
|
|
1911
|
+
}
|
|
1912
|
+
// When the socket is closed while we're probing
|
|
1913
|
+
function onclose() {
|
|
1914
|
+
onerror("socket closed");
|
|
1915
|
+
}
|
|
1916
|
+
// When the socket is upgraded while we're probing
|
|
1917
|
+
function onupgrade(to) {
|
|
1918
|
+
if (transport && to.name !== transport.name) {
|
|
1919
|
+
freezeTransport();
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
// Remove all listeners on the transport and on self
|
|
1923
|
+
var cleanup = function cleanup() {
|
|
1924
|
+
transport.removeListener("open", onTransportOpen);
|
|
1925
|
+
transport.removeListener("error", onerror);
|
|
1926
|
+
transport.removeListener("close", onTransportClose);
|
|
1927
|
+
_this4.off("close", onclose);
|
|
1928
|
+
_this4.off("upgrading", onupgrade);
|
|
1929
|
+
};
|
|
1930
|
+
transport.once("open", onTransportOpen);
|
|
1931
|
+
transport.once("error", onerror);
|
|
1932
|
+
transport.once("close", onTransportClose);
|
|
1933
|
+
this.once("close", onclose);
|
|
1934
|
+
this.once("upgrading", onupgrade);
|
|
1935
|
+
if (this._upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") {
|
|
1936
|
+
// favor WebTransport
|
|
1937
|
+
this.setTimeoutFn(function () {
|
|
1938
|
+
if (!failed) {
|
|
1939
|
+
transport.open();
|
|
1940
|
+
}
|
|
1941
|
+
}, 200);
|
|
1942
|
+
} else {
|
|
1943
|
+
transport.open();
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1848
1946
|
/**
|
|
1849
1947
|
* Called when connection is deemed open.
|
|
1850
1948
|
*
|
|
@@ -1852,9 +1950,14 @@
|
|
|
1852
1950
|
*/;
|
|
1853
1951
|
_proto.onOpen = function onOpen() {
|
|
1854
1952
|
this.readyState = "open";
|
|
1855
|
-
|
|
1953
|
+
Socket.priorWebsocketSuccess = "websocket" === this.transport.name;
|
|
1856
1954
|
this.emitReserved("open");
|
|
1857
1955
|
this.flush();
|
|
1956
|
+
if ("open" === this.readyState && this.opts.upgrade) {
|
|
1957
|
+
for (var i = 0; i < this._upgrades.length; i++) {
|
|
1958
|
+
this._probe(this._upgrades[i]);
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1858
1961
|
}
|
|
1859
1962
|
/**
|
|
1860
1963
|
* Handles a packet.
|
|
@@ -1899,6 +2002,7 @@
|
|
|
1899
2002
|
this.emitReserved("handshake", data);
|
|
1900
2003
|
this.id = data.sid;
|
|
1901
2004
|
this.transport.query.sid = data.sid;
|
|
2005
|
+
this._upgrades = this._filterUpgrades(data.upgrades);
|
|
1902
2006
|
this._pingInterval = data.pingInterval;
|
|
1903
2007
|
this._pingTimeout = data.pingTimeout;
|
|
1904
2008
|
this._maxPayload = data.maxPayload;
|
|
@@ -1913,12 +2017,12 @@
|
|
|
1913
2017
|
* @private
|
|
1914
2018
|
*/;
|
|
1915
2019
|
_proto._resetPingTimeout = function _resetPingTimeout() {
|
|
1916
|
-
var
|
|
2020
|
+
var _this5 = this;
|
|
1917
2021
|
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
1918
2022
|
var delay = this._pingInterval + this._pingTimeout;
|
|
1919
2023
|
this._pingTimeoutTime = Date.now() + delay;
|
|
1920
2024
|
this._pingTimeoutTimer = this.setTimeoutFn(function () {
|
|
1921
|
-
|
|
2025
|
+
_this5._onClose("ping timeout");
|
|
1922
2026
|
}, delay);
|
|
1923
2027
|
if (this.opts.autoUnref) {
|
|
1924
2028
|
this._pingTimeoutTimer.unref();
|
|
@@ -1991,13 +2095,13 @@
|
|
|
1991
2095
|
*/
|
|
1992
2096
|
/* private */;
|
|
1993
2097
|
_proto._hasPingExpired = function _hasPingExpired() {
|
|
1994
|
-
var
|
|
2098
|
+
var _this6 = this;
|
|
1995
2099
|
if (!this._pingTimeoutTime) return true;
|
|
1996
2100
|
var hasExpired = Date.now() > this._pingTimeoutTime;
|
|
1997
2101
|
if (hasExpired) {
|
|
1998
2102
|
this._pingTimeoutTime = 0;
|
|
1999
2103
|
nextTick(function () {
|
|
2000
|
-
|
|
2104
|
+
_this6._onClose("ping timeout");
|
|
2001
2105
|
}, this.setTimeoutFn);
|
|
2002
2106
|
}
|
|
2003
2107
|
return hasExpired;
|
|
@@ -2029,7 +2133,7 @@
|
|
|
2029
2133
|
/**
|
|
2030
2134
|
* Sends a packet.
|
|
2031
2135
|
*
|
|
2032
|
-
* @param {String} type
|
|
2136
|
+
* @param {String} type - packet type.
|
|
2033
2137
|
* @param {String} data.
|
|
2034
2138
|
* @param {Object} options.
|
|
2035
2139
|
* @param {Function} fn - callback function.
|
|
@@ -2063,26 +2167,26 @@
|
|
|
2063
2167
|
* Closes the connection.
|
|
2064
2168
|
*/;
|
|
2065
2169
|
_proto.close = function close() {
|
|
2066
|
-
var
|
|
2170
|
+
var _this7 = this;
|
|
2067
2171
|
var close = function close() {
|
|
2068
|
-
|
|
2069
|
-
|
|
2172
|
+
_this7._onClose("forced close");
|
|
2173
|
+
_this7.transport.close();
|
|
2070
2174
|
};
|
|
2071
2175
|
var cleanupAndClose = function cleanupAndClose() {
|
|
2072
|
-
|
|
2073
|
-
|
|
2176
|
+
_this7.off("upgrade", cleanupAndClose);
|
|
2177
|
+
_this7.off("upgradeError", cleanupAndClose);
|
|
2074
2178
|
close();
|
|
2075
2179
|
};
|
|
2076
2180
|
var waitForUpgrade = function waitForUpgrade() {
|
|
2077
2181
|
// wait for upgrade to finish since we can't send packets while pausing a transport
|
|
2078
|
-
|
|
2079
|
-
|
|
2182
|
+
_this7.once("upgrade", cleanupAndClose);
|
|
2183
|
+
_this7.once("upgradeError", cleanupAndClose);
|
|
2080
2184
|
};
|
|
2081
2185
|
if ("opening" === this.readyState || "open" === this.readyState) {
|
|
2082
2186
|
this.readyState = "closing";
|
|
2083
2187
|
if (this.writeBuffer.length) {
|
|
2084
2188
|
this.once("drain", function () {
|
|
2085
|
-
if (
|
|
2189
|
+
if (_this7.upgrading) {
|
|
2086
2190
|
waitForUpgrade();
|
|
2087
2191
|
} else {
|
|
2088
2192
|
close();
|
|
@@ -2102,7 +2206,7 @@
|
|
|
2102
2206
|
* @private
|
|
2103
2207
|
*/;
|
|
2104
2208
|
_proto._onError = function _onError(err) {
|
|
2105
|
-
|
|
2209
|
+
Socket.priorWebsocketSuccess = false;
|
|
2106
2210
|
if (this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening") {
|
|
2107
2211
|
this.transports.shift();
|
|
2108
2212
|
return this._open();
|
|
@@ -2147,151 +2251,6 @@
|
|
|
2147
2251
|
this.writeBuffer = [];
|
|
2148
2252
|
this._prevBufferLen = 0;
|
|
2149
2253
|
}
|
|
2150
|
-
};
|
|
2151
|
-
return SocketWithoutUpgrade;
|
|
2152
|
-
}(Emitter);
|
|
2153
|
-
SocketWithoutUpgrade.protocol = protocol$1;
|
|
2154
|
-
/**
|
|
2155
|
-
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
2156
|
-
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
2157
|
-
*
|
|
2158
|
-
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
2159
|
-
* low-level transport, it will try to upgrade to a better transport.
|
|
2160
|
-
*
|
|
2161
|
-
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
2162
|
-
*
|
|
2163
|
-
* @example
|
|
2164
|
-
* import { SocketWithUpgrade, WebSocket } from "engine.io-client";
|
|
2165
|
-
*
|
|
2166
|
-
* const socket = new SocketWithUpgrade({
|
|
2167
|
-
* transports: [WebSocket]
|
|
2168
|
-
* });
|
|
2169
|
-
*
|
|
2170
|
-
* socket.on("open", () => {
|
|
2171
|
-
* socket.send("hello");
|
|
2172
|
-
* });
|
|
2173
|
-
*
|
|
2174
|
-
* @see SocketWithoutUpgrade
|
|
2175
|
-
* @see Socket
|
|
2176
|
-
*/
|
|
2177
|
-
var SocketWithUpgrade = /*#__PURE__*/function (_SocketWithoutUpgrade) {
|
|
2178
|
-
function SocketWithUpgrade() {
|
|
2179
|
-
var _this7;
|
|
2180
|
-
_this7 = _SocketWithoutUpgrade.apply(this, arguments) || this;
|
|
2181
|
-
_this7._upgrades = [];
|
|
2182
|
-
return _this7;
|
|
2183
|
-
}
|
|
2184
|
-
_inheritsLoose(SocketWithUpgrade, _SocketWithoutUpgrade);
|
|
2185
|
-
var _proto2 = SocketWithUpgrade.prototype;
|
|
2186
|
-
_proto2.onOpen = function onOpen() {
|
|
2187
|
-
_SocketWithoutUpgrade.prototype.onOpen.call(this);
|
|
2188
|
-
if ("open" === this.readyState && this.opts.upgrade) {
|
|
2189
|
-
for (var i = 0; i < this._upgrades.length; i++) {
|
|
2190
|
-
this._probe(this._upgrades[i]);
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2193
|
-
}
|
|
2194
|
-
/**
|
|
2195
|
-
* Probes a transport.
|
|
2196
|
-
*
|
|
2197
|
-
* @param {String} name - transport name
|
|
2198
|
-
* @private
|
|
2199
|
-
*/;
|
|
2200
|
-
_proto2._probe = function _probe(name) {
|
|
2201
|
-
var _this8 = this;
|
|
2202
|
-
var transport = this.createTransport(name);
|
|
2203
|
-
var failed = false;
|
|
2204
|
-
SocketWithoutUpgrade.priorWebsocketSuccess = false;
|
|
2205
|
-
var onTransportOpen = function onTransportOpen() {
|
|
2206
|
-
if (failed) return;
|
|
2207
|
-
transport.send([{
|
|
2208
|
-
type: "ping",
|
|
2209
|
-
data: "probe"
|
|
2210
|
-
}]);
|
|
2211
|
-
transport.once("packet", function (msg) {
|
|
2212
|
-
if (failed) return;
|
|
2213
|
-
if ("pong" === msg.type && "probe" === msg.data) {
|
|
2214
|
-
_this8.upgrading = true;
|
|
2215
|
-
_this8.emitReserved("upgrading", transport);
|
|
2216
|
-
if (!transport) return;
|
|
2217
|
-
SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === transport.name;
|
|
2218
|
-
_this8.transport.pause(function () {
|
|
2219
|
-
if (failed) return;
|
|
2220
|
-
if ("closed" === _this8.readyState) return;
|
|
2221
|
-
cleanup();
|
|
2222
|
-
_this8.setTransport(transport);
|
|
2223
|
-
transport.send([{
|
|
2224
|
-
type: "upgrade"
|
|
2225
|
-
}]);
|
|
2226
|
-
_this8.emitReserved("upgrade", transport);
|
|
2227
|
-
transport = null;
|
|
2228
|
-
_this8.upgrading = false;
|
|
2229
|
-
_this8.flush();
|
|
2230
|
-
});
|
|
2231
|
-
} else {
|
|
2232
|
-
var err = new Error("probe error");
|
|
2233
|
-
// @ts-ignore
|
|
2234
|
-
err.transport = transport.name;
|
|
2235
|
-
_this8.emitReserved("upgradeError", err);
|
|
2236
|
-
}
|
|
2237
|
-
});
|
|
2238
|
-
};
|
|
2239
|
-
function freezeTransport() {
|
|
2240
|
-
if (failed) return;
|
|
2241
|
-
// Any callback called by transport should be ignored since now
|
|
2242
|
-
failed = true;
|
|
2243
|
-
cleanup();
|
|
2244
|
-
transport.close();
|
|
2245
|
-
transport = null;
|
|
2246
|
-
}
|
|
2247
|
-
// Handle any error that happens while probing
|
|
2248
|
-
var onerror = function onerror(err) {
|
|
2249
|
-
var error = new Error("probe error: " + err);
|
|
2250
|
-
// @ts-ignore
|
|
2251
|
-
error.transport = transport.name;
|
|
2252
|
-
freezeTransport();
|
|
2253
|
-
_this8.emitReserved("upgradeError", error);
|
|
2254
|
-
};
|
|
2255
|
-
function onTransportClose() {
|
|
2256
|
-
onerror("transport closed");
|
|
2257
|
-
}
|
|
2258
|
-
// When the socket is closed while we're probing
|
|
2259
|
-
function onclose() {
|
|
2260
|
-
onerror("socket closed");
|
|
2261
|
-
}
|
|
2262
|
-
// When the socket is upgraded while we're probing
|
|
2263
|
-
function onupgrade(to) {
|
|
2264
|
-
if (transport && to.name !== transport.name) {
|
|
2265
|
-
freezeTransport();
|
|
2266
|
-
}
|
|
2267
|
-
}
|
|
2268
|
-
// Remove all listeners on the transport and on self
|
|
2269
|
-
var cleanup = function cleanup() {
|
|
2270
|
-
transport.removeListener("open", onTransportOpen);
|
|
2271
|
-
transport.removeListener("error", onerror);
|
|
2272
|
-
transport.removeListener("close", onTransportClose);
|
|
2273
|
-
_this8.off("close", onclose);
|
|
2274
|
-
_this8.off("upgrading", onupgrade);
|
|
2275
|
-
};
|
|
2276
|
-
transport.once("open", onTransportOpen);
|
|
2277
|
-
transport.once("error", onerror);
|
|
2278
|
-
transport.once("close", onTransportClose);
|
|
2279
|
-
this.once("close", onclose);
|
|
2280
|
-
this.once("upgrading", onupgrade);
|
|
2281
|
-
if (this._upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") {
|
|
2282
|
-
// favor WebTransport
|
|
2283
|
-
this.setTimeoutFn(function () {
|
|
2284
|
-
if (!failed) {
|
|
2285
|
-
transport.open();
|
|
2286
|
-
}
|
|
2287
|
-
}, 200);
|
|
2288
|
-
} else {
|
|
2289
|
-
transport.open();
|
|
2290
|
-
}
|
|
2291
|
-
};
|
|
2292
|
-
_proto2.onHandshake = function onHandshake(data) {
|
|
2293
|
-
this._upgrades = this._filterUpgrades(data.upgrades);
|
|
2294
|
-
_SocketWithoutUpgrade.prototype.onHandshake.call(this, data);
|
|
2295
2254
|
}
|
|
2296
2255
|
/**
|
|
2297
2256
|
* Filters upgrades, returning only those matching client transports.
|
|
@@ -2299,50 +2258,16 @@
|
|
|
2299
2258
|
* @param {Array} upgrades - server upgrades
|
|
2300
2259
|
* @private
|
|
2301
2260
|
*/;
|
|
2302
|
-
|
|
2261
|
+
_proto._filterUpgrades = function _filterUpgrades(upgrades) {
|
|
2303
2262
|
var filteredUpgrades = [];
|
|
2304
2263
|
for (var i = 0; i < upgrades.length; i++) {
|
|
2305
2264
|
if (~this.transports.indexOf(upgrades[i])) filteredUpgrades.push(upgrades[i]);
|
|
2306
2265
|
}
|
|
2307
2266
|
return filteredUpgrades;
|
|
2308
2267
|
};
|
|
2309
|
-
return SocketWithUpgrade;
|
|
2310
|
-
}(SocketWithoutUpgrade);
|
|
2311
|
-
/**
|
|
2312
|
-
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
2313
|
-
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
2314
|
-
*
|
|
2315
|
-
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
2316
|
-
* low-level transport, it will try to upgrade to a better transport.
|
|
2317
|
-
*
|
|
2318
|
-
* @example
|
|
2319
|
-
* import { Socket } from "engine.io-client";
|
|
2320
|
-
*
|
|
2321
|
-
* const socket = new Socket();
|
|
2322
|
-
*
|
|
2323
|
-
* socket.on("open", () => {
|
|
2324
|
-
* socket.send("hello");
|
|
2325
|
-
* });
|
|
2326
|
-
*
|
|
2327
|
-
* @see SocketWithoutUpgrade
|
|
2328
|
-
* @see SocketWithUpgrade
|
|
2329
|
-
*/
|
|
2330
|
-
var Socket$1 = /*#__PURE__*/function (_SocketWithUpgrade) {
|
|
2331
|
-
function Socket(uri) {
|
|
2332
|
-
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2333
|
-
var o = _typeof(uri) === "object" ? uri : opts;
|
|
2334
|
-
if (!o.transports || o.transports && typeof o.transports[0] === "string") {
|
|
2335
|
-
o.transports = (o.transports || ["polling", "websocket", "webtransport"]).map(function (transportName) {
|
|
2336
|
-
return transports[transportName];
|
|
2337
|
-
}).filter(function (t) {
|
|
2338
|
-
return !!t;
|
|
2339
|
-
});
|
|
2340
|
-
}
|
|
2341
|
-
return _SocketWithUpgrade.call(this, uri, o) || this;
|
|
2342
|
-
}
|
|
2343
|
-
_inheritsLoose(Socket, _SocketWithUpgrade);
|
|
2344
2268
|
return Socket;
|
|
2345
|
-
}(
|
|
2269
|
+
}(Emitter);
|
|
2270
|
+
Socket$1.protocol = protocol$1;
|
|
2346
2271
|
|
|
2347
2272
|
Socket$1.protocol;
|
|
2348
2273
|
|
|
@@ -3111,7 +3036,7 @@
|
|
|
3111
3036
|
buffers: buffers
|
|
3112
3037
|
};
|
|
3113
3038
|
}
|
|
3114
|
-
function _deconstructPacket(data, buffers) {
|
|
3039
|
+
function _deconstructPacket(data, buffers, toJSON) {
|
|
3115
3040
|
if (!data) return data;
|
|
3116
3041
|
if (isBinary(data)) {
|
|
3117
3042
|
var placeholder = {
|
|
@@ -3127,6 +3052,9 @@
|
|
|
3127
3052
|
}
|
|
3128
3053
|
return newData;
|
|
3129
3054
|
} else if (_typeof(data) === "object" && !(data instanceof Date)) {
|
|
3055
|
+
if (data.toJSON && typeof data.toJSON === "function" && !toJSON) {
|
|
3056
|
+
return _deconstructPacket(data.toJSON(), buffers, true);
|
|
3057
|
+
}
|
|
3130
3058
|
var _newData = {};
|
|
3131
3059
|
for (var key in data) {
|
|
3132
3060
|
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
@@ -3283,13 +3211,16 @@
|
|
|
3283
3211
|
var Decoder = /*#__PURE__*/function (_Emitter) {
|
|
3284
3212
|
/**
|
|
3285
3213
|
* Decoder constructor
|
|
3286
|
-
*
|
|
3287
|
-
* @param {function} reviver - custom reviver to pass down to JSON.stringify
|
|
3288
3214
|
*/
|
|
3289
|
-
function Decoder(
|
|
3215
|
+
function Decoder(opts) {
|
|
3290
3216
|
var _this;
|
|
3291
3217
|
_this = _Emitter.call(this) || this;
|
|
3292
|
-
_this.
|
|
3218
|
+
_this.opts = _extends({
|
|
3219
|
+
reviver: undefined,
|
|
3220
|
+
maxAttachments: 10
|
|
3221
|
+
}, typeof opts === "function" ? {
|
|
3222
|
+
reviver: opts
|
|
3223
|
+
} : opts);
|
|
3293
3224
|
return _this;
|
|
3294
3225
|
}
|
|
3295
3226
|
/**
|
|
@@ -3311,10 +3242,6 @@
|
|
|
3311
3242
|
packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK;
|
|
3312
3243
|
// binary packet's json
|
|
3313
3244
|
this.reconstructor = new BinaryReconstructor(packet);
|
|
3314
|
-
// no attachments, labeled binary but no binary data to follow
|
|
3315
|
-
if (packet.attachments === 0) {
|
|
3316
|
-
_Emitter.prototype.emitReserved.call(this, "decoded", packet);
|
|
3317
|
-
}
|
|
3318
3245
|
} else {
|
|
3319
3246
|
// non-binary full packet
|
|
3320
3247
|
_Emitter.prototype.emitReserved.call(this, "decoded", packet);
|
|
@@ -3358,7 +3285,13 @@
|
|
|
3358
3285
|
if (buf != Number(buf) || str.charAt(i) !== "-") {
|
|
3359
3286
|
throw new Error("Illegal attachments");
|
|
3360
3287
|
}
|
|
3361
|
-
|
|
3288
|
+
var n = Number(buf);
|
|
3289
|
+
if (!isInteger(n) || n < 1) {
|
|
3290
|
+
throw new Error("Illegal attachments");
|
|
3291
|
+
} else if (n > this.opts.maxAttachments) {
|
|
3292
|
+
throw new Error("too many attachments");
|
|
3293
|
+
}
|
|
3294
|
+
p.attachments = n;
|
|
3362
3295
|
}
|
|
3363
3296
|
// look up namespace (if any)
|
|
3364
3297
|
if ("/" === str.charAt(i + 1)) {
|
|
@@ -3399,7 +3332,7 @@
|
|
|
3399
3332
|
};
|
|
3400
3333
|
_proto2.tryParse = function tryParse(str) {
|
|
3401
3334
|
try {
|
|
3402
|
-
return JSON.parse(str, this.reviver);
|
|
3335
|
+
return JSON.parse(str, this.opts.reviver);
|
|
3403
3336
|
} catch (e) {
|
|
3404
3337
|
return false;
|
|
3405
3338
|
}
|
|
@@ -4045,7 +3978,6 @@
|
|
|
4045
3978
|
case PacketType.CONNECT_ERROR:
|
|
4046
3979
|
this.destroy();
|
|
4047
3980
|
var err = new Error(packet.data.message);
|
|
4048
|
-
// @ts-ignore
|
|
4049
3981
|
err.data = packet.data.data;
|
|
4050
3982
|
this.emitReserved("connect_error", err);
|
|
4051
3983
|
break;
|