bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/app/AppService.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

import { Meteor } from 'meteor/meteor'
import { Users } from '/imports/api/users/usersCollection';
2016-05-11 04:25:24 +08:00
import { Polls } from '/imports/api/polls/pollsCollection'; //TODO Anton join these, rename one?
2016-05-06 03:50:11 +08:00
let AppService = function () {
const setInStorage = function(key, value) {
if (!!value) {
console.log('in setInStorage', key, value);
localStorage.setItem(key, value);
}
};
const getInStorage = function(key) {
return localStorage.getItem(key);
};
const setCredentials = function (nextState, replace) {
2016-05-11 04:25:24 +08:00
if (!!nextState && !!nextState.params) {
setInStorage('meetingID', nextState.params.meetingID);
setInStorage('userID', nextState.params.userID);
setInStorage('authToken', nextState.params.authToken);
}
};
const subscribeForData = function() {
subscribeFor('chat');
subscribeFor('cursor');
2016-05-11 04:25:24 +08:00
subscribeFor('deskshare');
subscribeFor('meetings');
subscribeFor('polls');
2016-05-11 04:25:24 +08:00
subscribeFor('presentations');
subscribeFor('shapes');
subscribeFor('slides');
subscribeFor('users');
};
const subscribeFor = function (collectionName) {
const userID = getInStorage("userID");
const meetingID = getInStorage("meetingID");
const authToken = getInStorage("authToken");
2016-05-11 04:25:24 +08:00
// console.log("subscribingForData", collectionName, meetingID, userID, authToken);
Meteor.subscribe(collectionName, meetingID, userID, authToken, onError(), onReady());
};
let onError = function(error, result) {
// console.log("OnError", error, result);
};
let onReady = function() {
// console.log("OnReady", Users.find().fetch());
window.Users = Users; // for debug purposes TODO remove
};
2016-05-06 02:50:18 +08:00
const poll = Polls.findOne({});
return {
pollExists: !!poll,
subscribeForData: subscribeForData,
setCredentials: setCredentials,
};
};
2016-05-06 02:50:18 +08:00
export default AppService;