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

71 lines
2.0 KiB
JavaScript
Raw Normal View History

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';
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) {
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');
subscribeFor('deskshare');
subscribeFor('meetings');
subscribeFor('polls');
subscribeFor('presentations');
subscribeFor('shapes');
subscribeFor('slides');
subscribeFor('users');
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
};
const subscribeFor = function (collectionName) {
const userID = getInStorage("userID");
const meetingID = getInStorage("meetingID");
const authToken = getInStorage("authToken");
// 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());
};
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-12 23:41:51 +08:00
};