mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-12 08:27:57 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81c1f4e819 | ||
|
|
1fba399b17 | ||
|
|
4e6d40493d | ||
|
|
28c7cc0856 |
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -7,10 +7,10 @@
|
||||
* [ ] a code change that improves performance
|
||||
* [ ] other
|
||||
|
||||
### Current behaviour
|
||||
### Current behavior
|
||||
|
||||
|
||||
### New behaviour
|
||||
### New behavior
|
||||
|
||||
|
||||
### Other information (e.g. related issues)
|
||||
|
||||
26
.github/workflows/ci.yml
vendored
Normal file
26
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 0 * * 0'
|
||||
|
||||
jobs:
|
||||
test-node:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [10.x, 12.x, 14.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm ci
|
||||
- run: npm test
|
||||
env:
|
||||
CI: true
|
||||
10
.travis.yml
10
.travis.yml
@@ -1,10 +0,0 @@
|
||||
language: node_js
|
||||
sudo: false
|
||||
node_js:
|
||||
- '10'
|
||||
- '12'
|
||||
- '14'
|
||||
notifications:
|
||||
irc: "irc.freenode.org#socket.io"
|
||||
git:
|
||||
depth: 1
|
||||
@@ -1,3 +1,6 @@
|
||||
## [3.0.4](https://github.com/socketio/socket.io/compare/3.0.3...3.0.4) (2020-12-07)
|
||||
|
||||
|
||||
## [3.0.3](https://github.com/socketio/socket.io/compare/3.0.2...3.0.3) (2020-11-19)
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# socket.io
|
||||
|
||||
[](#backers) [](#sponsors)
|
||||
[](https://travis-ci.org/socketio/socket.io)
|
||||
[](https://github.com/socketio/socket.io/actions)
|
||||
[](https://david-dm.org/socketio/socket.io)
|
||||
[](https://david-dm.org/socketio/socket.io#info=devDependencies)
|
||||
[](https://www.npmjs.com/package/socket.io)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* Socket.IO v3.0.3
|
||||
* Socket.IO v3.0.4
|
||||
* (c) 2014-2020 Guillermo Rauch
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
@@ -165,7 +165,7 @@ function lookup(uri, opts) {
|
||||
var source = parsed.source;
|
||||
var id = parsed.id;
|
||||
var path = parsed.path;
|
||||
var sameNamespace = cache[id] && path in cache[id].nsps;
|
||||
var sameNamespace = cache[id] && path in cache[id]["nsps"];
|
||||
var newConnection = opts.forceNew || opts["force new connection"] || false === opts.multiplex || sameNamespace;
|
||||
var io;
|
||||
|
||||
@@ -298,7 +298,6 @@ var Manager = /*#__PURE__*/function (_Emitter) {
|
||||
_this = _super.call(this);
|
||||
_this.nsps = {};
|
||||
_this.subs = [];
|
||||
_this.connecting = [];
|
||||
|
||||
if (uri && "object" === _typeof(uri)) {
|
||||
opts = uri;
|
||||
@@ -356,25 +355,31 @@ var Manager = /*#__PURE__*/function (_Emitter) {
|
||||
}, {
|
||||
key: "reconnectionDelay",
|
||||
value: function reconnectionDelay(v) {
|
||||
var _a;
|
||||
|
||||
if (v === undefined) return this._reconnectionDelay;
|
||||
this._reconnectionDelay = v;
|
||||
this.backoff && this.backoff.setMin(v);
|
||||
(_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMin(v);
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "randomizationFactor",
|
||||
value: function randomizationFactor(v) {
|
||||
var _a;
|
||||
|
||||
if (v === undefined) return this._randomizationFactor;
|
||||
this._randomizationFactor = v;
|
||||
this.backoff && this.backoff.setJitter(v);
|
||||
(_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setJitter(v);
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "reconnectionDelayMax",
|
||||
value: function reconnectionDelayMax(v) {
|
||||
var _a;
|
||||
|
||||
if (v === undefined) return this._reconnectionDelayMax;
|
||||
this._reconnectionDelayMax = v;
|
||||
this.backoff && this.backoff.setMax(v);
|
||||
(_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMax(v);
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
@@ -404,7 +409,7 @@ var Manager = /*#__PURE__*/function (_Emitter) {
|
||||
* Sets the current transport `socket`.
|
||||
*
|
||||
* @param {Function} fn - optional, callback
|
||||
* @return {Manager} self
|
||||
* @return self
|
||||
* @public
|
||||
*/
|
||||
|
||||
@@ -499,11 +504,7 @@ var Manager = /*#__PURE__*/function (_Emitter) {
|
||||
|
||||
|
||||
var socket = this.engine;
|
||||
this.subs.push(on_1.on(socket, "data", bind(this, "ondata")));
|
||||
this.subs.push(on_1.on(socket, "ping", bind(this, "onping")));
|
||||
this.subs.push(on_1.on(socket, "error", bind(this, "onerror")));
|
||||
this.subs.push(on_1.on(socket, "close", bind(this, "onclose")));
|
||||
this.subs.push(on_1.on(this.decoder, "decoded", bind(this, "ondecoded")));
|
||||
this.subs.push(on_1.on(socket, "data", bind(this, "ondata")), on_1.on(socket, "ping", bind(this, "onping")), on_1.on(socket, "error", bind(this, "onerror")), on_1.on(socket, "close", bind(this, "onclose")), on_1.on(this.decoder, "decoded", bind(this, "ondecoded")));
|
||||
}
|
||||
/**
|
||||
* Called upon a ping.
|
||||
@@ -566,19 +567,6 @@ var Manager = /*#__PURE__*/function (_Emitter) {
|
||||
if (!socket) {
|
||||
socket = new socket_1.Socket(this, nsp, opts);
|
||||
this.nsps[nsp] = socket;
|
||||
var self = this;
|
||||
socket.on("connecting", onConnecting);
|
||||
|
||||
if (this._autoConnect) {
|
||||
// manually call here since connecting event is fired before listening
|
||||
onConnecting();
|
||||
}
|
||||
}
|
||||
|
||||
function onConnecting() {
|
||||
if (!~self.connecting.indexOf(socket)) {
|
||||
self.connecting.push(socket);
|
||||
}
|
||||
}
|
||||
|
||||
return socket;
|
||||
@@ -586,23 +574,31 @@ var Manager = /*#__PURE__*/function (_Emitter) {
|
||||
/**
|
||||
* Called upon a socket close.
|
||||
*
|
||||
* @param {Socket} socket
|
||||
* @param socket
|
||||
* @private
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "_destroy",
|
||||
value: function _destroy(socket) {
|
||||
var index = this.connecting.indexOf(socket);
|
||||
if (~index) this.connecting.splice(index, 1);
|
||||
if (this.connecting.length) return;
|
||||
var nsps = Object.keys(this.nsps);
|
||||
|
||||
for (var _i = 0, _nsps = nsps; _i < _nsps.length; _i++) {
|
||||
var nsp = _nsps[_i];
|
||||
var _socket = this.nsps[nsp];
|
||||
|
||||
if (_socket.active) {
|
||||
debug("socket %s is still active, skipping close", nsp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this._close();
|
||||
}
|
||||
/**
|
||||
* Writes a packet.
|
||||
*
|
||||
* @param {Object} packet
|
||||
* @param packet
|
||||
* @private
|
||||
*/
|
||||
|
||||
@@ -786,7 +782,7 @@ function on(obj, ev, fn) {
|
||||
obj.on(ev, fn);
|
||||
return {
|
||||
destroy: function destroy() {
|
||||
obj.removeListener(ev, fn);
|
||||
obj.off(ev, fn);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -857,7 +853,7 @@ var debug = __webpack_require__(/*! debug */ "./node_modules/debug/src/browser.j
|
||||
*/
|
||||
|
||||
|
||||
var RESERVED_EVENTS = {
|
||||
var RESERVED_EVENTS = Object.freeze({
|
||||
connect: 1,
|
||||
connect_error: 1,
|
||||
disconnect: 1,
|
||||
@@ -865,7 +861,7 @@ var RESERVED_EVENTS = {
|
||||
// EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
|
||||
newListener: 1,
|
||||
removeListener: 1
|
||||
};
|
||||
});
|
||||
|
||||
var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
_inherits(Socket, _Emitter);
|
||||
@@ -920,17 +916,21 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
this.subs = [on_1.on(io, "open", bind(this, "onopen")), on_1.on(io, "packet", bind(this, "onpacket")), on_1.on(io, "close", bind(this, "onclose"))];
|
||||
}
|
||||
/**
|
||||
* "Opens" the socket.
|
||||
*
|
||||
* @public
|
||||
* Whether the Socket will try to reconnect when its Manager connects or reconnects
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "connect",
|
||||
|
||||
/**
|
||||
* "Opens" the socket.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
value: function connect() {
|
||||
if (this.connected) return this;
|
||||
this.subEvents();
|
||||
if (!this.io._reconnecting) this.io.open(); // ensure open
|
||||
if (!this.io["_reconnecting"]) this.io.open(); // ensure open
|
||||
|
||||
if ("open" === this.io._readyState) this.onopen();
|
||||
return this;
|
||||
@@ -947,7 +947,7 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
/**
|
||||
* Sends a `message` event.
|
||||
*
|
||||
* @return {Socket} self
|
||||
* @return self
|
||||
* @public
|
||||
*/
|
||||
|
||||
@@ -966,8 +966,8 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
* Override `emit`.
|
||||
* If the event is in `events`, it's emitted normally.
|
||||
*
|
||||
* @param {String} ev - event name
|
||||
* @return {Socket} self
|
||||
* @param ev - event name
|
||||
* @return self
|
||||
* @public
|
||||
*/
|
||||
|
||||
@@ -1013,7 +1013,7 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
/**
|
||||
* Sends a packet.
|
||||
*
|
||||
* @param {Object} packet
|
||||
* @param packet
|
||||
* @private
|
||||
*/
|
||||
|
||||
@@ -1054,7 +1054,7 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
/**
|
||||
* Called upon engine `close`.
|
||||
*
|
||||
* @param {String} reason
|
||||
* @param reason
|
||||
* @private
|
||||
*/
|
||||
|
||||
@@ -1071,7 +1071,7 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
/**
|
||||
* Called with socket packet.
|
||||
*
|
||||
* @param {Object} packet
|
||||
* @param packet
|
||||
* @private
|
||||
*/
|
||||
|
||||
@@ -1083,8 +1083,13 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
|
||||
switch (packet.type) {
|
||||
case socket_io_parser_1.PacketType.CONNECT:
|
||||
var id = packet.data.sid;
|
||||
this.onconnect(id);
|
||||
if (packet.data && packet.data.sid) {
|
||||
var id = packet.data.sid;
|
||||
this.onconnect(id);
|
||||
} else {
|
||||
_get(_getPrototypeOf(Socket.prototype), "emit", this).call(this, "connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case socket_io_parser_1.PacketType.EVENT:
|
||||
@@ -1120,7 +1125,7 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
/**
|
||||
* Called upon a server event.
|
||||
*
|
||||
* @param {Object} packet
|
||||
* @param packet
|
||||
* @private
|
||||
*/
|
||||
|
||||
@@ -1138,7 +1143,7 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
if (this.connected) {
|
||||
this.emitEvent(args);
|
||||
} else {
|
||||
this.receiveBuffer.push(args);
|
||||
this.receiveBuffer.push(Object.freeze(args));
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@@ -1195,7 +1200,7 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
/**
|
||||
* Called upon a server acknowlegement.
|
||||
*
|
||||
* @param {Object} packet
|
||||
* @param packet
|
||||
* @private
|
||||
*/
|
||||
|
||||
@@ -1221,6 +1226,7 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
}, {
|
||||
key: "onconnect",
|
||||
value: function onconnect(id) {
|
||||
debug("socket connected with id %s", id);
|
||||
this.id = id;
|
||||
this.connected = true;
|
||||
this.disconnected = false;
|
||||
@@ -1238,16 +1244,15 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
}, {
|
||||
key: "emitBuffered",
|
||||
value: function emitBuffered() {
|
||||
for (var i = 0; i < this.receiveBuffer.length; i++) {
|
||||
this.emitEvent(this.receiveBuffer[i]);
|
||||
}
|
||||
var _this3 = this;
|
||||
|
||||
this.receiveBuffer.forEach(function (args) {
|
||||
return _this3.emitEvent(args);
|
||||
});
|
||||
this.receiveBuffer = [];
|
||||
|
||||
for (var _i = 0; _i < this.sendBuffer.length; _i++) {
|
||||
this.packet(this.sendBuffer[_i]);
|
||||
}
|
||||
|
||||
this.sendBuffer.forEach(function (packet) {
|
||||
return _this3.packet(packet);
|
||||
});
|
||||
this.sendBuffer = [];
|
||||
}
|
||||
/**
|
||||
@@ -1283,12 +1288,12 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
this.subs = null;
|
||||
}
|
||||
|
||||
this.io._destroy(this);
|
||||
this.io["_destroy"](this);
|
||||
}
|
||||
/**
|
||||
* Disconnects the socket manually.
|
||||
*
|
||||
* @return {Socket} self
|
||||
* @return self
|
||||
* @public
|
||||
*/
|
||||
|
||||
@@ -1315,7 +1320,7 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
/**
|
||||
* Alias for disconnect()
|
||||
*
|
||||
* @return {Socket} self
|
||||
* @return self
|
||||
* @public
|
||||
*/
|
||||
|
||||
@@ -1327,8 +1332,8 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
/**
|
||||
* Sets the compress flag.
|
||||
*
|
||||
* @param {Boolean} compress - if `true`, compresses the sending data
|
||||
* @return {Socket} self
|
||||
* @param compress - if `true`, compresses the sending data
|
||||
* @return self
|
||||
* @public
|
||||
*/
|
||||
|
||||
@@ -1342,7 +1347,7 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
* Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
|
||||
* ready to send messages.
|
||||
*
|
||||
* @returns {Socket} self
|
||||
* @returns self
|
||||
* @public
|
||||
*/
|
||||
|
||||
@@ -1421,6 +1426,11 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
value: function listenersAny() {
|
||||
return this._anyListeners || [];
|
||||
}
|
||||
}, {
|
||||
key: "active",
|
||||
get: function get() {
|
||||
return !!this.subs;
|
||||
}
|
||||
}, {
|
||||
key: "volatile",
|
||||
get: function get() {
|
||||
@@ -1457,9 +1467,9 @@ var debug = __webpack_require__(/*! debug */ "./node_modules/debug/src/browser.j
|
||||
/**
|
||||
* URL parser.
|
||||
*
|
||||
* @param {String} uri - url
|
||||
* @param {Object} loc - An object meant to mimic window.location.
|
||||
* Defaults to window.location.
|
||||
* @param uri - url
|
||||
* @param loc - An object meant to mimic window.location.
|
||||
* Defaults to window.location.
|
||||
* @public
|
||||
*/
|
||||
|
||||
@@ -1470,7 +1480,7 @@ function url(uri, loc) {
|
||||
loc = loc || typeof location !== "undefined" && location;
|
||||
if (null == uri) uri = loc.protocol + "//" + loc.host; // relative path support
|
||||
|
||||
if ("string" === typeof uri) {
|
||||
if (typeof uri === "string") {
|
||||
if ("/" === uri.charAt(0)) {
|
||||
if ("/" === uri.charAt(1)) {
|
||||
uri = loc.protocol + uri;
|
||||
@@ -2525,7 +2535,6 @@ var Socket = /*#__PURE__*/function (_Emitter) {
|
||||
upgrade: true,
|
||||
jsonp: true,
|
||||
timestampParam: "t",
|
||||
policyPort: 843,
|
||||
rememberUpgrade: false,
|
||||
rejectUnauthorized: true,
|
||||
perMessageDeflate: {
|
||||
@@ -3663,8 +3672,6 @@ var debug = __webpack_require__(/*! debug */ "./node_modules/debug/src/browser.j
|
||||
function empty() {}
|
||||
|
||||
var hasXHR2 = function () {
|
||||
var XMLHttpRequest = __webpack_require__(/*! xmlhttprequest-ssl */ "./node_modules/engine.io-client/lib/xmlhttprequest.js");
|
||||
|
||||
var xhr = new XMLHttpRequest({
|
||||
xdomain: false
|
||||
});
|
||||
|
||||
File diff suppressed because one or more lines are too long
4
client-dist/socket.io.min.js
vendored
4
client-dist/socket.io.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
4
client-dist/socket.io.msgpack.min.js
vendored
4
client-dist/socket.io.msgpack.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
3542
package-lock.json
generated
3542
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "socket.io",
|
||||
"version": "3.0.3",
|
||||
"version": "3.0.4",
|
||||
"description": "node.js realtime framework server",
|
||||
"keywords": [
|
||||
"realtime",
|
||||
@@ -31,8 +31,8 @@
|
||||
"scripts": {
|
||||
"compile": "rimraf ./dist && tsc",
|
||||
"test": "npm run format:check && npm run compile && nyc mocha --require ts-node/register --reporter spec --slow 200 --bail --timeout 10000 test/socket.io.ts",
|
||||
"format:check": "prettier --check 'lib/**/*.ts' 'test/**/*.ts'",
|
||||
"format:fix": "prettier --write 'lib/**/*.ts' 'test/**/*.ts'",
|
||||
"format:check": "prettier --check \"lib/**/*.ts\" \"test/**/*.ts\"",
|
||||
"format:fix": "prettier --write \"lib/**/*.ts\" \"test/**/*.ts\"",
|
||||
"prepack": "npm run compile"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -53,10 +53,10 @@
|
||||
"eslint-config-prettier": "^6.11.0",
|
||||
"expect.js": "0.3.1",
|
||||
"mocha": "^3.5.3",
|
||||
"nyc": "^11.2.1",
|
||||
"nyc": "^15.1.0",
|
||||
"prettier": "^1.19.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"socket.io-client": "3.0.3",
|
||||
"socket.io-client": "3.0.4",
|
||||
"superagent": "^3.8.2",
|
||||
"supertest": "^3.0.0",
|
||||
"ts-node": "^9.0.0",
|
||||
|
||||
Reference in New Issue
Block a user