Skip to content

Commit

Permalink
fix: set default protocol version to 3 (#616)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
simonemazzoni authored and darrachequesne committed Mar 9, 2021
1 parent 5a7fa13 commit 868d891
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 868d891

Please sign in to comment.