Skip to content

Commit

Permalink
feat(io): room evict (#783)
Browse files Browse the repository at this point in the history
  • Loading branch information
pluvrt authored Oct 15, 2024
1 parent 84491c7 commit bb21274
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-papayas-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pluv/io": patch
---

Added the ability to evict (i.e. close) a connection to a room via `IORoom.evict` and `IORoom.evictAll`.
26 changes: 26 additions & 0 deletions packages/io/src/IORoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,32 @@ export class IORoom<
this._uninitialize = uninitialize;
}

/**
* @description Closes a connection with the specified sessionId
* @param sessionId The session id of the connection to close
*/
public async evict(sessionId: string): Promise<void> {
const session = this._sessions.get(sessionId);

if (session) session.state.quit = true;

await this._emitQuitters();
}

/**
* @description Closes all connections to this room, effectively destroying
* the room
*/
public async evictAll(): Promise<void> {
const sessions = Array.from(this._sessions.values());

sessions.forEach((session) => {
session.state.quit = true;
});

await this._emitQuitters();
}

public getSize(): number {
const currentTime = new Date().getTime();

Expand Down

0 comments on commit bb21274

Please sign in to comment.