From 868d89111de0ab5bd0e147ecaff7983afbf5d087 Mon Sep 17 00:00:00 2001 From: Simone Mazzoni Date: Sun, 7 Mar 2021 00:22:29 +0100 Subject: [PATCH] fix: set default protocol version to 3 (#616) socket.io-client-swift libs version <=15.2.0, which uses protocol version 3, do not explicitly add the EIO query parameter at transport initialization. This omission leads the server to treat the client as a client that supports the protocol version 4, previously set as default, which is not correct for those versions of the client lib. From socket.io-client-swift version v16.0.0 the EIO query parameter is explicitly passed to specify the protocol version supported, but since the allowEIO3 parameter aims to make the server compatible with previous versions which in most of the cases are already used in production and not easily upgradable, it makes more sense to default the EIO version to 3 if not explicitly set by the client since the newer client versions pass the EIO protocol version in query parameters. Related: https://github.com/socketio/socket.io/issues/3794 --- lib/server.js | 2 +- lib/transport.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/server.js b/lib/server.js index 644d6b9ef..9a267a6dd 100644 --- a/lib/server.js +++ b/lib/server.js @@ -229,7 +229,7 @@ class Server extends EventEmitter { * @api private */ async handshake(transportName, req) { - const protocol = req._query.EIO === "3" ? 3 : 4; // 4th revision by default + const protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default if (protocol === 3 && !this.opts.allowEIO3) { debug("unsupported protocol version"); sendErrorMessage( diff --git a/lib/transport.js b/lib/transport.js index 7fb2603a5..0da3993cb 100644 --- a/lib/transport.js +++ b/lib/transport.js @@ -22,8 +22,8 @@ class Transport extends EventEmitter { super(); this.readyState = "open"; this.discarded = false; - this.protocol = req._query.EIO === "3" ? 3 : 4; // 4th revision by default - this.parser = this.protocol === 3 ? parser_v3 : parser_v4; + this.protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default + this.parser = this.protocol === 4 ? parser_v4 : parser_v3; } /**