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';
|
2017-12-09 00:38:51 +08:00
|
|
|
import Users from '/imports/api/users';
|
2018-01-13 02:39:16 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
class VideoService {
|
|
|
|
constructor() {
|
|
|
|
this.defineProperties({
|
|
|
|
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() {
|
|
|
|
var joinVideoEvent = new Event('joinVideo');
|
|
|
|
document.dispatchEvent(joinVideoEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
joiningVideo() {
|
|
|
|
this.isWaitingResponse = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
joinedVideo() {
|
|
|
|
this.isWaitingResponse = false;
|
|
|
|
this.isConnected = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
exitVideo() {
|
|
|
|
var exitVideoEvent = new Event('exitVideo');
|
|
|
|
document.dispatchEvent(exitVideoEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
exitingVideo() {
|
|
|
|
this.isWaitingResponse = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
exitedVideo() {
|
|
|
|
this.isWaitingResponse = false;
|
|
|
|
this.isConnected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
resetState() {
|
|
|
|
this.isWaitingResponse = false;
|
|
|
|
this.isConnected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendUserShareWebcam(stream) {
|
|
|
|
makeCall('userShareWebcam', stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendUserUnshareWebcam(stream) {
|
|
|
|
makeCall('userUnshareWebcam', stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllUsers() {
|
|
|
|
return Users.find().fetch();
|
|
|
|
}
|
|
|
|
|
2018-01-13 05:31:01 +08:00
|
|
|
userId() {
|
|
|
|
return Auth.userID;
|
|
|
|
}
|
|
|
|
|
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(),
|
|
|
|
getAllUsers: () => videoService.getAllUsers(),
|
|
|
|
isConnected: () => videoService.isConnected,
|
|
|
|
isWaitingResponse: () => videoService.isWaitingResponse,
|
|
|
|
joinVideo: () => videoService.joinVideo(),
|
|
|
|
joiningVideo: () => videoService.joiningVideo(),
|
|
|
|
joinedVideo: () => videoService.joinedVideo(),
|
|
|
|
resetState: () => videoService.resetState(),
|
2018-01-13 05:31:01 +08:00
|
|
|
sendUserShareWebcam: (stream) => videoService.sendUserShareWebcam(stream),
|
|
|
|
sendUserUnshareWebcam: (stream) => videoService.sendUserUnshareWebcam(stream),
|
|
|
|
userId: () => videoService.userId(),
|
2017-09-01 23:26:57 +08:00
|
|
|
};
|