Skip to content

Commit 2e023bf

Browse files
feat: add init() and close() methods
These extension points may be used by another adapter, in order to open or close a connection to a database for example. In Socket.IO v2, the join() method did accept a callback: ```js socket.join("room1", () => { io.to("room1").emit("hello"); }); ``` Depending on the adapter, it may now return a promise: ```js await socket.join("room1"); io.to("room1").emit("hello"); ``` Related: socketio/socket.io#3662
1 parent 5f417d2 commit 2e023bf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,24 @@ export class Adapter extends EventEmitter {
3232
this.encoder = nsp.server.encoder;
3333
}
3434

35+
/**
36+
* To be overridden
37+
*/
38+
public init(): Promise<void> | void {}
39+
40+
/**
41+
* To be overridden
42+
*/
43+
public close(): Promise<void> | void {}
44+
3545
/**
3646
* Adds a socket to a list of room.
3747
*
3848
* @param {SocketId} id the socket id
3949
* @param {Set<Room>} rooms a set of rooms
4050
* @public
4151
*/
42-
public addAll(id: SocketId, rooms: Set<Room>): void {
52+
public addAll(id: SocketId, rooms: Set<Room>): Promise<void> | void {
4353
for (const room of rooms) {
4454
if (!this.sids.has(id)) {
4555
this.sids.set(id, new Set());
@@ -59,7 +69,7 @@ export class Adapter extends EventEmitter {
5969
* @param {SocketId} id the socket id
6070
* @param {Room} room the room name
6171
*/
62-
public del(id: SocketId, room: Room): void {
72+
public del(id: SocketId, room: Room): Promise<void> | void {
6373
if (this.sids.has(id)) {
6474
this.sids.get(id).delete(room);
6575
}

0 commit comments

Comments
 (0)