Skip to content

Commit

Permalink
refactor: rename clients and clientRooms methods
Browse files Browse the repository at this point in the history
In Socket.IO glossary:

- a Client manages the low-level connection and can be associated with several Sockets
- a Socket belongs to a given Namespace
  • Loading branch information
darrachequesne committed Sep 16, 2020
1 parent 53ed3f4 commit 130f28a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ class Adapter extends EventEmitter {
}

/**
* Gets a list of clients by sid.
* Gets a list of sockets by sid.
*
* @param {Set<string>} rooms the explicit set of rooms to check.
* @public
*/
clients(rooms) {
sockets(rooms) {
const sids = new Set();

if (rooms.size) {
Expand All @@ -152,12 +152,12 @@ class Adapter extends EventEmitter {
}

/**
* Gets the list of rooms a given client has joined.
* Gets the list of rooms a given socket has joined.
*
* @param {String} id the socket id
* @public
*/
clientRooms(id) {
socketRooms(id) {
return this.sids.get(id);
}
}
Expand Down
16 changes: 8 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("socket.io-adapter", () => {
expect(adapter.sids.has("s2")).to.be(false);
});

it("should return a list of clients", () => {
it("should return a list of sockets", () => {
const adapter = new Adapter({
server: { encoder: null },
connected: new Map([
Expand All @@ -39,11 +39,11 @@ describe("socket.io-adapter", () => {
adapter.addAll("s2", new Set(["r2", "r3"]));
adapter.addAll("s3", new Set(["r3"]));

const clients = adapter.clients(new Set());
expect(clients).to.be.a(Set);
expect(clients.size).to.be(3);
expect(adapter.clients(new Set(["r2"])).size).to.be(2);
expect(adapter.clients(new Set(["r4"])).size).to.be(0);
const sockets = adapter.sockets(new Set());
expect(sockets).to.be.a(Set);
expect(sockets.size).to.be(3);
expect(adapter.sockets(new Set(["r2"])).size).to.be(2);
expect(adapter.sockets(new Set(["r4"])).size).to.be(0);
});

it("should return a list of rooms", () => {
Expand All @@ -52,9 +52,9 @@ describe("socket.io-adapter", () => {
adapter.addAll("s2", new Set(["r2", "r3"]));
adapter.addAll("s3", new Set(["r3"]));

const rooms = adapter.clientRooms("s2");
const rooms = adapter.socketRooms("s2");
expect(rooms).to.be.a(Set);
expect(rooms.size).to.be(2);
expect(adapter.clientRooms("s4")).to.be(undefined);
expect(adapter.socketRooms("s4")).to.be(undefined);
});
});

0 comments on commit 130f28a

Please sign in to comment.