mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
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: -5579d40c24-dc381b72c6Related: - https://github.com/socketio/socket.io/issues/3922 - https://github.com/socketio/socket.io/issues/3927
This commit is contained in:
@@ -13,6 +13,7 @@ const debug = debugModule("socket.io:client");
|
||||
interface WriteOptions {
|
||||
compress?: boolean;
|
||||
volatile?: boolean;
|
||||
preEncoded?: boolean;
|
||||
wsPreEncoded?: string;
|
||||
}
|
||||
|
||||
@@ -200,12 +201,14 @@ export class Client<
|
||||
* @param {Object} opts
|
||||
* @private
|
||||
*/
|
||||
_packet(packet: Packet, opts: WriteOptions = {}): void {
|
||||
_packet(packet: Packet | any[], opts: WriteOptions = {}): void {
|
||||
if (this.conn.readyState !== "open") {
|
||||
debug("ignoring packet write %j", packet);
|
||||
return;
|
||||
}
|
||||
const encodedPackets = this.encoder.encode(packet);
|
||||
const encodedPackets = opts.preEncoded
|
||||
? (packet as any[]) // previous versions of the adapter incorrectly used socket.packet() instead of writeToEngine()
|
||||
: this.encoder.encode(packet as Packet);
|
||||
for (const encodedPacket of encodedPackets) {
|
||||
this.writeToEngine(encodedPacket, opts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user