2018-11-30 01:24:02 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-09-05 00:49:01 +08:00
|
|
|
import Users from '/imports/api/users';
|
2019-01-16 21:14:32 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
export default function startWatchingExternalVideo(options) {
|
2019-01-16 21:14:32 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
2020-08-28 18:58:55 +08:00
|
|
|
const EVENT_NAME = 'StartExternalVideoPubMsg';
|
2019-01-16 21:14:32 +08:00
|
|
|
|
2020-09-05 00:49:01 +08:00
|
|
|
const { meetingId, requesterUserId: userId } = extractCredentials(this.userId);
|
2018-11-30 01:24:02 +08:00
|
|
|
const { externalVideoUrl } = options;
|
|
|
|
|
2020-09-04 03:07:54 +08:00
|
|
|
try {
|
|
|
|
check(meetingId, String);
|
2020-09-05 00:49:01 +08:00
|
|
|
check(userId, String);
|
2020-09-04 03:07:54 +08:00
|
|
|
check(externalVideoUrl, String);
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2021-02-21 19:04:39 +08:00
|
|
|
const user = Users.findOne({ meetingId, userId }, { presenter: 1 });
|
2020-09-05 00:49:01 +08:00
|
|
|
|
2021-02-21 19:04:39 +08:00
|
|
|
if (user && user.presenter) {
|
|
|
|
check(externalVideoUrl, String);
|
|
|
|
const payload = { externalVideoUrl };
|
|
|
|
Logger.debug(`User id=${userId} sending ${EVENT_NAME} url:${externalVideoUrl} for meeting ${meetingId}`);
|
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, userId, payload);
|
2020-09-05 00:49:01 +08:00
|
|
|
}
|
2021-02-21 19:04:39 +08:00
|
|
|
Logger.error(`Only presenters are allowed to start external video for a meeting. meeting=${meetingId} userId=${userId}`);
|
2020-09-04 03:07:54 +08:00
|
|
|
} catch (error) {
|
|
|
|
Logger.error(`Error on sharing an external video: ${externalVideoUrl} ${error}`);
|
|
|
|
}
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|