refactor: use Namespace#sockets to broadcast

This commit is contained in:
Damien Arrachequesne
2020-10-15 12:15:32 +02:00
parent 5d81b13431
commit 0a9762cac2
2 changed files with 5 additions and 5 deletions

View File

@@ -122,7 +122,7 @@ export class Adapter extends EventEmitter {
for (const id of this.rooms.get(room)) {
if (ids.has(id) || except.has(id)) continue;
const socket = this.nsp.connected.get(id);
const socket = this.nsp.sockets.get(id);
if (socket) {
socket.packet(encodedPackets, packetOpts);
ids.add(id);
@@ -132,7 +132,7 @@ export class Adapter extends EventEmitter {
} else {
for (const [id] of this.sids) {
if (except.has(id)) continue;
const socket = this.nsp.connected.get(id);
const socket = this.nsp.sockets.get(id);
if (socket) socket.packet(encodedPackets, packetOpts);
}
}
@@ -151,14 +151,14 @@ export class Adapter extends EventEmitter {
if (!this.rooms.has(room)) continue;
for (const id of this.rooms.get(room)) {
if (this.nsp.connected.has(id)) {
if (this.nsp.sockets.has(id)) {
sids.add(id);
}
}
}
} else {
for (const [id] of this.sids) {
if (this.nsp.connected.has(id)) sids.add(id);
if (this.nsp.sockets.has(id)) sids.add(id);
}
}

View File

@@ -29,7 +29,7 @@ describe("socket.io-adapter", () => {
it("should return a list of sockets", async () => {
const adapter = new Adapter({
server: { encoder: null },
connected: new Map([
sockets: new Map([
["s1", true],
["s2", true],
["s3", true]