Skip to content

Commit

Permalink
feat: add current match tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
azaleacolburn committed Nov 19, 2024
1 parent 71520df commit 63b0eeb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Server } from 'socket.io';
import { type ViteDevServer } from 'vite';

const robotQueue: [string, 'red' | 'blue'][] = [];
let curr_match_key: string = '';

const webSocketServer = {
name: 'webSocketServer',
Expand All @@ -27,14 +28,24 @@ const webSocketServer = {
socket.leave('scout_queue');
});

socket.on('send_match', (teams: [string, 'red' | 'blue'][]) => {
socket.on('send_match', ([match_key, teams]: [string, [string, 'red' | 'blue'][]]) => {
if (!socket.rooms.has('admin_room')) return;

const scout_queue: Set<string> = io.of('/').adapter.rooms.get('scout_queue')!;
scout_queue
.values()
.forEach((sid) => io.to(sid).emit('time_to_scout', teams.pop()));
robotQueue.push(...teams);

// TODO: Decide if we care about this
// Update all connected sockets with new match info (for cosmetic purposes)
io.emit('new_match', match_key);
curr_match_key = match_key;
});

// Event-listener sockets that were offline to sync back up with the current match key
socket.on('request_curr_match', () => {
socket.emit('new_match', curr_match_key);
});
});
}
Expand Down

0 comments on commit 63b0eeb

Please sign in to comment.