Merge pull request #7771 from antobinary/makecall-retry

Prevent client freze on Meteor.call() if not connected
This commit is contained in:
Chad Pilkey 2019-07-12 15:27:26 -04:00 committed by GitHub
commit 459d775d26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 8 deletions

View File

@ -25,6 +25,7 @@ class JoinHandler extends Component {
super(props);
this.fetchToken = this.fetchToken.bind(this);
this.changeToJoin = this.changeToJoin.bind(this);
this.numFetchTokenRetries = 0;
this.state = {
joined: false,
@ -32,14 +33,34 @@ class JoinHandler extends Component {
}
componentDidMount() {
this._isMounted = true;
this.fetchToken();
}
componentWillUnmount() {
this._isMounted = false;
}
changeToJoin(bool) {
this.setState({ joined: bool });
}
async fetchToken() {
if (!this._isMounted) return;
if (!Meteor.status().connected) {
if (this.numFetchTokenRetries > 9) {
logger.error({
logCode: 'joinhandler_component_fetchToken_not_connected',
extraInfo: {
numFetchTokenRetries: this.numFetchTokenRetries,
},
}, 'Meteor was not connected, retry in a few moments');
}
this.numFetchTokenRetries += 1;
setTimeout(() => this.fetchToken(), 200);
}
const urlParams = new URLSearchParams(window.location.search);
const sessionToken = urlParams.get('sessionToken');
@ -102,7 +123,6 @@ class JoinHandler extends Component {
meetingID, internalUserID, customdata,
} = resp;
return new Promise((resolve) => {
if (customdata.length) {
makeCall('addUserSettings', meetingID, internalUserID, customdata).then(r => resolve(r));

View File

@ -11,12 +11,12 @@ import { notify } from '/imports/ui/services/notification';
* @return {Promise}
*/
export function makeCall(name, ...args) {
if (Meteor.status().connected) {
check(name, String);
check(name, String);
const { credentials } = Auth;
const { credentials } = Auth;
return new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
if (Meteor.status().connected) {
Meteor.call(name, credentials, ...args, (error, result) => {
if (error) {
reject(error);
@ -24,9 +24,10 @@ export function makeCall(name, ...args) {
resolve(result);
});
});
}
return null;
} else {
reject(new Error('Meteor was not connected'));
}
});
}
/**