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

119 lines
2.9 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 Users from '/imports/api/users';
2018-03-22 22:14:54 +08:00
import Meetings from '/imports/api/meetings/';
import Auth from '/imports/ui/services/auth';
2017-09-01 23:26:57 +08:00
class VideoService {
constructor() {
this.defineProperties({
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() {
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.isWaitingResponse = false;
this.isConnected = false;
}
sendUserShareWebcam(stream) {
makeCall('userShareWebcam', stream);
}
sendUserUnshareWebcam(stream) {
this.isWaitingResponse = true;
makeCall('userUnshareWebcam', stream);
}
getAllUsers() {
return Users.find().fetch();
}
2018-03-22 22:14:54 +08:00
webcamOnlyModerator() {
const m = Meetings.findOne({meetingId: Auth.meetingID});
return m.usersProp.webcamsOnlyForModerator;
}
isLocked() {
const m = Meetings.findOne({meetingId: Auth.meetingID});
return m.lockSettingsProp ? m.lockSettingsProp.disableCam : false;
}
userId() {
return Auth.userID;
}
meetingId() {
return Auth.meetingID;
}
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(),
getAllUsers: () => videoService.getAllUsers(),
2018-03-22 22:14:54 +08:00
webcamOnlyModerator: () => videoService.webcamOnlyModerator(),
isLocked: () => videoService.isLocked(),
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),
userId: () => videoService.userId(),
meetingId: () => videoService.meetingId(),
2017-09-01 23:26:57 +08:00
};