2018-01-11 09:15:44 +08:00
|
|
|
import { Tracker } from 'meteor/tracker';
|
2017-09-19 21:53:27 +08:00
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
2018-01-13 02:39:16 +08:00
|
|
|
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/';
|
2019-09-06 02:29:30 +08:00
|
|
|
import VideoUsers from '/imports/api/video-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
|
|
|
|
2019-08-10 06:28:49 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|
|
|
const ROLE_VIEWER = Meteor.settings.public.user.role_viewer;
|
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
class VideoService {
|
|
|
|
constructor() {
|
|
|
|
this.defineProperties({
|
2018-04-25 22:23:44 +08:00
|
|
|
isSharing: false,
|
2018-01-11 09:15:44 +08:00
|
|
|
isConnected: false,
|
|
|
|
isWaitingResponse: false,
|
|
|
|
});
|
|
|
|
}
|
2017-09-20 11:12:10 +08:00
|
|
|
|
2018-01-11 09:15:44 +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
|
|
|
|
2018-01-11 09:15:44 +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
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
joinVideo() {
|
2018-04-12 02:50:14 +08:00
|
|
|
this.isSharing = true;
|
2018-03-20 01:52:39 +08:00
|
|
|
const joinVideoEvent = new Event('joinVideo');
|
2018-01-11 09:15:44 +08:00
|
|
|
document.dispatchEvent(joinVideoEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
joiningVideo() {
|
|
|
|
this.isWaitingResponse = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
joinedVideo() {
|
|
|
|
this.isWaitingResponse = false;
|
|
|
|
this.isConnected = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
exitVideo() {
|
2018-03-20 01:52:39 +08:00
|
|
|
const exitVideoEvent = new Event('exitVideo');
|
2018-01-11 09:15:44 +08:00
|
|
|
document.dispatchEvent(exitVideoEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
exitedVideo() {
|
2018-04-19 02:16:26 +08:00
|
|
|
this.isSharing = false;
|
2018-01-11 09:15:44 +08:00
|
|
|
this.isWaitingResponse = false;
|
|
|
|
this.isConnected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendUserShareWebcam(stream) {
|
|
|
|
makeCall('userShareWebcam', stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendUserUnshareWebcam(stream) {
|
|
|
|
makeCall('userUnshareWebcam', stream);
|
|
|
|
}
|
|
|
|
|
2019-08-10 06:28:49 +08:00
|
|
|
getAllWebcamUsers() {
|
|
|
|
const webcamsLocked = this.webcamsLocked();
|
|
|
|
const webcamsOnlyForModerator = this.webcamsOnlyForModerator();
|
2019-08-10 07:45:26 +08:00
|
|
|
const hideUserList = this.hideUserList();
|
2019-08-10 06:28:49 +08:00
|
|
|
const currentUser = Users.findOne({ userId: Auth.userID });
|
|
|
|
const currentUserIsViewer = currentUser.role === ROLE_VIEWER;
|
2018-04-12 02:50:14 +08:00
|
|
|
const sharedWebcam = this.isSharing;
|
2019-09-06 02:29:30 +08:00
|
|
|
const videoUsers = VideoUsers.find({ meetingId: Auth.meetingID, hasStream: true }).fetch();
|
|
|
|
|
|
|
|
const videoUserIds = videoUsers.map(u => u.userId);
|
2018-04-10 02:28:54 +08:00
|
|
|
|
2019-08-10 06:28:49 +08:00
|
|
|
let users = Users
|
|
|
|
.find({
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
connectionStatus: 'online',
|
2019-09-06 02:29:30 +08:00
|
|
|
$and: [
|
|
|
|
{ userId: { $ne: Auth.userID } },
|
|
|
|
{ userId: { $in: videoUserIds } },
|
|
|
|
],
|
2019-08-10 06:28:49 +08:00
|
|
|
})
|
|
|
|
.fetch();
|
|
|
|
|
|
|
|
const userIsNotLocked = user => user.role === ROLE_MODERATOR || !user.locked;
|
|
|
|
|
|
|
|
if (webcamsLocked) {
|
|
|
|
users = users.filter(userIsNotLocked);
|
|
|
|
}
|
|
|
|
|
|
|
|
const userIsModerator = user => user.role === ROLE_MODERATOR;
|
|
|
|
|
2019-08-10 07:45:26 +08:00
|
|
|
if ((webcamsOnlyForModerator || hideUserList) && currentUserIsViewer) {
|
2019-08-10 06:28:49 +08:00
|
|
|
users = users.filter(userIsModerator);
|
|
|
|
}
|
2018-04-10 02:28:54 +08:00
|
|
|
|
2019-08-10 06:28:49 +08:00
|
|
|
if (sharedWebcam) {
|
|
|
|
users.unshift(currentUser);
|
|
|
|
}
|
2018-04-10 02:28:54 +08:00
|
|
|
|
2019-08-10 06:28:49 +08:00
|
|
|
return users.sort(UserListService.sortUsers);
|
2018-04-10 02:28:54 +08:00
|
|
|
}
|
|
|
|
|
2019-08-10 06:28:49 +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
|
|
|
}
|
|
|
|
|
2019-08-10 06:28:49 +08:00
|
|
|
webcamsLocked() {
|
2018-12-07 06:41:09 +08:00
|
|
|
const m = Meetings.findOne({ meetingId: Auth.meetingID }) || {};
|
2019-04-04 01:23:31 +08:00
|
|
|
return m.lockSettingsProps ? m.lockSettingsProps.disableCam : false;
|
2018-03-22 22:14:54 +08:00
|
|
|
}
|
|
|
|
|
2019-08-10 07:45:26 +08:00
|
|
|
hideUserList() {
|
|
|
|
const m = Meetings.findOne({ meetingId: Auth.meetingID }) || {};
|
|
|
|
return m.lockSettingsProps ? m.lockSettingsProps.hideUserList : false;
|
|
|
|
}
|
|
|
|
|
2018-01-13 05:31:01 +08:00
|
|
|
userId() {
|
|
|
|
return Auth.userID;
|
|
|
|
}
|
|
|
|
|
2018-06-20 01:36:12 +08:00
|
|
|
userName() {
|
|
|
|
const currentUser = Users.findOne({ userId: Auth.userID });
|
|
|
|
return currentUser.name;
|
|
|
|
}
|
|
|
|
|
2018-03-20 01:52:39 +08:00
|
|
|
meetingId() {
|
|
|
|
return Auth.meetingID;
|
|
|
|
}
|
|
|
|
|
2018-07-10 05:29:27 +08:00
|
|
|
sessionToken() {
|
|
|
|
return Auth.sessionToken;
|
|
|
|
}
|
|
|
|
|
2018-08-27 15:37:25 +08:00
|
|
|
voiceBridge() {
|
2018-12-15 06:33:52 +08:00
|
|
|
const m = Meetings.findOne({ meetingId: Auth.meetingID }) || {};
|
|
|
|
return m.voiceProp ? m.voiceProp.voiceConf : null;
|
2018-08-27 15:37:25 +08:00
|
|
|
}
|
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
isConnected() {
|
|
|
|
return this.isConnected;
|
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
isWaitingResponse() {
|
|
|
|
return this.isWaitingResponse;
|
|
|
|
}
|
2017-12-09 00:38:51 +08:00
|
|
|
}
|
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
const videoService = new VideoService();
|
2018-01-13 02:39:16 +08:00
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
export default {
|
2018-01-11 09:15:44 +08:00
|
|
|
exitVideo: () => videoService.exitVideo(),
|
|
|
|
exitingVideo: () => videoService.exitingVideo(),
|
|
|
|
exitedVideo: () => videoService.exitedVideo(),
|
2019-08-10 06:28:49 +08:00
|
|
|
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,
|
2018-01-11 09:15:44 +08:00
|
|
|
isConnected: () => videoService.isConnected,
|
|
|
|
isWaitingResponse: () => videoService.isWaitingResponse,
|
|
|
|
joinVideo: () => videoService.joinVideo(),
|
|
|
|
joiningVideo: () => videoService.joiningVideo(),
|
|
|
|
joinedVideo: () => videoService.joinedVideo(),
|
2018-03-20 01:52:39 +08:00
|
|
|
sendUserShareWebcam: stream => videoService.sendUserShareWebcam(stream),
|
|
|
|
sendUserUnshareWebcam: stream => videoService.sendUserUnshareWebcam(stream),
|
2018-06-20 01:36:12 +08:00
|
|
|
userName: () => videoService.userName(),
|
2018-03-20 01:52:39 +08:00
|
|
|
meetingId: () => videoService.meetingId(),
|
2019-08-10 06:28:49 +08:00
|
|
|
getAllWebcamUsers: () => videoService.getAllWebcamUsers(),
|
2018-07-10 05:29:27 +08:00
|
|
|
sessionToken: () => videoService.sessionToken(),
|
2018-08-27 15:37:25 +08:00
|
|
|
voiceBridge: () => videoService.voiceBridge(),
|
2017-09-01 23:26:57 +08:00
|
|
|
};
|