bigbluebutton-Github/bigbluebutton-html5/imports/api/video-streams/server/modifiers/sharedWebcam.js
Max Franke 85ad9a5e30 feat(video): webcam video pinning server side logic
Add the new ChangeUserPinState messages to handle the new video pinning
functionality
2021-12-21 16:58:38 -03:00

59 lines
1.3 KiB
JavaScript

import Logger from '/imports/startup/server/logger';
import VideoStreams from '/imports/api/video-streams';
import { check } from 'meteor/check';
import {
getDeviceId,
getUserName,
} from '/imports/api/video-streams/server/helpers';
import VoiceUsers from '/imports/api/voice-users/';
import Users from '/imports/api/users/';
const BASE_FLOOR_TIME = "0";
export default function sharedWebcam(meetingId, userId, stream) {
check(meetingId, String);
check(userId, String);
check(stream, String);
const deviceId = getDeviceId(stream);
const name = getUserName(userId, meetingId);
const vu = VoiceUsers.findOne(
{ meetingId, intId: userId },
{ fields: { floor: 1, lastFloorTime: 1 }}
) || {};
const u = Users.findOne(
{ meetingId, intId: userId },
{ fields: { pin: 1 } },
) || {};
const floor = vu.floor || false;
const pin = u.pin || false;
const lastFloorTime = vu.lastFloorTime || BASE_FLOOR_TIME;
const selector = {
meetingId,
userId,
deviceId,
};
const modifier = {
$set: {
stream,
name,
lastFloorTime,
floor,
pin,
},
};
try {
const { insertedId } = VideoStreams.upsert(selector, modifier);
if (insertedId) {
Logger.info(`Updated stream=${stream} meeting=${meetingId}`);
}
} catch (err) {
Logger.error(`Error setting stream: ${err}`);
}
}