2016-05-10 05:19:45 +08:00
|
|
|
import { Meteor } from 'meteor/meteor'
|
2016-05-13 01:43:59 +08:00
|
|
|
import Users from '/imports/api/users/collection';
|
2016-05-13 03:22:51 +08:00
|
|
|
import Chat from '/imports/api/chat/collection';
|
|
|
|
import Meetings from '/imports/api/meetings/collection';
|
|
|
|
import Cursor from '/imports/api/cursor/collection';
|
2016-05-13 03:50:02 +08:00
|
|
|
import Polls from '/imports/api/polls';
|
2016-05-11 03:39:01 +08:00
|
|
|
|
2016-05-13 02:58:06 +08:00
|
|
|
const setInStorage = function(key, value) {
|
|
|
|
if (!!value) {
|
|
|
|
console.log('in setInStorage', key, value);
|
|
|
|
localStorage.setItem(key, value);
|
|
|
|
}
|
|
|
|
};
|
2016-05-11 03:39:01 +08:00
|
|
|
|
2016-05-13 02:58:06 +08:00
|
|
|
const getInStorage = function(key) {
|
|
|
|
return localStorage.getItem(key);
|
|
|
|
};
|
2016-05-11 03:39:01 +08:00
|
|
|
|
2016-05-13 02:58:06 +08:00
|
|
|
const setCredentials = function (nextState, replace) {
|
|
|
|
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
|
|
|
|
2016-05-13 02:58:06 +08:00
|
|
|
const subscribeForData = function() {
|
|
|
|
subscribeFor('chat');
|
|
|
|
subscribeFor('cursor');
|
|
|
|
subscribeFor('deskshare');
|
|
|
|
subscribeFor('meetings');
|
|
|
|
subscribeFor('polls');
|
|
|
|
subscribeFor('presentations');
|
|
|
|
subscribeFor('shapes');
|
|
|
|
subscribeFor('slides');
|
|
|
|
subscribeFor('users');
|
2016-05-11 03:39:01 +08:00
|
|
|
|
2016-05-13 03:30:46 +08:00
|
|
|
window.Users = Users; // for debug purposes TODO remove
|
|
|
|
window.Chat = Chat; // for debug purposes TODO remove
|
|
|
|
window.Meetings = Meetings; // for debug purposes TODO remove
|
|
|
|
window.Cursor = Cursor; // for debug purposes TODO remove
|
|
|
|
window.Polls = Polls; // for debug purposes TODO remove
|
2016-05-13 02:58:06 +08:00
|
|
|
};
|
2016-05-11 03:39:01 +08:00
|
|
|
|
2016-05-13 02:58:06 +08:00
|
|
|
const subscribeFor = function (collectionName) {
|
|
|
|
const userID = getInStorage("userID");
|
|
|
|
const meetingID = getInStorage("meetingID");
|
|
|
|
const authToken = getInStorage("authToken");
|
|
|
|
// console.log("subscribingForData", collectionName, meetingID, userID, authToken);
|
2016-05-11 03:39:01 +08:00
|
|
|
|
2016-05-13 02:58:06 +08:00
|
|
|
Meteor.subscribe(collectionName, meetingID, userID, authToken, onError(), onReady());
|
|
|
|
};
|
2016-05-11 03:39:01 +08:00
|
|
|
|
2016-05-13 02:58:06 +08:00
|
|
|
let onError = function(error, result) {
|
|
|
|
// console.log("OnError", error, result);
|
|
|
|
};
|
2016-05-11 03:39:01 +08:00
|
|
|
|
2016-05-13 02:58:06 +08:00
|
|
|
let onReady = function() {
|
|
|
|
// console.log("OnReady", Users.find().fetch());
|
2016-05-13 03:30:46 +08:00
|
|
|
};
|
2016-05-11 03:39:01 +08:00
|
|
|
|
2016-05-12 23:41:51 +08:00
|
|
|
function pollExists() {
|
|
|
|
return !!(Polls.findOne({}));
|
|
|
|
}
|
|
|
|
|
2016-05-13 03:50:02 +08:00
|
|
|
export {
|
2016-05-12 23:41:51 +08:00
|
|
|
pollExists,
|
2016-05-13 03:50:02 +08:00
|
|
|
subscribeForData,
|
|
|
|
setCredentials,
|
2016-05-14 00:17:00 +08:00
|
|
|
getInStorage,
|
2016-05-12 23:41:51 +08:00
|
|
|
};
|