bigbluebutton-Github/bigbluebutton-html5/lib/router.js

149 lines
6.0 KiB
JavaScript
Raw Normal View History

2016-01-13 04:15:16 +08:00
this.Router.configure({
layoutTemplate: 'layout',
2016-01-13 04:15:16 +08:00
});
this.Router.map(function () {
2016-01-15 13:46:41 +08:00
// this is how we handle login attempts
this.route('main', {
path: '/html5client/:meeting_id/:user_id/:auth_token',
where: 'client',
2016-01-13 04:15:16 +08:00
onBeforeAction() {
let applyNewSessionVars, authToken, meetingId, userId;
meetingId = this.params.meeting_id;
userId = this.params.user_id;
authToken = this.params.auth_token;
setInSession('loginUrl', this.originalUrl);
2016-01-15 13:46:41 +08:00
// catch if any of the user's meeting data is invalid
2016-01-13 04:15:16 +08:00
if ((authToken == null) || (meetingId == null) || (userId == null)) {
2016-01-15 13:46:41 +08:00
// if their data is invalid, redirect the user to the logout page
2016-01-13 04:15:16 +08:00
document.location = getInSession('logoutURL');
} else {
Meteor.call('validateAuthToken', meetingId, userId, authToken);
applyNewSessionVars = function () {
setInSession('authToken', authToken);
setInSession('meetingId', meetingId);
setInSession('userId', userId);
2016-01-13 04:15:16 +08:00
return Router.go('/html5client');
};
2016-01-13 04:15:16 +08:00
clearSessionVar(applyNewSessionVars);
}
2016-01-13 04:15:16 +08:00
return this.next();
},
2016-01-13 04:15:16 +08:00
});
2016-01-15 13:46:41 +08:00
// the user successfully logged in
this.route('signedin', {
path: '/html5client',
where: 'client',
2016-01-13 04:15:16 +08:00
action() {
let authToken, meetingId, onErrorFunction, userId;
meetingId = getInSession('meetingId');
userId = getInSession('userId');
authToken = getInSession('authToken');
onErrorFunction = function (error, result) {
console.log('ONERRORFUNCTION');
2016-01-15 13:46:41 +08:00
//make sure the user is not let through
Meteor.call('userLogout', meetingId, userId, authToken);
2016-01-15 13:46:41 +08:00
2016-01-13 04:15:16 +08:00
clearSessionVar();
2016-01-15 13:46:41 +08:00
// Attempt to log back in
2016-01-13 04:15:16 +08:00
if (error == null) {
window.location.href = getInSession('loginUrl') || getInSession('logoutURL');
}
};
2016-01-13 04:15:16 +08:00
Meteor.subscribe('chat', meetingId, userId, authToken, {
onError: onErrorFunction,
onReady: (_this => {
return function () {
2016-01-13 04:15:16 +08:00
return Meteor.subscribe('shapes', meetingId, {
onReady: function () {
2016-01-13 04:15:16 +08:00
return Meteor.subscribe('slides', meetingId, {
onReady: function () {
2016-01-13 04:15:16 +08:00
return Meteor.subscribe('meetings', meetingId, {
onReady: function () {
2016-01-13 04:15:16 +08:00
return Meteor.subscribe('presentations', meetingId, {
onReady: function () {
2016-01-13 04:15:16 +08:00
return Meteor.subscribe('users', meetingId, userId, authToken, {
onError: onErrorFunction,
onReady: function () {
2016-01-13 04:15:16 +08:00
return Meteor.subscribe('whiteboard-clean-status', meetingId, {
onReady: function () {
2016-01-13 04:15:16 +08:00
return Meteor.subscribe('bbb_poll', meetingId, userId, authToken, {
onReady: function () {
2016-01-13 04:15:16 +08:00
return Meteor.subscribe('bbb_cursor', meetingId, {
onReady: function () {
2016-01-13 04:15:16 +08:00
let a, handleLogourUrlError;
2016-01-15 13:46:41 +08:00
// done subscribing, start rendering the client and set default settings
2016-01-13 04:15:16 +08:00
_this.render('main');
onLoadComplete();
handleLogourUrlError = function () {
alert('Error: could not find the logoutURL');
setInSession('logoutURL', document.location.hostname);
2016-01-13 04:15:16 +08:00
};
2016-01-15 13:46:41 +08:00
// obtain the logoutURL
2016-01-13 04:15:16 +08:00
a = $.ajax({
dataType: 'json',
url: '/bigbluebutton/api/enter',
2016-01-13 04:15:16 +08:00
});
a.done(data => {
2016-01-15 13:46:41 +08:00
if (data.response.logoutURL != null) { // for a meeting with 0 users
setInSession('logoutURL', data.response.logoutURL);
2016-01-13 04:15:16 +08:00
} else {
2016-01-15 13:46:41 +08:00
if (data.response.logoutUrl != null) { // for a running meeting
setInSession('logoutURL', data.response.logoutUrl);
2016-01-13 04:15:16 +08:00
} else {
return handleLogourUrlError();
}
}
});
return a.fail((data, textStatus, errorThrown) => {
return handleLogourUrlError();
});
},
2016-01-13 04:15:16 +08:00
});
},
2016-01-13 04:15:16 +08:00
});
},
2016-01-13 04:15:16 +08:00
});
},
2016-01-13 04:15:16 +08:00
});
},
2016-01-13 04:15:16 +08:00
});
},
2016-01-13 04:15:16 +08:00
});
},
2016-01-13 04:15:16 +08:00
});
},
2016-01-13 04:15:16 +08:00
});
};
})(this),
2016-01-13 04:15:16 +08:00
});
return this.render('loading');
},
2016-01-13 04:15:16 +08:00
});
2016-01-15 13:46:41 +08:00
// endpoint - is the html5client running (ready to handle a user)
2016-01-13 04:15:16 +08:00
this.route('meteorEndpoint', {
path: '/check',
where: 'server',
action() {
this.response.writeHead(200, {
'Content-Type': 'application/json',
2016-01-13 04:15:16 +08:00
});
2016-01-15 13:46:41 +08:00
// reply that the html5client is running
2016-01-13 04:15:16 +08:00
this.response.end(JSON.stringify({
html5clientStatus: 'running',
2016-01-13 04:15:16 +08:00
}));
},
2016-01-13 04:15:16 +08:00
});
});