Skip to content

Commit fb760d9

Browse files
feat: remove deprecated methods
An official alternative has been added in the core in v4.0.0: - adapter.remoteJoin() -> io.socketsJoin() - adapter.remoteLeave() -> io.socketsLeave() - adapter.remoteDisconnect() -> io.disconnectSockets() - adapter.sockets() -> io.fetchSockets() BREAKING CHANGE: the remoteJoin(), remoteLeave(), remoteDisconnect() and sockets() methods are removed in favor of the official alternatives Related: socketio/socket.io@b25495c
1 parent 5b3bc8a commit fb760d9

File tree

2 files changed

+0
-225
lines changed

2 files changed

+0
-225
lines changed

Diff for: lib/index.ts

-188
Original file line numberDiff line numberDiff line change
@@ -663,53 +663,6 @@ export class RedisAdapter extends Adapter {
663663
super.broadcastWithAck(packet, opts, clientCountCallback, ack);
664664
}
665665

666-
/**
667-
* @deprecated Please use `namespace.fetchSockets()` instead.
668-
*
669-
* Gets a list of sockets by sid.
670-
*
671-
* @param {Set<Room>} rooms the explicit set of rooms to check.
672-
*/
673-
public async sockets(rooms: Set<Room>): Promise<Set<SocketId>> {
674-
const localSockets = await super.sockets(rooms);
675-
const numSub = await this.getNumSub();
676-
debug('waiting for %d responses to "sockets" request', numSub);
677-
678-
if (numSub <= 1) {
679-
return Promise.resolve(localSockets);
680-
}
681-
682-
const requestId = uid2(6);
683-
const request = JSON.stringify({
684-
uid: this.uid,
685-
requestId,
686-
type: RequestType.SOCKETS,
687-
rooms: [...rooms],
688-
});
689-
690-
return new Promise((resolve, reject) => {
691-
const timeout = setTimeout(() => {
692-
if (this.requests.has(requestId)) {
693-
reject(
694-
new Error("timeout reached while waiting for sockets response")
695-
);
696-
this.requests.delete(requestId);
697-
}
698-
}, this.requestsTimeout);
699-
700-
this.requests.set(requestId, {
701-
type: RequestType.SOCKETS,
702-
numSub,
703-
resolve,
704-
timeout,
705-
msgCount: 1,
706-
sockets: localSockets,
707-
});
708-
709-
this.pubClient.publish(this.requestChannel, request);
710-
});
711-
}
712-
713666
/**
714667
* Gets the list of all rooms (across every node)
715668
*
@@ -754,147 +707,6 @@ export class RedisAdapter extends Adapter {
754707
});
755708
}
756709

757-
/**
758-
* @deprecated Please use `namespace.socketsJoin()` instead.
759-
*
760-
* Makes the socket with the given id join the room
761-
*
762-
* @param {String} id - socket id
763-
* @param {String} room - room name
764-
* @public
765-
*/
766-
public remoteJoin(id: SocketId, room: Room): Promise<void> {
767-
const requestId = uid2(6);
768-
769-
const socket = this.nsp.sockets.get(id);
770-
if (socket) {
771-
socket.join(room);
772-
return Promise.resolve();
773-
}
774-
775-
const request = JSON.stringify({
776-
uid: this.uid,
777-
requestId,
778-
type: RequestType.REMOTE_JOIN,
779-
sid: id,
780-
room,
781-
});
782-
783-
return new Promise((resolve, reject) => {
784-
const timeout = setTimeout(() => {
785-
if (this.requests.has(requestId)) {
786-
reject(
787-
new Error("timeout reached while waiting for remoteJoin response")
788-
);
789-
this.requests.delete(requestId);
790-
}
791-
}, this.requestsTimeout);
792-
793-
this.requests.set(requestId, {
794-
type: RequestType.REMOTE_JOIN,
795-
resolve,
796-
timeout,
797-
});
798-
799-
this.pubClient.publish(this.requestChannel, request);
800-
});
801-
}
802-
803-
/**
804-
* @deprecated Please use `namespace.socketsLeave()` instead.
805-
*
806-
* Makes the socket with the given id leave the room
807-
*
808-
* @param {String} id - socket id
809-
* @param {String} room - room name
810-
* @public
811-
*/
812-
public remoteLeave(id: SocketId, room: Room): Promise<void> {
813-
const requestId = uid2(6);
814-
815-
const socket = this.nsp.sockets.get(id);
816-
if (socket) {
817-
socket.leave(room);
818-
return Promise.resolve();
819-
}
820-
821-
const request = JSON.stringify({
822-
uid: this.uid,
823-
requestId,
824-
type: RequestType.REMOTE_LEAVE,
825-
sid: id,
826-
room,
827-
});
828-
829-
return new Promise((resolve, reject) => {
830-
const timeout = setTimeout(() => {
831-
if (this.requests.has(requestId)) {
832-
reject(
833-
new Error("timeout reached while waiting for remoteLeave response")
834-
);
835-
this.requests.delete(requestId);
836-
}
837-
}, this.requestsTimeout);
838-
839-
this.requests.set(requestId, {
840-
type: RequestType.REMOTE_LEAVE,
841-
resolve,
842-
timeout,
843-
});
844-
845-
this.pubClient.publish(this.requestChannel, request);
846-
});
847-
}
848-
849-
/**
850-
* @deprecated Please use `namespace.disconnectSockets()` instead.
851-
*
852-
* Makes the socket with the given id to be forcefully disconnected
853-
*
854-
* @param {String} id - socket id
855-
* @param {Boolean} close - if `true`, closes the underlying connection
856-
*
857-
* @public
858-
*/
859-
public remoteDisconnect(id: SocketId, close?: boolean): Promise<void> {
860-
const requestId = uid2(6);
861-
862-
const socket = this.nsp.sockets.get(id);
863-
if (socket) {
864-
socket.disconnect(close);
865-
return Promise.resolve();
866-
}
867-
868-
const request = JSON.stringify({
869-
uid: this.uid,
870-
requestId,
871-
type: RequestType.REMOTE_DISCONNECT,
872-
sid: id,
873-
close,
874-
});
875-
876-
return new Promise((resolve, reject) => {
877-
const timeout = setTimeout(() => {
878-
if (this.requests.has(requestId)) {
879-
reject(
880-
new Error(
881-
"timeout reached while waiting for remoteDisconnect response"
882-
)
883-
);
884-
this.requests.delete(requestId);
885-
}
886-
}, this.requestsTimeout);
887-
888-
this.requests.set(requestId, {
889-
type: RequestType.REMOTE_DISCONNECT,
890-
resolve,
891-
timeout,
892-
});
893-
894-
this.pubClient.publish(this.requestChannel, request);
895-
});
896-
}
897-
898710
public async fetchSockets(opts: BroadcastOptions): Promise<any[]> {
899711
const localSockets = await super.fetchSockets(opts);
900712

Diff for: test/index.ts

-37
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,6 @@ describe(`socket.io-redis with ${
108108
socket1.disconnect();
109109
});
110110

111-
it("returns sockets in the same room", async () => {
112-
socket1.join("woot");
113-
socket2.join("woot");
114-
115-
const sockets = await namespace1.adapter.sockets(new Set(["woot"]));
116-
117-
expect(sockets.size).to.eql(2);
118-
expect(sockets.has(socket1.id)).to.be(true);
119-
expect(sockets.has(socket2.id)).to.be(true);
120-
expect(namespace1.adapter.requests.size).to.eql(0);
121-
});
122-
123111
it("broadcasts with multiple acknowledgements", (done) => {
124112
client1.on("test", (cb) => {
125113
cb(1);
@@ -266,31 +254,6 @@ describe(`socket.io-redis with ${
266254
expect(rooms.has("woot1")).to.be(true);
267255
});
268256

269-
it("makes a given socket join a room", async () => {
270-
await namespace3.adapter.remoteJoin(socket1.id, "woot3");
271-
272-
expect(socket1.rooms.size).to.eql(2);
273-
expect(socket1.rooms.has("woot3")).to.be(true);
274-
});
275-
276-
it("makes a given socket leave a room", async () => {
277-
socket1.join("woot3");
278-
279-
await namespace3.adapter.remoteLeave(socket1.id, "woot3");
280-
281-
expect(socket1.rooms.size).to.eql(1);
282-
expect(socket1.rooms.has("woot3")).to.be(false);
283-
});
284-
285-
it("makes a given socket disconnect", (done) => {
286-
client1.on("disconnect", (err) => {
287-
expect(err).to.be("io server disconnect");
288-
done();
289-
});
290-
291-
namespace2.adapter.remoteDisconnect(socket1.id, false);
292-
});
293-
294257
describe("socketsJoin", () => {
295258
it("makes all socket instances join the specified room", (done) => {
296259
namespace1.socketsJoin("room1");

0 commit comments

Comments
 (0)