-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSession.ts
More file actions
29 lines (23 loc) · 739 Bytes
/
Copy pathSession.ts
File metadata and controls
29 lines (23 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { QueueAction } from './types'
import { randomUUID } from 'node:crypto'
export interface SessionSettings {
action?: QueueAction
}
export default class Session {
public static create(): string {
const sid = randomUUID()
this.sessions.set(sid, {})
return sid
}
public static remove(sid: string) {
this.sessions.delete(sid)
}
public static get(sid: string): SessionSettings|undefined {
return this.sessions.get(sid)
}
public static set(sid: string, settings: Partial<SessionSettings>) {
const s = this.sessions.get(sid)
s && this.sessions.set(sid, Object.assign(s, settings))
}
private static sessions = new Map<string, Session>()
}