Skip to content

Commit 868d891

Browse files
simonemazzonidarrachequesne
authored andcommitted
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: socketio/socket.io#3794
1 parent 5a7fa13 commit 868d891

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class Server extends EventEmitter {
229229
* @api private
230230
*/
231231
async handshake(transportName, req) {
232-
const protocol = req._query.EIO === "3" ? 3 : 4; // 4th revision by default
232+
const protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default
233233
if (protocol === 3 && !this.opts.allowEIO3) {
234234
debug("unsupported protocol version");
235235
sendErrorMessage(

lib/transport.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class Transport extends EventEmitter {
2222
super();
2323
this.readyState = "open";
2424
this.discarded = false;
25-
this.protocol = req._query.EIO === "3" ? 3 : 4; // 4th revision by default
26-
this.parser = this.protocol === 3 ? parser_v3 : parser_v4;
25+
this.protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default
26+
this.parser = this.protocol === 4 ? parser_v4 : parser_v3;
2727
}
2828

2929
/**

0 commit comments

Comments
 (0)