forked from shivansh-bhatnagar18/multiplayer-uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added an error page which is rendered when an unknown route is accessed Fixes: shivansh-bhatnagar18#21
- Loading branch information
Showing
27 changed files
with
1,286 additions
and
81 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,18 @@ | ||
# .github/workflows/take.yml | ||
name: Assign issue to contributor | ||
on: | ||
issue_comment: | ||
|
||
jobs: | ||
assign: | ||
name: Take an issue | ||
runs-on: ubuntu-latest | ||
permissions: | ||
issues: write | ||
steps: | ||
- name: take the issue | ||
uses: bdougie/take-action@main | ||
with: | ||
message: Thanks for taking this issue! Let us know if you have any questions! | ||
trigger: /assign | ||
token: ${{ secrets.ISSUE_TOKEN }} |
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
import { getAllClients, scheduleSend } from '../eventRecipients'; | ||
|
||
async function handleEvent(req, res) { | ||
const event = req.body; | ||
|
||
const clientIds = getAllClients(); | ||
|
||
const eligibleClientIds = filterEligibleClients(clientIds); | ||
|
||
eligibleClientIds.forEach((clientId) => { | ||
scheduleSend(clientId, event); | ||
}); | ||
|
||
res.status(200).send({ message: 'Event propagated to clients.' }); | ||
} | ||
|
||
function filterEligibleClients(clientIds) { | ||
return clientIds; | ||
} | ||
|
||
export default handleEvent; |
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,49 @@ | ||
// this module is responsible for handling the clients currently connected to the server. | ||
// It stores the clients in a Map object, where the key is the client id and the value is the | ||
// client's http response object. | ||
// When sending an event, we first push the event to a queue. We need to use a queue because it | ||
// is possible that the client hasn't sent the next polling request yet, i.e, we don't have a response | ||
// object for that client yet. When the client sends the next polling request, we will send the events | ||
// from the queue to the client. | ||
|
||
import { Response } from 'express'; | ||
|
||
type ClientId = string; | ||
|
||
const clients = new Map<ClientId, Response>(); | ||
const eventQueue = new Map<ClientId, AppEvent[]>(); | ||
|
||
export function addClient(clientId: ClientId, res: Response) { | ||
// todo: We can immediately send any events that are in the queue. | ||
clients.set(clientId, res); | ||
eventQueue.set(clientId, []); | ||
} | ||
|
||
export function removeClient(clientId: ClientId) { | ||
clients.delete(clientId); | ||
eventQueue.delete(clientId); | ||
} | ||
|
||
export function getClient(clientId: ClientId) { | ||
return clients.get(clientId); | ||
} | ||
|
||
export function getAllClients(): ClientId[] { | ||
return Array.from(clients.keys()); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export function scheduleSend(clientId: ClientId, event: AppEvent) { | ||
//todo: Enqueue the event for sending. | ||
} | ||
|
||
export function doSendEvents(clientId: ClientId) { | ||
const res = clients.get(clientId); | ||
const events = eventQueue.get(clientId) || []; | ||
|
||
if (res && events.length > 0) { | ||
res.json({ events }); | ||
eventQueue.set(clientId, []); | ||
clients.delete(clientId); | ||
} | ||
} |
File renamed without changes.
7 changes: 5 additions & 2 deletions
7
backend/routes/gameRoutes.js → backend/src/routes/gameRoutes.ts
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import express from 'express'; | ||
import { addClient } from '../eventRecipients'; | ||
import handleEvent from '../controllers/gameControllers'; | ||
|
||
const router = express.Router(); | ||
|
||
router.get('/events', (req, res) => { | ||
addClient('user_id', res); | ||
}); | ||
|
||
// the post handler should retrieve the game the user is currently in, and update the game state. | ||
// The request body contains the event data, as described in ARCHITECTURE.md | ||
router.post('/events', handleEvent); | ||
|
||
export default router; |
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
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
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
File renamed without changes.
Oops, something went wrong.