aboutsummaryrefslogtreecommitdiffstats
path: root/backend/dist/config/session-store.js
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2023-11-04 21:28:11 +0000
committerLeonardo Bishop <me@leonardobishop.com>2023-11-04 21:28:11 +0000
commit7d8cca54e548d2a85287fd2325db88f2697be55a (patch)
tree3daa82c6a709363f2f08d9f875d849e4babe1f8f /backend/dist/config/session-store.js
parente1633f3348ff7fc5e9131eeae2f2feba09f04838 (diff)
Add more shit
Diffstat (limited to 'backend/dist/config/session-store.js')
-rw-r--r--backend/dist/config/session-store.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/backend/dist/config/session-store.js b/backend/dist/config/session-store.js
new file mode 100644
index 0000000..e40e6f6
--- /dev/null
+++ b/backend/dist/config/session-store.js
@@ -0,0 +1,59 @@
+const sessions = {};
+function makeid(length) {
+ let result = '';
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+ const charactersLength = characters.length;
+ let counter = 0;
+ while (counter < length) {
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
+ counter += 1;
+ }
+ return result;
+}
+export const createNewSession = () => {
+ const id = makeid(10);
+ const session = {
+ id,
+ state: "waiting",
+ host: undefined,
+ clients: [],
+ };
+ sessions[id] = session;
+ return session;
+};
+export const setSessionState = (id, state) => {
+ if (!sessions[id]) {
+ return;
+ }
+ sessions[id].state = state;
+};
+export const setSessionHost = (id, clientId) => {
+ if (!sessions[id]) {
+ return;
+ }
+ sessions[id].host = clientId;
+};
+export const addSessionClient = (id, clientId) => {
+ var _a;
+ if (!sessions[id]) {
+ return;
+ }
+ (_a = sessions[id]) === null || _a === void 0 ? void 0 : _a.clients.push(clientId);
+};
+export const cleanupSession = (id) => {
+ if (!sessions[id]) {
+ return;
+ }
+ // if (sessions[id].host) {
+ // sessions[id].host!.close();
+ // }
+ //
+ // sessions[id].clients.forEach((client) => {
+ // client.close();
+ // });
+ delete sessions[id];
+};
+export const getSession = (id) => {
+ return sessions[id];
+};
+//# sourceMappingURL=session-store.js.map \ No newline at end of file