bigbluebutton-Github/bigbluebutton-html5/imports/api/video-streams/server/modifiers/sharedWebcam.js

104 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-09-01 23:26:57 +08:00
import Logger from '/imports/startup/server/logger';
2019-09-07 00:50:31 +08:00
import VideoStreams from '/imports/api/video-streams';
2019-06-13 02:03:23 +08:00
import { check } from 'meteor/check';
2019-11-27 04:31:41 +08:00
import {
getDeviceId,
getUserName,
} from '/imports/api/video-streams/server/helpers';
import VoiceUsers from '/imports/api/voice-users/';
import Users from '/imports/api/users/';
2022-12-14 02:00:13 +08:00
import { lowercaseTrim } from '/imports/utils/string-utils';
const BASE_FLOOR_TIME = "0";
2017-09-01 23:26:57 +08:00
export default function sharedWebcam(meetingId, userId, stream) {
2017-09-01 23:26:57 +08:00
check(meetingId, String);
check(userId, String);
2019-11-23 05:08:27 +08:00
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;
2017-09-01 23:26:57 +08:00
const selector = {
meetingId,
userId,
2019-11-23 05:08:27 +08:00
deviceId,
2017-09-01 23:26:57 +08:00
};
const modifier = {
$set: {
stream,
2019-11-27 04:31:41 +08:00
name,
2022-12-14 02:00:13 +08:00
sortName: lowercaseTrim(name),
lastFloorTime,
floor,
pin,
2017-09-01 23:26:57 +08:00
},
};
try {
const { insertedId } = VideoStreams.upsert(selector, modifier);
2017-09-01 23:26:57 +08:00
if (insertedId) {
Logger.info(`Updated stream=${stream} meeting=${meetingId}`);
2017-09-01 23:26:57 +08:00
}
} catch (err) {
Logger.error(`Error setting stream: ${err}`);
}
2017-09-01 23:26:57 +08:00
}
export function addWebcamSync(meetingId, videoStream) {
check(videoStream, {
userId: String,
stream: String,
name: String,
pin: Boolean,
floor: Boolean,
lastFloorTime: String,
});
const {
stream, userId, name, pin, floor, lastFloorTime,
} = videoStream;
const deviceId = getDeviceId(stream);
const selector = {
meetingId,
userId,
deviceId,
};
const modifier = {
$set: {
stream,
name,
lastFloorTime,
floor,
pin,
},
};
try {
const { insertedId } = VideoStreams.upsert(selector, modifier);
if (insertedId) {
Logger.info(`Synced stream=${stream} meeting=${meetingId}`);
}
} catch (err) {
Logger.error(`Error setting sync stream: ${err}`);
}
}