diff --git a/lib/index.ts b/lib/index.ts index 60da9b9..ee7cc7c 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -663,53 +663,6 @@ export class RedisAdapter extends Adapter { super.broadcastWithAck(packet, opts, clientCountCallback, ack); } - /** - * @deprecated Please use `namespace.fetchSockets()` instead. - * - * Gets a list of sockets by sid. - * - * @param {Set} rooms the explicit set of rooms to check. - */ - public async sockets(rooms: Set): Promise> { - const localSockets = await super.sockets(rooms); - const numSub = await this.getNumSub(); - debug('waiting for %d responses to "sockets" request', numSub); - - if (numSub <= 1) { - return Promise.resolve(localSockets); - } - - const requestId = uid2(6); - const request = JSON.stringify({ - uid: this.uid, - requestId, - type: RequestType.SOCKETS, - rooms: [...rooms], - }); - - return new Promise((resolve, reject) => { - const timeout = setTimeout(() => { - if (this.requests.has(requestId)) { - reject( - new Error("timeout reached while waiting for sockets response") - ); - this.requests.delete(requestId); - } - }, this.requestsTimeout); - - this.requests.set(requestId, { - type: RequestType.SOCKETS, - numSub, - resolve, - timeout, - msgCount: 1, - sockets: localSockets, - }); - - this.pubClient.publish(this.requestChannel, request); - }); - } - /** * Gets the list of all rooms (across every node) * @@ -754,147 +707,6 @@ export class RedisAdapter extends Adapter { }); } - /** - * @deprecated Please use `namespace.socketsJoin()` instead. - * - * Makes the socket with the given id join the room - * - * @param {String} id - socket id - * @param {String} room - room name - * @public - */ - public remoteJoin(id: SocketId, room: Room): Promise { - const requestId = uid2(6); - - const socket = this.nsp.sockets.get(id); - if (socket) { - socket.join(room); - return Promise.resolve(); - } - - const request = JSON.stringify({ - uid: this.uid, - requestId, - type: RequestType.REMOTE_JOIN, - sid: id, - room, - }); - - return new Promise((resolve, reject) => { - const timeout = setTimeout(() => { - if (this.requests.has(requestId)) { - reject( - new Error("timeout reached while waiting for remoteJoin response") - ); - this.requests.delete(requestId); - } - }, this.requestsTimeout); - - this.requests.set(requestId, { - type: RequestType.REMOTE_JOIN, - resolve, - timeout, - }); - - this.pubClient.publish(this.requestChannel, request); - }); - } - - /** - * @deprecated Please use `namespace.socketsLeave()` instead. - * - * Makes the socket with the given id leave the room - * - * @param {String} id - socket id - * @param {String} room - room name - * @public - */ - public remoteLeave(id: SocketId, room: Room): Promise { - const requestId = uid2(6); - - const socket = this.nsp.sockets.get(id); - if (socket) { - socket.leave(room); - return Promise.resolve(); - } - - const request = JSON.stringify({ - uid: this.uid, - requestId, - type: RequestType.REMOTE_LEAVE, - sid: id, - room, - }); - - return new Promise((resolve, reject) => { - const timeout = setTimeout(() => { - if (this.requests.has(requestId)) { - reject( - new Error("timeout reached while waiting for remoteLeave response") - ); - this.requests.delete(requestId); - } - }, this.requestsTimeout); - - this.requests.set(requestId, { - type: RequestType.REMOTE_LEAVE, - resolve, - timeout, - }); - - this.pubClient.publish(this.requestChannel, request); - }); - } - - /** - * @deprecated Please use `namespace.disconnectSockets()` instead. - * - * Makes the socket with the given id to be forcefully disconnected - * - * @param {String} id - socket id - * @param {Boolean} close - if `true`, closes the underlying connection - * - * @public - */ - public remoteDisconnect(id: SocketId, close?: boolean): Promise { - const requestId = uid2(6); - - const socket = this.nsp.sockets.get(id); - if (socket) { - socket.disconnect(close); - return Promise.resolve(); - } - - const request = JSON.stringify({ - uid: this.uid, - requestId, - type: RequestType.REMOTE_DISCONNECT, - sid: id, - close, - }); - - return new Promise((resolve, reject) => { - const timeout = setTimeout(() => { - if (this.requests.has(requestId)) { - reject( - new Error( - "timeout reached while waiting for remoteDisconnect response" - ) - ); - this.requests.delete(requestId); - } - }, this.requestsTimeout); - - this.requests.set(requestId, { - type: RequestType.REMOTE_DISCONNECT, - resolve, - timeout, - }); - - this.pubClient.publish(this.requestChannel, request); - }); - } - public async fetchSockets(opts: BroadcastOptions): Promise { const localSockets = await super.fetchSockets(opts); diff --git a/test/index.ts b/test/index.ts index c064485..a5df888 100644 --- a/test/index.ts +++ b/test/index.ts @@ -108,18 +108,6 @@ describe(`socket.io-redis with ${ socket1.disconnect(); }); - it("returns sockets in the same room", async () => { - socket1.join("woot"); - socket2.join("woot"); - - const sockets = await namespace1.adapter.sockets(new Set(["woot"])); - - expect(sockets.size).to.eql(2); - expect(sockets.has(socket1.id)).to.be(true); - expect(sockets.has(socket2.id)).to.be(true); - expect(namespace1.adapter.requests.size).to.eql(0); - }); - it("broadcasts with multiple acknowledgements", (done) => { client1.on("test", (cb) => { cb(1); @@ -266,31 +254,6 @@ describe(`socket.io-redis with ${ expect(rooms.has("woot1")).to.be(true); }); - it("makes a given socket join a room", async () => { - await namespace3.adapter.remoteJoin(socket1.id, "woot3"); - - expect(socket1.rooms.size).to.eql(2); - expect(socket1.rooms.has("woot3")).to.be(true); - }); - - it("makes a given socket leave a room", async () => { - socket1.join("woot3"); - - await namespace3.adapter.remoteLeave(socket1.id, "woot3"); - - expect(socket1.rooms.size).to.eql(1); - expect(socket1.rooms.has("woot3")).to.be(false); - }); - - it("makes a given socket disconnect", (done) => { - client1.on("disconnect", (err) => { - expect(err).to.be("io server disconnect"); - done(); - }); - - namespace2.adapter.remoteDisconnect(socket1.id, false); - }); - describe("socketsJoin", () => { it("makes all socket instances join the specified room", (done) => { namespace1.socketsJoin("room1");