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

69 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-05-14 00:31:06 +08:00
import { Meteor } from 'meteor/meteor';
import Auth from '/imports/ui/services/auth';
2016-05-17 02:05:44 +08:00
import Users from '/imports/api/users';
import Chat from '/imports/api/chat';
import Meetings from '/imports/api/meetings';
import Cursor from '/imports/api/cursor';
2016-05-13 03:50:02 +08:00
import Polls from '/imports/api/polls';
2016-05-14 00:31:06 +08:00
function setCredentials(nextState, replace) {
2016-06-03 02:40:27 +08:00
if (nextState && nextState.params.authToken) {
const { meetingID, userID, authToken } = nextState.params;
Auth.setCredentials(meetingID, userID, authToken);
}
};
2016-05-14 00:31:06 +08:00
function subscribeForData() {
subscribeFor('users');
Meteor.setTimeout(() => {
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
2016-06-18 06:15:11 +08:00
Auth.setLogOut();
}, 2000); //To avoid race condition where we subscribe before receiving auth from BBB
};
2016-05-14 00:31:06 +08:00
function subscribeFor(collectionName) {
const credentials = Auth.getCredentials();
2016-05-14 00:31:06 +08:00
// console.log("subscribingForData", collectionName, meetingID, userID, authToken);
2016-05-17 02:12:27 +08:00
Meteor.subscribe(collectionName, credentials, onError, onReady);
};
2016-05-14 00:31:06 +08:00
function onError(error, result) {
2016-06-25 07:09:32 +08:00
// console.log("OnError", error, result);
2016-06-18 06:15:11 +08:00
console.log('OnError', error, result);
2016-06-29 02:50:44 +08:00
Auth.completeLogout();
};
2016-05-14 00:31:06 +08:00
function onReady() {
// 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
};