Skip to content

Commit c043650

Browse files
fix: Adapter#encode() is now synchronous
See https://github.com/socketio/socket.io-parser/releases/tag/4.0.0
1 parent 7216d7a commit c043650

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

lib/index.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,28 +114,28 @@ export class Adapter extends EventEmitter {
114114
const ids = new Set();
115115

116116
packet.nsp = this.nsp.name;
117-
this.encoder.encode(packet, encodedPackets => {
118-
if (rooms.size) {
119-
for (const room of rooms) {
120-
if (!this.rooms.has(room)) continue;
121-
122-
for (const id of this.rooms.get(room)) {
123-
if (ids.has(id) || except.has(id)) continue;
124-
const socket = this.nsp.connected.get(id);
125-
if (socket) {
126-
socket.packet(encodedPackets, packetOpts);
127-
ids.add(id);
128-
}
129-
}
130-
}
131-
} else {
132-
for (const [id] of this.sids) {
133-
if (except.has(id)) continue;
117+
const encodedPackets = this.encoder.encode(packet);
118+
119+
if (rooms.size) {
120+
for (const room of rooms) {
121+
if (!this.rooms.has(room)) continue;
122+
123+
for (const id of this.rooms.get(room)) {
124+
if (ids.has(id) || except.has(id)) continue;
134125
const socket = this.nsp.connected.get(id);
135-
if (socket) socket.packet(encodedPackets, packetOpts);
126+
if (socket) {
127+
socket.packet(encodedPackets, packetOpts);
128+
ids.add(id);
129+
}
136130
}
137131
}
138-
});
132+
} else {
133+
for (const [id] of this.sids) {
134+
if (except.has(id)) continue;
135+
const socket = this.nsp.connected.get(id);
136+
if (socket) socket.packet(encodedPackets, packetOpts);
137+
}
138+
}
139139
}
140140

141141
/**

0 commit comments

Comments
 (0)