This repository has been archived by the owner on May 22, 2021. It is now read-only.
forked from rhpijnacker/rehearse20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6235e95
commit 773d89b
Showing
3 changed files
with
51 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Socket } from 'socket.io'; | ||
|
||
export interface Client { | ||
id: string; | ||
address: string; | ||
name: string; | ||
sessionId: string; | ||
socket: Socket; | ||
} | ||
|
||
export default class Session extends Set<Client> { | ||
clients: Client[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Session from './Session'; | ||
|
||
export default class SessionManager { | ||
// sessionId -> Session | ||
static sessions = new Map<string, Session>(); | ||
|
||
static initializeSession(sessionId: string) { | ||
let session = SessionManager.sessions.get(sessionId); | ||
if (!session) { | ||
session = new Session(); | ||
SessionManager.sessions.set(sessionId, session); | ||
} | ||
return session; | ||
} | ||
|
||
static cleanupSession(sessionId: string) { | ||
const session = SessionManager.sessions.get(sessionId); | ||
if (session && session.size === 0) { | ||
SessionManager.sessions.delete(sessionId); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters