bigbluebutton-Github/bigbluebutton-html5/imports/api/timer/server/methods/stopTimer.js
Pedro Beschorner Marin 5463a4a423 Stopwatch handlers
2023-05-18 15:29:31 -03:00

37 lines
912 B
JavaScript

import { check } from 'meteor/check';
import Timer from '/imports/api/timer';
import Logger from '/imports/startup/server/logger';
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
import { extractCredentials } from '/imports/api/common/server/helpers';
export default function stopTimer() {
const { meetingId } = extractCredentials(this.userId);
check(meetingId, String);
const now = Date.now();
const timer = Timer.findOne(
{ meetingId },
{ fields:
{
stopwatch: 1,
time: 1,
accumulated: 1,
timestamp: 1,
},
},
);
if (timer) {
const {
stopwatch,
time,
timestamp,
} = timer;
const accumulated = timer.accumulated + (now - timestamp);
updateTimer('stop', meetingId, time, stopwatch, accumulated);
} else {
Logger.warn(`Could not stop timer for meetingId=${meetingId}`);
}
}