Remove: Timer meteor server files

This commit is contained in:
Tainan Felipe 2024-04-25 14:19:05 -03:00
parent 946c440bc2
commit 773884af88
24 changed files with 0 additions and 578 deletions

View File

@ -9,7 +9,6 @@ import Meetings, {
} from '/imports/api/meetings';
import Logger from '/imports/startup/server/logger';
import { initPads } from '/imports/api/pads/server/helpers';
import createTimer from '/imports/api/timer/server/methods/createTimer';
import { LAYOUT_TYPE } from '/imports/ui/components/layout/enums';
const addLayout = async (meetingId, layout) => {
@ -217,7 +216,6 @@ export default async function addMeeting(meeting) {
if (insertedId) {
Logger.info(`Added meeting id=${meetingId}`);
// Init Timer collection
createTimer(meetingId);
if (newMeeting.meetingProp.disabledFeatures.indexOf('sharedNotes') === -1) {
initPads(meetingId);
}

View File

@ -4,7 +4,6 @@ import Logger from '/imports/startup/server/logger';
import clearUsers from '/imports/api/users/server/modifiers/clearUsers';
import clearPads from '/imports/api/pads/server/modifiers/clearPads';
import clearVoiceUsers from '/imports/api/voice-users/server/modifiers/clearVoiceUsers';
import clearTimer from '/imports/api/timer/server/modifiers/clearTimer';
import clearMeetingTimeRemaining from '/imports/api/meetings/server/modifiers/clearMeetingTimeRemaining';
import clearVideoStreams from '/imports/api/video-streams/server/modifiers/clearVideoStreams';
import Metrics from '/imports/startup/server/metrics';
@ -15,7 +14,6 @@ export default async function meetingHasEnded(meetingId) {
clearPads(meetingId),
clearUsers(meetingId),
clearVoiceUsers(meetingId),
clearTimer(meetingId),
clearMeetingTimeRemaining(meetingId),
clearVideoStreams(meetingId),
]);

View File

@ -1,20 +0,0 @@
import RedisPubSub from '/imports/startup/server/redis';
import handleTimerActivated from './handlers/timerActivated';
import handleTimerDeactivated from './handlers/timerDeactivated';
import handleTimerStarted from './handlers/timerStarted';
import handleTimerStopped from './handlers/timerStopped';
import handleTimerSwitched from './handlers/timerSwitched';
import handleTimerSet from './handlers/timerSet';
import handleTimerReset from './handlers/timerReset';
import handleTimerEnded from './handlers/timerEnded';
import handleTrackSet from './handlers/trackSet';
RedisPubSub.on('ActivateTimerRespMsg', handleTimerActivated);
RedisPubSub.on('DeactivateTimerRespMsg', handleTimerDeactivated);
RedisPubSub.on('StartTimerRespMsg', handleTimerStarted);
RedisPubSub.on('StopTimerRespMsg', handleTimerStopped);
RedisPubSub.on('SwitchTimerRespMsg', handleTimerSwitched);
RedisPubSub.on('SetTimerRespMsg', handleTimerSet);
RedisPubSub.on('ResetTimerRespMsg', handleTimerReset);
RedisPubSub.on('TimerEndedEvtMsg', handleTimerEnded);
RedisPubSub.on('SetTrackRespMsg', handleTrackSet);

View File

@ -1,14 +0,0 @@
import { check } from 'meteor/check';
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
export default function handleTimerActivated({ body }, meetingId) {
const { userId } = body;
check(meetingId, String);
check(userId, String);
updateTimer({
action: 'activate',
meetingId,
requesterUserId: userId,
});
}

View File

@ -1,14 +0,0 @@
import { check } from 'meteor/check';
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
export default function handleTimerDeactivated({ body }, meetingId) {
const { userId } = body;
check(meetingId, String);
check(userId, String);
updateTimer({
action: 'deactivate',
meetingId,
requesterUserId: userId,
});
}

View File

@ -1,13 +0,0 @@
import { check } from 'meteor/check';
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
export default function handleTimerEnded({ body }, meetingId) {
check(meetingId, String);
check(body, Object);
updateTimer({
action: 'reset',
meetingId,
requesterUserId: 'nodeJSapp',
});
}

View File

@ -1,14 +0,0 @@
import { check } from 'meteor/check';
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
export default function handleTimerReset({ body }, meetingId) {
const { userId } = body;
check(meetingId, String);
check(userId, String);
updateTimer({
action: 'reset',
meetingId,
requesterUserId: userId,
});
}

View File

@ -1,17 +0,0 @@
import { check } from 'meteor/check';
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
export default function handleTimerSet({ body }, meetingId) {
const { userId, time } = body;
check(meetingId, String);
check(userId, String);
check(time, Number);
updateTimer({
action: 'set',
meetingId,
requesterUserId: userId,
time,
});
}

View File

@ -1,14 +0,0 @@
import { check } from 'meteor/check';
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
export default function handleTimerStarted({ body }, meetingId) {
const { userId } = body;
check(meetingId, String);
check(userId, String);
updateTimer({
action: 'start',
meetingId,
requesterUserId: userId,
});
}

View File

@ -1,17 +0,0 @@
import { check } from 'meteor/check';
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
export default function handleTimerStopped({ body }, meetingId) {
const { userId, accumulated } = body;
check(meetingId, String);
check(userId, String);
check(accumulated, Number);
updateTimer({
action: 'stop',
meetingId,
requesterUserId: userId,
accumulated,
});
}

View File

@ -1,17 +0,0 @@
import { check } from 'meteor/check';
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
export default function handleTimerSwitched({ body }, meetingId) {
const { userId, stopwatch } = body;
check(meetingId, String);
check(userId, String);
check(stopwatch, Boolean);
updateTimer({
action: 'switch',
meetingId,
requesterUserId: userId,
stopwatch,
});
}

View File

@ -1,18 +0,0 @@
import { check } from 'meteor/check';
import updateTimer from '/imports/api/timer/server/modifiers/updateTimer';
export default function handleTrackSet({ body }, meetingId) {
const { userId, track } = body;
check(meetingId, String);
check(userId, String);
check(track, String);
updateTimer({
action: 'track',
meetingId,
requesterUserId: userId,
stopwatch: false,
track,
});
}

View File

@ -1,40 +0,0 @@
import { Meteor } from 'meteor/meteor';
const TIMER_CONFIG = Meteor.settings.public.timer;
const MILLI_IN_MINUTE = 60000;
const TRACKS = [
'noTrack',
'track1',
'track2',
'track3',
];
const isEnabled = () => TIMER_CONFIG.enabled;
const getDefaultTime = () => TIMER_CONFIG.time * MILLI_IN_MINUTE;
const getInitialState = () => {
const time = getDefaultTime();
check(time, Number);
return {
stopwatch: true,
running: false,
time,
accumulated: 0,
timestamp: 0,
track: TRACKS[0],
};
};
const isTrackValid = (track) => TRACKS.includes(track);
export {
TRACKS,
isEnabled,
getDefaultTime,
getInitialState,
isTrackValid,
};

View File

@ -1,2 +0,0 @@
import './methods';
import './eventHandlers';

View File

@ -1,8 +0,0 @@
import { Meteor } from 'meteor/meteor';
import getServerTime from './methods/getServerTime';
import timerEnded from './methods/endTimer';
Meteor.methods({
getServerTime,
timerEnded,
});

View File

@ -1,29 +0,0 @@
import { check } from 'meteor/check';
import { getInitialState, isEnabled } from '/imports/api/timer/server/helpers';
import addTimer from '/imports/api/timer/server/modifiers/addTimer';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';
// This method should only be used by the server
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;
}
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}`);
}
}

View File

@ -1,33 +0,0 @@
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis';
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 timerEnded() {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
check(meetingId, String);
check(requesterUserId, String);
updateTimer({
action: 'ended',
meetingId,
requesterUserId,
});
}
// This method should only be used by the server
export function sysEndTimer(meetingId) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'TimerEndedPubMsg';
const USER_ID = 'nodeJSapp';
try {
check(meetingId, String);
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, USER_ID, {});
} catch (err) {
Logger.error(`Ending timer: ${err}`);
}
}

View File

@ -1,5 +0,0 @@
export default function getServerTime() {
if (this.userId) return Date.now();
return 0;
}

View File

@ -1,34 +0,0 @@
import { check } from 'meteor/check';
import Timer from '/imports/api/timer';
import Logger from '/imports/startup/server/logger';
import { getInitialState } from '/imports/api/timer/server/helpers';
// This method should only be used by the server
export default function addTimer(meetingId) {
check(meetingId, String);
const selector = {
meetingId,
};
const modifier = {
meetingId,
...getInitialState(),
active: false,
ended: 0,
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Adding timer to the collection: ${err}`);
}
if (numChanged) {
return Logger.debug(`Added timer meeting=${meetingId}`);
}
return Logger.debug(`Upserted timer meeting=${meetingId}`);
};
return Timer.upsert(selector, modifier, cb);
}

