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';
|
2021-04-09 10:58:13 +08:00
|
|
|
import VoiceUsers from '/imports/api/voice-users/';
|
2021-11-29 21:44:14 +08:00
|
|
|
import Users from '/imports/api/users/';
|
2021-04-09 10:58:13 +08:00
|
|
|
|
|
|
|
const BASE_FLOOR_TIME = "0";
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2019-09-06 02:29:30 +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);
|
2021-05-03 20:49:33 +08:00
|
|
|
const name = getUserName(userId, meetingId);
|
2021-04-09 10:58:13 +08:00
|
|
|
const vu = VoiceUsers.findOne(
|
|
|
|
{ meetingId, intId: userId },
|
|
|
|
{ fields: { floor: 1, lastFloorTime: 1 }}
|
|
|
|
) || {};
|
2021-11-29 21:44:14 +08:00
|
|
|
const u = Users.findOne(
|
|
|
|
{ meetingId, intId: userId },
|
|
|
|
{ fields: { pin: 1 } },
|
|
|
|
) || {};
|
2021-04-09 10:58:13 +08:00
|
|
|
const floor = vu.floor || false;
|
2021-11-29 21:44:14 +08:00
|
|
|
const pin = u.pin || false;
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
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: {
|
2019-09-06 02:29:30 +08:00
|
|
|
stream,
|
2019-11-27 04:31:41 +08:00
|
|
|
name,
|
2021-04-09 10:58:13 +08:00
|
|
|
lastFloorTime,
|
|
|
|
floor,
|
2021-11-29 21:44:14 +08:00
|
|
|
pin,
|
2017-09-01 23:26:57 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
|
|
|
const { insertedId } = VideoStreams.upsert(selector, modifier);
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
if (insertedId) {
|
|
|
|
Logger.info(`Updated stream=${stream} meeting=${meetingId}`);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Error setting stream: ${err}`);
|
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|