2022-02-02 03:05:02 +08:00
|
|
|
import { check } from 'meteor/check';
|
2023-05-03 04:46:33 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2022-02-02 03:05:02 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
|
|
|
import { isTrackValid } from '/imports/api/timer/server/helpers';
|
|
|
|
|
|
|
|
export default function setTrack(track) {
|
2023-05-03 04:46:33 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'SetTrackReqMsg';
|
2022-02-02 03:05:02 +08:00
|
|
|
|
2023-05-03 04:46:33 +08:00
|
|
|
try {
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(track, String);
|
|
|
|
|
|
|
|
if (isTrackValid(track)) {
|
|
|
|
const payload = {
|
2023-06-09 03:24:25 +08:00
|
|
|
track,
|
2023-05-03 04:46:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
} else {
|
|
|
|
Logger.warn(`User=${requesterUserId} tried to set invalid track '${track}' in meeting=${meetingId}`);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Setting track: ${err}`);
|
2022-02-02 03:05:02 +08:00
|
|
|
}
|
|
|
|
}
|