From e59e04a23f7c08c5718ee595346d9d4ce8a9a708 Mon Sep 17 00:00:00 2001 From: Tainan Felipe <tainanfelipe214@gmail.com> Date: Mon, 10 Dec 2018 13:52:25 -0200 Subject: [PATCH] testing async await to join --- .../authenticated-handler/component.jsx | 21 +++--- .../ui/components/join-handler/component.jsx | 67 +++++++++---------- .../imports/ui/services/auth/index.js | 2 +- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/bigbluebutton-html5/imports/ui/components/authenticated-handler/component.jsx b/bigbluebutton-html5/imports/ui/components/authenticated-handler/component.jsx index 9de30ed45e..552080bb16 100644 --- a/bigbluebutton-html5/imports/ui/components/authenticated-handler/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/authenticated-handler/component.jsx @@ -31,20 +31,25 @@ class AuthenticatedHandler extends Component { } }); } - static authenticatedRouteHandler(callback) { + static async authenticatedRouteHandler(callback) { if (Auth.loggedIn) { callback(); } AuthenticatedHandler.addReconnectObservable(); - Auth.authenticate() - .then(callback) - .catch((reason) => { - log('error', reason); - AuthenticatedHandler.setError(reason.error); - callback(); - }); + const setReason = (reason) => { + log('error', reason); + AuthenticatedHandler.setError(reason.error); + callback(); + }; + + try { + const getAuthenticate = await Auth.authenticate(); + callback(getAuthenticate); + } catch (error) { + setReason(error); + } } constructor(props) { super(props); diff --git a/bigbluebutton-html5/imports/ui/components/join-handler/component.jsx b/bigbluebutton-html5/imports/ui/components/join-handler/component.jsx index 433be3f486..2bf0244d9e 100644 --- a/bigbluebutton-html5/imports/ui/components/join-handler/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/join-handler/component.jsx @@ -31,7 +31,7 @@ class JoinHandler extends Component { this.setState({ joined: bool }); } - fetchToken() { + async fetchToken() { const urlParams = new URLSearchParams(window.location.search); const sessionToken = urlParams.get('sessionToken'); if (!sessionToken) { @@ -56,7 +56,7 @@ class JoinHandler extends Component { location: window.location.href, }; - logger.info(clientInfo); + logger.info(clientInfo); }; const setAuth = (resp) => { @@ -64,11 +64,13 @@ class JoinHandler extends Component { meetingID, internalUserID, authToken, logoutUrl, fullname, externUserID, confname, } = resp; - Auth.set( - meetingID, internalUserID, authToken, logoutUrl, - sessionToken, fullname, externUserID, confname, - ); - return resp; + return new Promise((resolve) => { + Auth.set( + meetingID, internalUserID, authToken, logoutUrl, + sessionToken, fullname, externUserID, confname, + ); + resolve(resp); + }); }; const setLogoutURL = (url) => { @@ -86,38 +88,33 @@ class JoinHandler extends Component { meetingID, internalUserID, customdata, } = resp; - if (customdata.length) { - makeCall('addUserSettings', meetingID, internalUserID, customdata); - } - return resp; + + return new Promise((resolve) => { + if (customdata.length) { + makeCall('addUserSettings', meetingID, internalUserID, customdata).then(r => resolve(r)); + } + resolve(true); + }); }; // use enter api to get params for the client const url = `/bigbluebutton/api/enter?sessionToken=${sessionToken}`; - const validAuth = new Promise((resolve, reject) => { - fetch(url, { credentials: 'same-origin' }) - .then(response => response.json()) - .then(({ response }) => response) - .then((resp) => { - setLogoutURL(resp.logoutURL); - if (resp.returncode !== 'FAILED') { - logger.info(`User successfully went through main.joinRouteHandler with [${JSON.stringify(resp)}].`); - return resolve(resp); - } - const e = new Error('Session not found'); - logger.error(`User faced [${e}] on main.joinRouteHandler. Error was:`, JSON.stringify(resp)); - return reject(e); - }); - }); - - validAuth - .then(setCustomData) - .then(setAuth) - .then(setLogoURL) - .then(logUserInfo) - .then(() => Session.set('isUserListOpen', deviceInfo.type().isPhone)) - .then(() => this.changeToJoin(true)) - .catch(() => this.changeToJoin(true)); + const fetchContent = await fetch(url, { credentials: 'same-origin' }); + const parseToJson = await fetchContent.json(); + const { response } = parseToJson; + setLogoutURL(response); + if (response.returncode !== 'FAILED') { + await setAuth(response); + await setCustomData(response); + setLogoURL(response); + logUserInfo(); + Session.set('isUserListOpen', deviceInfo.type().isPhone); + logger.info(`User successfully went through main.joinRouteHandler with [${JSON.stringify(response)}].`); + } else { + const e = new Error('Session not found'); + logger.error(`User faced [${e}] on main.joinRouteHandler. Error was:`, JSON.stringify(response)); + } + this.changeToJoin(true); } render() { diff --git a/bigbluebutton-html5/imports/ui/services/auth/index.js b/bigbluebutton-html5/imports/ui/services/auth/index.js index d950defbd6..e0ef521059 100755 --- a/bigbluebutton-html5/imports/ui/services/auth/index.js +++ b/bigbluebutton-html5/imports/ui/services/auth/index.js @@ -221,7 +221,7 @@ class Auth { computation.stop(); clearTimeout(validationTimeout); // setTimeout to prevent race-conditions with subscription - setTimeout(resolve, 100); + setTimeout(() => resolve(true), 100); } }); -- GitLab