View File

@ -1,14 +0,0 @@
import Timer from '/imports/api/timer';
import Logger from '/imports/startup/server/logger';
export default function clearTimer(meetingId) {
if (meetingId) {
return Timer.remove({ meetingId }, () => {
Logger.info(`Cleared Timer (${meetingId})`);
});
}
return Timer.remove({}, () => {
Logger.info('Cleared Timer (all)');
});
}

View File

@ -1,18 +0,0 @@
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';
export default function endTimer(meetingId) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'TimerEndedPubMsg';
const USER_ID = 'nodeJSapp';
try {
check(meetingId, String);
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, USER_ID, {});
} catch (err) {
Logger.error(`Ending timer: ${err}`);
}
}

View File

@ -1,46 +0,0 @@
import { check } from 'meteor/check';
import Timer from '/imports/api/timer';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';
export default function stopTimer(meetingId) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'StopTimerReqMsg';
const USER_ID = 'nodeJSapp';
try {
check(meetingId, String);
const now = Date.now();
const timer = Timer.findOne(
{ meetingId },
{
fields:
{
stopwatch: 1,
time: 1,
accumulated: 1,
timestamp: 1,
},
},
);
if (timer) {
const {
timestamp,
} = timer;
const accumulated = timer.accumulated + (now - timestamp);
const payload = {
accumulated,
};
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, USER_ID, payload);
} else {
Logger.warn(`Could not stop timer for meeting=${meetingId}, timer not found`);
}
} catch (err) {
Logger.error(`Stopping timer: ${err}`);
}
}

