-
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.
Merge pull request #100 from the-orange-alliance/aud-disp-manager
Add audience display manager
- Loading branch information
Showing
17 changed files
with
625 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { NextFunction, Request, Response, Router } from 'express'; | ||
import { getDB } from '../db/EventDatabase.js'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
const router = Router(); | ||
|
||
// Get all displays | ||
router.get( | ||
'/', | ||
async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const db = await getDB('global'); | ||
const clients = await db.selectAll( | ||
'socket_clients' | ||
); | ||
res.json(clients); | ||
} catch (e) { | ||
next(e); | ||
} | ||
} | ||
); | ||
|
||
// New client | ||
router.post( | ||
'/connect', | ||
async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
// Check if client already exists | ||
const db = await getDB('global'); | ||
if (req.body.persistantClientId) { | ||
req.body.connected = 1; | ||
// Update | ||
req.body.audienceDisplayChroma = req.body.audienceDisplayChroma.replaceAll('"', '') | ||
await db.updateWhere( | ||
'socket_clients', | ||
req.body, | ||
`persistantClientId = "${req.body.persistantClientId}"` | ||
); | ||
} else { | ||
// Brand new client, create new UUID | ||
req.body.persistantClientId = uuidv4(); | ||
await db.insertValue('socket_clients', [req.body]); | ||
} | ||
|
||
res.json(req.body); | ||
} catch (e) { | ||
next(e); | ||
} | ||
} | ||
); | ||
|
||
// Client Disconnected | ||
router.post( | ||
'/update/:persistantClientId', | ||
async (req: Request, res: Response, next: NextFunction) => { | ||
const { persistantClientId } = req.params; | ||
try { | ||
const db = await getDB('global'); | ||
await db.updateWhere( | ||
'socket_clients', | ||
req.body, | ||
`persistantClientId = "${persistantClientId}"` | ||
); | ||
res.json({ success: true }); | ||
} catch (e) { | ||
next(e); | ||
} | ||
} | ||
); | ||
|
||
// Client Deleted | ||
router.post( | ||
'/disconnect/:lastSocketId', | ||
async (req: Request, res: Response, next: NextFunction) => { | ||
const { lastSocketId } = req.params; | ||
try { | ||
const db = await getDB('global'); | ||
await db.updateWhere( | ||
'socket_clients', | ||
{ connected: 0 }, | ||
`lastSocketId = "${lastSocketId}"` | ||
); | ||
res.json({ success: true }); | ||
} catch (e) { | ||
next(e); | ||
} | ||
} | ||
); | ||
|
||
// Client Deleted | ||
router.delete( | ||
'/remove/:persistantClientId', | ||
async (req: Request, res: Response, next: NextFunction) => { | ||
const { persistantClientId } = req.params; | ||
try { | ||
const db = await getDB('global'); | ||
await db.deleteWhere( | ||
'socket_clients', | ||
`persistantClientId = "${persistantClientId}"` | ||
); | ||
res.json({ success: true }); | ||
} catch (e) { | ||
next(e); | ||
} | ||
} | ||
); | ||
|
||
export default router; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Oops, something went wrong.