MCPcopy Create free account
hub / github.com/AlecM33/Werewolf / handleTimerCommand

Function handleTimerCommand

server/modules/Events.js:5–92  ·  view source on GitHub ↗
(timerEventSubtype, game, socketId, vars)

Source from the content-addressed store, hash-verified

3const { EVENT_IDS, STATUS, USER_TYPES, GAME_PROCESS_COMMANDS, REDIS_CHANNELS, PRIMITIVES } = require('../config/globals');
4
5async function handleTimerCommand (timerEventSubtype, game, socketId, vars) {
6 switch (timerEventSubtype) {
7 case GAME_PROCESS_COMMANDS.PAUSE_TIMER:
8 const pauseTimeRemaining = await vars.gameManager.pauseTimer(game);
9 if (pauseTimeRemaining !== null) {
10 await vars.eventManager.handleEventById(
11 EVENT_IDS.PAUSE_TIMER,
12 null,
13 game,
14 null,
15 game.accessCode,
16 { timeRemaining: pauseTimeRemaining },
17 null,
18 false
19 );
20 await vars.gameManager.refreshGame(game);
21 await vars.eventManager.publisher.publish(
22 REDIS_CHANNELS.ACTIVE_GAME_STREAM,
23 vars.eventManager.createMessageToPublish(
24 game.accessCode,
25 EVENT_IDS.PAUSE_TIMER,
26 vars.instanceId,
27 JSON.stringify({ timeRemaining: pauseTimeRemaining })
28 )
29 );
30 }
31 break;
32 case GAME_PROCESS_COMMANDS.RESUME_TIMER:
33 const resumeTimeRemaining = await vars.gameManager.resumeTimer(game);
34 if (resumeTimeRemaining !== null) {
35 await vars.eventManager.handleEventById(
36 EVENT_IDS.RESUME_TIMER,
37 null,
38 game,
39 null,
40 game.accessCode,
41 { timeRemaining: resumeTimeRemaining },
42 null,
43 false
44 );
45 await vars.gameManager.refreshGame(game);
46 await vars.eventManager.publisher.publish(
47 REDIS_CHANNELS.ACTIVE_GAME_STREAM,
48 vars.eventManager.createMessageToPublish(
49 game.accessCode,
50 EVENT_IDS.RESUME_TIMER,
51 vars.instanceId,
52 JSON.stringify({ timeRemaining: resumeTimeRemaining })
53 )
54 );
55 }
56 break;
57 case GAME_PROCESS_COMMANDS.GET_TIME_REMAINING:
58 if (game.timerParams && game.timerParams.ended) {
59 const socket = vars.gameManager.namespace.sockets.get(socketId);
60 if (socket) {
61 vars.gameManager.namespace.to(socket.id).emit(
62 GAME_PROCESS_COMMANDS.GET_TIME_REMAINING,

Callers 1

Events.jsFile · 0.85

Calls 1

resumeTimerMethod · 0.80

Tested by

no test coverage detected