Skip to content

Commit a2cf248

Browse files
committedMay 17, 2021
fix: ensure compatibility with previous versions of the adapter
Using `socket.io@4.1.0` with `socket.io-adapter@2.2.0` would lead to the following error: > Uncaught Error: unknown packet type NaN Because the packet would be encoded twice, resulting in "undefined". See also: - socketio/socket.io-adapter@5579d40 - dc381b7 Related: - #3922 - #3927
1 parent 995f38f commit a2cf248

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎lib/client.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const debug = debugModule("socket.io:client");
1313
interface WriteOptions {
1414
compress?: boolean;
1515
volatile?: boolean;
16+
preEncoded?: boolean;
1617
wsPreEncoded?: string;
1718
}
1819

@@ -200,12 +201,14 @@ export class Client<
200201
* @param {Object} opts
201202
* @private
202203
*/
203-
_packet(packet: Packet, opts: WriteOptions = {}): void {
204+
_packet(packet: Packet | any[], opts: WriteOptions = {}): void {
204205
if (this.conn.readyState !== "open") {
205206
debug("ignoring packet write %j", packet);
206207
return;
207208
}
208-
const encodedPackets = this.encoder.encode(packet);
209+
const encodedPackets = opts.preEncoded
210+
? (packet as any[]) // previous versions of the adapter incorrectly used socket.packet() instead of writeToEngine()
211+
: this.encoder.encode(packet as Packet);
209212
for (const encodedPacket of encodedPackets) {
210213
this.writeToEngine(encodedPacket, opts);
211214
}

0 commit comments

Comments
 (0)
Please sign in to comment.