Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
feat: more queue stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonHowe committed Jul 17, 2020
1 parent 6eedbbb commit c0b5079
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/api/src/modules/websockets/actions/joinQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import HandlerResponse from "../types/HandlerResponse";
import WebSocket from "ws";

export default (data: number, ws: WebSocket): HandlerResponse => {
queue.push({ id: data, ws });
const changeWSKey = Math.floor(Math.random() * 899999) + 100000;
queue.push({ id: data, ws, changeWSKey });
return {
category: "joinResponse",
data: [{ client: ws, data: "Successfully joined queue" }]
data: [{ client: ws, data: { success: true, changeWSKey } }]
};
};
2 changes: 1 addition & 1 deletion packages/api/src/modules/websockets/actions/leaveQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default (id: number, ws: WebSocket): HandlerResponse => {
queue.splice(queue.findIndex(l => l.id === id));
return {
category: "joinResponse",
data: [{ client: ws, data: "Successfully left queue" }]
data: [{ client: ws, data: { success: true } }]
};
};
11 changes: 11 additions & 0 deletions packages/api/src/modules/websockets/actions/switchQueueLocation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import WebSocket from "ws";
import { queue } from "../gamesData";

export default (data: number, ws: WebSocket) => {
const queueling = queue.find(l => l.changeWSKey === data);
if (!queueling) {
return false;
}
queueling.ws = ws;
return true;
};
1 change: 1 addition & 0 deletions packages/api/src/modules/websockets/gamesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import WebSocket from "ws";
interface Queueling {
id: number;
ws: WebSocket | null;
changeWSKey: number;
}

export const games = {};
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/modules/websockets/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import HandlerResponse from "./types/HandlerResponse";

const wsRoutes: Record<
string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(data: any, ws: WebSocket) => HandlerResponse
> = {
joinQueue,
Expand Down

0 comments on commit c0b5079

Please sign in to comment.