View File

@ -1,186 +0,0 @@
import { check } from 'meteor/check';
import Timer from '/imports/api/timer';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
import { TRACKS, getInitialState } from '/imports/api/timer/server/helpers';
import { sysEndTimer } from '../methods/endTimer';
const getActivateModifier = () => ({
$set: {
active: true,
...getInitialState(),
ended: 0,
},
});
const getDeactivateModifier = () => ({
$set: {
active: false,
running: false,
ended: 0,
},
});
const getResetModifier = () => ({
$set: {
accumulated: 0,
timestamp: Date.now(),
ended: 0,
},
});
const handleTimerEndedNotifications = (fields, meetingId, handle) => {
const meetingUsers = Users.find({ meetingId }).count();
if (fields.running === false) {
handle.stop();
}
if (fields.ended >= meetingUsers) {
sysEndTimer(meetingId);
}
};
const setTimerEndObserver = (meetingId) => {
const { stopwatch } = Timer.findOne({ meetingId });
if (stopwatch === false) {
const meetingTimer = Timer.find(
{ meetingId },
{ fields: { ended: 1, running: 1 } },
);
const handle = meetingTimer.observeChanges({
changed: (id, fields) => {
handleTimerEndedNotifications(fields, meetingId, handle);
},
});
}
};
const getStartModifier = () => ({
$set: {
running: true,
timestamp: Date.now(),
ended: 0,
},
});
const getStopModifier = (accumulated) => ({
$set: {
running: false,
accumulated,
timestamp: 0,
ended: 0,
},
});
const getSwitchModifier = (stopwatch) => ({
$set: {
stopwatch,
running: false,
accumulated: 0,
timestamp: 0,
track: TRACKS[0],
ended: 0,
},
});
const getSetModifier = (time) => ({
$set: {
running: false,
accumulated: 0,
timestamp: 0,
time,
},
});
const getTrackModifier = (track) => ({
$set: {
track,
},
});
const getEndedModifier = () => ({
$inc: {
ended: 1,
},
});
const logTimer = (meetingId, requesterUserId, action, stopwatch, time, track) => {
if (action === 'switch') {
Logger.info(`Timer: meetingId=${meetingId} requesterUserId=${requesterUserId} action=${action} stopwatch=${stopwatch} `);
} else if (action === 'set' && time !== 0) {
Logger.info(`Timer: meetingId=${meetingId} requesterUserId=${requesterUserId} action=${action} ${time}ms`);
} else if (action === 'track') {
Logger.info(`Timer: meetingId=${meetingId} requesterUserId=${requesterUserId} action=${action} changed to ${track}`);
} else {
Logger.info(`Timer: meetingId=${meetingId} requesterUserId=${requesterUserId} action=${action}`);
}
};
export default function updateTimer({
action,
meetingId,
requesterUserId,
time = 0,
stopwatch = true,
accumulated = 0,
track = TRACKS[0],
}) {
check(action, String);
check(meetingId, String);
check(requesterUserId, String);
check(time, Number);
check(stopwatch, Boolean);
check(accumulated, Number);
check(track, String);
const selector = {
meetingId,
};
let modifier;
switch (action) {
case 'activate':
modifier = getActivateModifier();
break;
case 'deactivate':
modifier = getDeactivateModifier();
break;
case 'reset':
modifier = getResetModifier();
break;
case 'start':
setTimerEndObserver(meetingId);
modifier = getStartModifier();
break;
case 'stop':
modifier = getStopModifier(accumulated);
break;
case 'switch':
modifier = getSwitchModifier(stopwatch);
break;
case 'set':
modifier = getSetModifier(time);
break;
case 'track':
modifier = getTrackModifier(track);
break;
case 'ended':
modifier = getEndedModifier();
break;
default:
Logger.error(`Unhandled timer action=${action}`);
}
try {
const { numberAffected } = Timer.upsert(selector, modifier);
if (numberAffected) {
logTimer(meetingId, requesterUserId, action, stopwatch, time, track);
}
} catch (err) {
Logger.error(`Updating timer: ${err}`);
}
}

View File

@ -5,7 +5,6 @@ import '/imports/api/meetings/server';
import '/imports/api/users/server';
import '/imports/api/voice-users/server';
import '/imports/api/video-streams/server';
import '/imports/api/timer/server';
import '/imports/api/pads/server';
// Commons