2016-06-02 21:46:35 +08:00
|
|
|
import Storage from '/imports/ui/services/storage';
|
2016-06-29 02:50:44 +08:00
|
|
|
import { callServer } from '/imports/ui/services/api';
|
2016-06-02 21:46:35 +08:00
|
|
|
|
2016-06-03 02:40:27 +08:00
|
|
|
export const setCredentials = (meeting, user, token) => {
|
2016-07-04 21:44:17 +08:00
|
|
|
Storage.setSession('meetingID', meeting);
|
|
|
|
Storage.setSession('userID', user);
|
|
|
|
Storage.setSession('authToken', token);
|
2016-06-02 21:46:35 +08:00
|
|
|
};
|
|
|
|
|
2016-06-03 02:40:27 +08:00
|
|
|
export const getCredentials = () => ({
|
2016-07-04 21:44:17 +08:00
|
|
|
meetingId: Storage.getSession('meetingID'),
|
|
|
|
requesterUserId: Storage.getSession('userID'),
|
|
|
|
requesterToken: Storage.getSession('authToken'),
|
2016-06-02 21:46:35 +08:00
|
|
|
});
|
|
|
|
|
2016-06-03 02:40:27 +08:00
|
|
|
export const getMeeting = () => getCredentials().meetingId;
|
2016-06-02 21:46:35 +08:00
|
|
|
|
2016-06-03 02:40:27 +08:00
|
|
|
export const getUser = () => getCredentials().requesterUserId;
|
2016-06-02 21:46:35 +08:00
|
|
|
|
2016-06-03 02:40:27 +08:00
|
|
|
export const getToken = () => getCredentials().requesterToken;
|
2016-06-02 21:46:35 +08:00
|
|
|
|
2016-06-18 06:15:11 +08:00
|
|
|
export const clearCredentials = (callback)=> {
|
2016-06-25 07:09:32 +08:00
|
|
|
Storage.set('meetingID', null);
|
|
|
|
Storage.set('userID', null);
|
|
|
|
Storage.set('authToken', null);
|
|
|
|
Storage.set('logoutURL', null);
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-06-25 07:09:32 +08:00
|
|
|
if (callback != null) {
|
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
};
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-06-25 07:09:32 +08:00
|
|
|
export const setLogOut = () => {
|
|
|
|
let request;
|
|
|
|
let handleLogoutUrlError;
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-06-25 07:09:32 +08:00
|
|
|
handleLogoutUrlError = function () {
|
|
|
|
console.log('Error : could not find the logoutURL');
|
|
|
|
Storage.set('logoutURL', document.location.hostname);
|
|
|
|
};
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-06-25 07:09:32 +08:00
|
|
|
// obtain the logoutURL
|
|
|
|
request = $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/bigbluebutton/api/enter',
|
|
|
|
});
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-06-25 07:09:32 +08:00
|
|
|
request.done(data => {
|
|
|
|
if (data.response.logoutURL != null) {
|
|
|
|
Storage.set('logoutURL', data.response.logoutURL);
|
|
|
|
} else {
|
|
|
|
if (data.response.logoutUrl != null) {
|
|
|
|
Storage.set('logoutURL', data.response.logoutUrl);
|
|
|
|
} else {
|
|
|
|
return handleLogoutUrlError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-06-25 07:09:32 +08:00
|
|
|
return request.fail(function (data, textStatus, errorThrown) {
|
|
|
|
return handleLogoutUrlError();
|
|
|
|
});
|
|
|
|
};
|
2016-06-18 06:15:11 +08:00
|
|
|
|
2016-06-29 02:50:44 +08:00
|
|
|
export const completeLogout = () => {
|
|
|
|
let logoutURL = Storage.get('logoutURL');
|
|
|
|
callServer('userLogout');
|
|
|
|
clearCredentials(() => {
|
|
|
|
document.location.href = logoutURL;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-06-02 21:46:35 +08:00
|
|
|
export default {
|
|
|
|
setCredentials,
|
|
|
|
getCredentials,
|
|
|
|
getMeeting,
|
|
|
|
getUser,
|
|
|
|
getToken,
|
2016-06-18 06:15:11 +08:00
|
|
|
clearCredentials,
|
|
|
|
setLogOut,
|
2016-06-29 02:50:44 +08:00
|
|
|
completeLogout,
|
2016-06-02 21:46:35 +08:00
|
|
|
};
|