bigbluebutton-Github/bigbluebutton-html5/imports/api/timer/server/modifiers/addTimer.js

43 lines
955 B
JavaScript
Raw Normal View History

2023-05-11 04:03:20 +08:00
import { check } from 'meteor/check';
import Timer from '/imports/api/timer';
import Logger from '/imports/startup/server/logger';
import { TRACKS, getDefaultTime } from '/imports/api/timer/server/helpers';
2023-05-11 04:03:20 +08:00
2020-04-26 03:03:35 +08:00
// This method should only be used by the server
2023-05-11 04:03:20 +08:00
export default function addTimer(meetingId) {
check(meetingId, String);
const selector = {
meetingId,
};
2020-04-26 03:03:35 +08:00
const time = getDefaultTime();
check(time, Number);
2023-05-11 04:03:20 +08:00
const modifier = {
meetingId,
stopwatch: true,
active: false,
running: false,
2020-04-26 03:03:35 +08:00
time,
2023-05-11 04:03:20 +08:00
accumulated: 0,
timestamp: 0,
track: TRACKS[0],
ended: 0,
2023-05-11 04:03:20 +08:00
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Adding timer to the collection: ${err}`);
}
if (numChanged) {
2020-04-27 01:44:01 +08:00
return Logger.debug(`Added timer meeting=${meetingId}`);
2023-05-11 04:03:20 +08:00
}
2020-04-27 01:44:01 +08:00
return Logger.debug(`Upserted timer meeting=${meetingId}`);
2023-05-11 04:03:20 +08:00
};
return Timer.upsert(selector, modifier, cb);
}