Merge pull request #8888 from pedrobmarin/fix-mod-webcams

Fix webcamsOnlyForModerator
This commit is contained in:
Anton Georgiev 2020-06-30 16:19:15 -04:00 committed by GitHub
commit ec94b0f781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 18 deletions

View File

@ -234,6 +234,8 @@ class VideoPreview extends Component {
const webcams = [];
let initialDeviceId;
VideoService.updateNumberOfDevices(devices);
if (!this._isMounted) return;
// set webcam

View File

@ -19,6 +19,7 @@ const SKIP_VIDEO_PREVIEW = Meteor.settings.public.kurento.skipVideoPreview;
const SFU_URL = Meteor.settings.public.kurento.wsUrl;
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
const ROLE_VIEWER = Meteor.settings.public.user.role_viewer;
const ENABLE_NETWORK_MONITORING = Meteor.settings.public.networkMonitoring.enableNetworkMonitoring;
const TOKEN = '_';
@ -29,11 +30,8 @@ class VideoService {
isConnecting: false,
isConnected: false,
});
this.skipVideoPreview = getFromUserSettings('bbb_skip_video_preview', false) || SKIP_VIDEO_PREVIEW;
this.userParameterProfile = getFromUserSettings(
'bbb_preferred_camera_profile',
(CAMERA_PROFILES.filter(i => i.default) || {}).id,
);
this.skipVideoPreview = null;
this.userParameterProfile = null;
const BROWSER_RESULTS = browser();
this.isMobile = BROWSER_RESULTS.mobile || BROWSER_RESULTS.os.includes('Android');
this.isSafari = BROWSER_RESULTS.name === 'safari';
@ -72,16 +70,26 @@ class VideoService {
});
}
updateNumberOfDevices() {
navigator.mediaDevices.enumerateDevices().then((devices) => {
const deviceIds = [];
devices.forEach((d) => {
if (d.kind === 'videoinput' && !deviceIds.includes(d.deviceId)) {
deviceIds.push(d.deviceId);
}
});
this.numberOfDevices = deviceIds.length;
fetchNumberOfDevices(devices) {
const deviceIds = [];
devices.forEach(d => {
const validDeviceId = d.deviceId !== '' && !deviceIds.includes(d.deviceId)
if (d.kind === 'videoinput' && validDeviceId) {
deviceIds.push(d.deviceId);
}
});
return deviceIds.length;
}
updateNumberOfDevices(devices = null) {
if (devices) {
this.numberOfDevices = this.fetchNumberOfDevices(devices);
} else {
navigator.mediaDevices.enumerateDevices().then(devices => {
this.numberOfDevices = this.fetchNumberOfDevices(devices);
});
}
}
joinVideo(deviceId) {
@ -154,7 +162,7 @@ class VideoService {
}
getVideoStreams() {
const streams = VideoStreams.find(
let streams = VideoStreams.find(
{ meetingId: Auth.meetingID },
{
fields: {
@ -163,8 +171,11 @@ class VideoService {
},
).fetch();
const connectingStream = this.getConnectingStream(streams);
const hideUsers = this.hideUserList();
const moderatorOnly = this.webcamsOnlyForModerator();
if (hideUsers || moderatorOnly) streams = this.filterModeratorOnly(streams);
const connectingStream = this.getConnectingStream(streams);
if (connectingStream) streams.push(connectingStream);
return streams.map(vs => ({
@ -215,12 +226,46 @@ class VideoService {
return streams.find(s => s.stream === stream);
}
filterModeratorOnly(streams) {
const me = Users.findOne({ userId: Auth.userID });
const amIViewer = me.role === ROLE_VIEWER;
if (amIViewer) {
const moderators = Users.find(
{
meetingId: Auth.meetingID,
connectionStatus: 'online',
role: ROLE_MODERATOR,
},
{ fields: { userId: 1 } },
).fetch().map(user => user.userId);
return streams.reduce((result, stream) => {
const { userId } = stream;
const isModerator = moderators.includes(userId);
const isMe = me.userId === userId;
if (isModerator || isMe) result.push(stream);
return result;
}, []);
}
return streams;
}
disableCam() {
const m = Meetings.findOne({ meetingId: Auth.meetingID },
{ fields: { 'lockSettingsProps.disableCam': 1 } });
return m.lockSettingsProps ? m.lockSettingsProps.disableCam : false;
}
webcamsOnlyForModerator() {
const m = Meetings.findOne({ meetingId: Auth.meetingID },
{ fields: { 'usersProp.webcamsOnlyForModerator': 1 } });
return m.usersProp ? m.usersProp.webcamsOnlyForModerator : false;
}
hideUserList() {
const m = Meetings.findOne({ meetingId: Auth.meetingID },
{ fields: { 'lockSettingsProps.hideUserList': 1 } });
@ -329,11 +374,22 @@ class VideoService {
return isLocal ? 'share' : 'viewer';
}
getSkipVideoPreview(fromInterface) {
getSkipVideoPreview(fromInterface = false) {
if (this.skipVideoPreview === null) {
this.skipVideoPreview = getFromUserSettings('bbb_skip_video_preview', false) || SKIP_VIDEO_PREVIEW;
}
return this.skipVideoPreview && !fromInterface;
}
getUserParameterProfile() {
if (this.userParameterProfile === null) {
this.userParameterProfile = getFromUserSettings(
'bbb_preferred_camera_profile',
(CAMERA_PROFILES.filter(i => i.default) || {}).id,
);
}
return this.userParameterProfile;
}
@ -342,7 +398,7 @@ class VideoService {
// Mobile shouldn't be able to share more than one camera at the same time
// Safari needs to implement devicechange event for safe device control
return MULTIPLE_CAMERAS
&& !this.skipVideoPreview
&& !this.getSkipVideoPreview()
&& !this.isMobile
&& !this.isSafari
&& this.numberOfDevices > 1;
@ -380,4 +436,5 @@ export default {
monitor: conn => videoService.monitor(conn),
onBeforeUnload: () => videoService.onBeforeUnload(),
notify: message => notify(message, 'error', 'video'),
updateNumberOfDevices: devices => videoService.updateNumberOfDevices(devices),
};