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

59 lines
1.3 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/';
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,
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
}