2016-05-10 05:19:45 +08:00
|
|
|
import { Meteor } from 'meteor/meteor'
|
2016-05-11 02:53:05 +08:00
|
|
|
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-11 03:39:01 +08:00
|
|
|
|
2016-05-06 03:50:11 +08:00
|
|
|
let AppService = function () {
|
2016-05-11 03:39:01 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2016-05-11 03:39:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const subscribeForData = function() {
|
|
|
|
subscribeFor('chat');
|
|
|
|
subscribeFor('cursor');
|
2016-05-11 04:25:24 +08:00
|
|
|
subscribeFor('deskshare');
|
2016-05-11 03:39:01 +08:00
|
|
|
subscribeFor('meetings');
|
|
|
|
subscribeFor('polls');
|
2016-05-11 04:25:24 +08:00
|
|
|
subscribeFor('presentations');
|
|
|
|
subscribeFor('shapes');
|
|
|
|
subscribeFor('slides');
|
|
|
|
subscribeFor('users');
|
2016-05-11 03:39:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
2016-05-11 03:39:01 +08:00
|
|
|
|
|
|
|
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({});
|
2016-05-11 03:39:01 +08:00
|
|
|
return {
|
|
|
|
pollExists: !!poll,
|
|
|
|
subscribeForData: subscribeForData,
|
|
|
|
setCredentials: setCredentials,
|
|
|
|
};
|
2016-05-11 02:53:05 +08:00
|
|
|
};
|
|
|
|
|
2016-05-06 02:50:18 +08:00
|
|
|
export default AppService;
|