stop external video if presenter changed

This commit is contained in:
Anton Georgiev 2021-02-21 12:19:01 +00:00
parent 0b6496618c
commit 740a3a9db9
7 changed files with 40 additions and 31 deletions

View File

@ -1,11 +1,9 @@
import { Meteor } from 'meteor/meteor';
import { makeCall } from '/imports/ui/services/api';
let streamer = null;
const getStreamer = (meetingID) => {
if (!streamer) {
streamer = new Meteor.Streamer(`external-videos-${meetingID}`);
makeCall('initializeExternalVideo');
}
return streamer;
};

View File

@ -1,6 +1,5 @@
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
export default function handleStopExternalVideo({ header, body }, meetingId) {
@ -9,10 +8,6 @@ export default function handleStopExternalVideo({ header, body }, meetingId) {
check(meetingId, String);
check(userId, String);
const user = Users.findOne({ meetingId: meetingId, userId: userId })
if (user && user.presenter) {
Logger.info(`User id=${userId} stop sharing an external video for meeting ${meetingId}`);
Meetings.update({ meetingId }, { $set: { externalVideoUrl: null } });
}
Logger.info(`External video stop sharing was initiated by:[${userId}] for meeting ${meetingId}`);
Meetings.update({ meetingId }, { $set: { externalVideoUrl: null } });
}

View File

@ -1,28 +1,21 @@
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
import RedisPubSub from '/imports/startup/server/redis';
import stopWatchingExternalVideoSystemCall from '/imports/api/external-videos/server/methods/stopWatchingExternalVideoSystemCall';
import { extractCredentials } from '/imports/api/common/server/helpers';
export default function stopWatchingExternalVideo(options) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'StopExternalVideoPubMsg';
// when we call stopWatchingExternalVideo as a Meteor method from client side we obtain
// user credentials from the connection via extractCredentials
// However, we also call this function from server side (end meeting, user left, etc)
const { meetingId, requesterUserId } = this.userId ? extractCredentials(this.userId) : options;
export default function stopWatchingExternalVideo() {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
try {
check(meetingId, String);
check(requesterUserId, String);
const user = Users.findOne({ meetingId, userId: requesterUserId });
if (user && user.presenter) {
const payload = { };
Logger.debug(`User id=${requesterUserId} sending ${EVENT_NAME} for meeting ${meetingId}`);
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
// proceed and publish the event
stopWatchingExternalVideoSystemCall({ meetingId, requesterUserId });
}
} catch (error) {
Logger.error(`Error on stop sharing an external video for meeting=${meetingId} ${error}`);

View File

@ -0,0 +1,26 @@
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Meetings from '/imports/api/meetings';
import RedisPubSub from '/imports/startup/server/redis';
export default function stopWatchingExternalVideoSystemCall({ meetingId, requesterUserId }) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'StopExternalVideoPubMsg';
try {
check(meetingId, String);
check(requesterUserId, String);
// check if there is ongoing video shared
const meeting = Meetings.findOne({ meetingId });
if (!meeting || meeting.externalVideoUrl === null) return;
Logger.info('ExternalVideo::stopWatchingExternalVideo was triggered ', { meetingId, requesterUserId });
const payload = { };
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
} catch (error) {
Logger.error(`Error on stop sharing an external video for meeting=${meetingId} ${error}`);
}
}

View File

@ -1,20 +1,17 @@
import { check } from 'meteor/check';
import Meetings from '/imports/api/meetings';
import Users from '/imports/api/users';
import addScreenshare from '../modifiers/addScreenshare';
import Logger from '/imports/startup/server/logger';
import stopWatchingExternalVideo from '/imports/api/external-videos/server/methods/stopWatchingExternalVideo';
import stopWatchingExternalVideoSystemCall from '/imports/api/external-videos/server/methods/stopWatchingExternalVideoSystemCall';
export default function handleScreenshareStarted({ body }, meetingId) {
check(meetingId, String);
check(body, Object);
const meeting = Meetings.findOne({ meetingId });
const presenter = Users.findOne({ meetingId, presenter: true });
const presenterId = presenter && presenter.userId ? presenter.userId : 'system-screenshare-starting';
if (meeting && meeting.externalVideoUrl) {
Logger.info(`ScreenshareStarted: There is external video being shared. Stopping it due to presenter change, ${meeting.externalVideoUrl}`);
stopWatchingExternalVideo({ meetingId, requesterUserId: presenterId });
stopWatchingExternalVideoSystemCall({ meetingId, requesterUserId: 'system-screenshare-starting' });
}
return addScreenshare(meetingId, body);
}

View File

@ -1,7 +1,7 @@
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
import stopWatchingExternalVideo from '/imports/api/external-videos/server/methods/stopWatchingExternalVideo';
import stopWatchingExternalVideoSystemCall from '/imports/api/external-videos/server/methods/stopWatchingExternalVideoSystemCall';
export default function changePresenter(presenter, userId, meetingId, changedBy) {
const selector = {
@ -19,7 +19,7 @@ export default function changePresenter(presenter, userId, meetingId, changedBy)
const meeting = Meetings.findOne({ meetingId });
if (meeting && meeting.externalVideoUrl) {
Logger.info(`ChangePresenter:There is external video being shared. Stopping it due to presenter change, ${meeting.externalVideoUrl}`);
stopWatchingExternalVideo({ meetingId, requesterUserId: userId });
stopWatchingExternalVideoSystemCall({ meetingId, requesterUserId: 'system-presenter-changed' });
}
const numberAffected = Users.update(selector, modifier);

View File

@ -2,7 +2,7 @@ import { check } from 'meteor/check';
import Users from '/imports/api/users';
import VideoStreams from '/imports/api/video-streams';
import Logger from '/imports/startup/server/logger';
import stopWatchingExternalVideo from '/imports/api/external-videos/server/methods/stopWatchingExternalVideo';
import stopWatchingExternalVideoSystemCall from '/imports/api/external-videos/server/methods/stopWatchingExternalVideoSystemCall';
import clearUserInfoForRequester from '/imports/api/users-infos/server/modifiers/clearUserInfoForRequester';
import ClientConnections from '/imports/startup/server/ClientConnections';
@ -22,7 +22,7 @@ export default function removeUser(meetingId, userId) {
if (userToRemove) {
const { presenter } = userToRemove;
if (presenter) {
stopWatchingExternalVideo({ meetingId, requesterUserId: userId });
stopWatchingExternalVideoSystemCall({ meetingId, requesterUserId: 'system-presenter-was-removed' });
}
}