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.
The getAllClients function has been added in eventReceipts.ts to return an array of client IDs. The handleEvent function has been implemented in gameControllers.js to handle event propagation. This function retrieves all client IDs and schedules the event sending to all clients. The routing in gameRoutes.js has been set up to handle the /events endpoint, including both GET and POST handlers. Fixes shivansh-bhatnagar18#45
- Loading branch information
Showing
3 changed files
with
30 additions
and
3 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 |
---|---|---|
@@ -1 +1,21 @@ | ||
// Implement the handler for `/events` endpoint. Refer to ARCHITECTURE.md for implementation details. | ||
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
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; |