2023-05-11 04:03:20 +08:00
|
|
|
import { check } from 'meteor/check';
|
2023-05-03 04:46:33 +08:00
|
|
|
import Timer from '/imports/api/timer';
|
|
|
|
import { getInitialState, isEnabled } from '/imports/api/timer/server/helpers';
|
2023-05-11 04:03:20 +08:00
|
|
|
import addTimer from '/imports/api/timer/server/modifiers/addTimer';
|
2023-05-03 04:46:33 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
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 createTimer(meetingId) {
|
|
|
|
check(meetingId, String);
|
|
|
|
|
|
|
|
// Avoid timer creation if this feature is disabled
|
|
|
|
if (!isEnabled()) {
|
|
|
|
Logger.warn(`Timers are disabled for ${meetingId}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-03 04:46:33 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'CreateTimerPubMsg';
|
|
|
|
|
|
|
|
try {
|
|
|
|
addTimer(meetingId);
|
|
|
|
const payload = getInitialState();
|
|
|
|
|
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, 'nodeJsApp', payload);
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Activating timer: ${err}`);
|
|
|
|
}
|
2023-05-11 04:03:20 +08:00
|
|
|
}
|