bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/video-provider/service.js

179 lines
4.8 KiB
JavaScript
Raw Normal View History

import { Tracker } from 'meteor/tracker';
2017-09-19 21:53:27 +08:00
import { makeCall } from '/imports/ui/services/api';
import Auth from '/imports/ui/services/auth';
2018-04-10 02:28:54 +08:00
import Meetings from '/imports/api/meetings/';
import Users from '/imports/api/users/';
2018-04-09 22:39:27 +08:00
import UserListService from '/imports/ui/components/user-list/service';
2017-09-01 23:26:57 +08:00
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
const ROLE_VIEWER = Meteor.settings.public.user.role_viewer;
class VideoService {
constructor() {
this.defineProperties({
isSharing: false,
isConnected: false,
isWaitingResponse: false,
});
}
2017-09-20 11:12:10 +08:00
defineProperties(obj) {
Object.keys(obj).forEach((key) => {
const privateKey = `_${key}`;
this[privateKey] = {
value: obj[key],
tracker: new Tracker.Dependency(),
};
2017-09-20 11:12:10 +08:00
Object.defineProperty(this, key, {
set: (value) => {
this[privateKey].value = value;
this[privateKey].tracker.changed();
},
get: () => {
this[privateKey].tracker.depend();
return this[privateKey].value;
},
});
});
}
2017-09-01 23:26:57 +08:00
joinVideo() {
this.isSharing = true;
const joinVideoEvent = new Event('joinVideo');
document.dispatchEvent(joinVideoEvent);
}
joiningVideo() {
this.isWaitingResponse = true;
}
joinedVideo() {
this.isWaitingResponse = false;
this.isConnected = true;
}
exitVideo() {
const exitVideoEvent = new Event('exitVideo');
document.dispatchEvent(exitVideoEvent);
}
exitedVideo() {
this.isSharing = false;
this.isWaitingResponse = false;
this.isConnected = false;
}
sendUserShareWebcam(stream) {
makeCall('userShareWebcam', stream);
}
sendUserUnshareWebcam(stream) {
makeCall('userUnshareWebcam', stream);
}
getAllWebcamUsers() {
const webcamsLocked = this.webcamsLocked();
const webcamsOnlyForModerator = this.webcamsOnlyForModerator();
const hideUserList = this.hideUserList();
const currentUser = Users.findOne({ userId: Auth.userID });
const currentUserIsViewer = currentUser.role === ROLE_VIEWER;
const sharedWebcam = this.isSharing;
2018-04-10 02:28:54 +08:00
let users = Users
.find({
meetingId: Auth.meetingID,
connectionStatus: 'online',
hasStream: true,
userId: { $ne: Auth.userID },
})
.fetch();
const userIsNotLocked = user => user.role === ROLE_MODERATOR || !user.locked;
if (webcamsLocked) {
users = users.filter(userIsNotLocked);
}
const userIsModerator = user => user.role === ROLE_MODERATOR;
if ((webcamsOnlyForModerator || hideUserList) && currentUserIsViewer) {
users = users.filter(userIsModerator);
}
2018-04-10 02:28:54 +08:00
if (sharedWebcam) {
users.unshift(currentUser);
}
2018-04-10 02:28:54 +08:00
return users.sort(UserListService.sortUsers);
2018-04-10 02:28:54 +08:00
}
webcamsOnlyForModerator() {
2018-12-15 06:33:52 +08:00
const m = Meetings.findOne({ meetingId: Auth.meetingID }) || {};
return m.usersProp ? m.usersProp.webcamsOnlyForModerator : false;
2018-03-22 22:14:54 +08:00
}
webcamsLocked() {
const m = Meetings.findOne({ meetingId: Auth.meetingID }) || {};
return m.lockSettingsProps ? m.lockSettingsProps.disableCam : false;
2018-03-22 22:14:54 +08:00
}
hideUserList() {
const m = Meetings.findOne({ meetingId: Auth.meetingID }) || {};
return m.lockSettingsProps ? m.lockSettingsProps.hideUserList : false;
}
userId() {
return Auth.userID;
}
userName() {
const currentUser = Users.findOne({ userId: Auth.userID });
return currentUser.name;
}
meetingId() {
return Auth.meetingID;
}
sessionToken() {
return Auth.sessionToken;
}
voiceBridge() {
2018-12-15 06:33:52 +08:00
const m = Meetings.findOne({ meetingId: Auth.meetingID }) || {};
return m.voiceProp ? m.voiceProp.voiceConf : null;
}
isConnected() {
return this.isConnected;
}
2017-09-01 23:26:57 +08:00
isWaitingResponse() {
return this.isWaitingResponse;
}
}
const videoService = new VideoService();
2017-09-01 23:26:57 +08:00
export default {
exitVideo: () => videoService.exitVideo(),
exitingVideo: () => videoService.exitingVideo(),
exitedVideo: () => videoService.exitedVideo(),
webcamsLocked: () => videoService.webcamsLocked(),
2018-03-22 22:14:54 +08:00
webcamOnlyModerator: () => videoService.webcamOnlyModerator(),
2018-04-24 23:51:41 +08:00
isSharing: () => videoService.isSharing,
isConnected: () => videoService.isConnected,
isWaitingResponse: () => videoService.isWaitingResponse,
joinVideo: () => videoService.joinVideo(),
joiningVideo: () => videoService.joiningVideo(),
joinedVideo: () => videoService.joinedVideo(),
sendUserShareWebcam: stream => videoService.sendUserShareWebcam(stream),
sendUserUnshareWebcam: stream => videoService.sendUserUnshareWebcam(stream),
userName: () => videoService.userName(),
meetingId: () => videoService.meetingId(),
getAllWebcamUsers: () => videoService.getAllWebcamUsers(),
sessionToken: () => videoService.sessionToken(),
voiceBridge: () => videoService.voiceBridge(),
2017-09-01 23:26:57 +08:00
};