bigbluebutton-Github/bigbluebutton-html5/imports/ui/services/api/index.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

import Auth from '/imports/ui/services/auth';
2017-04-20 22:12:14 +08:00
import { check } from 'meteor/check';
import logger from '/imports/startup/client/logger';
2017-04-20 22:12:14 +08:00
/**
* Send the request to the server via Meteor.call and don't treat errors.
2017-05-04 01:19:21 +08:00
*
2017-04-26 21:53:01 +08:00
* @param {string} name
* @param {any} args
2017-04-20 22:12:14 +08:00
* @see https://docs.meteor.com/api/methods.html#Meteor-call
* @return {Promise}
*/
2017-10-24 20:58:46 +08:00
export function makeCall(name, ...args) {
check(name, String);
const { credentials } = Auth;
return new Promise((resolve, reject) => {
if (Meteor.status().connected) {
Meteor.call(name, credentials, ...args, (error, result) => {
if (error) {
reject(error);
}
2017-04-26 21:53:01 +08:00
resolve(result);
});
} else {
2019-08-14 01:52:25 +08:00
const failureString = `Call to ${name} failed because Meteor is not connected`;
// We don't want to send a log message if the call that failed wasa log message.
// Without this you can get into an endless loop of failed logging.
if (name !== 'logClient') {
logger.warn({
logCode: 'servicesapiindex_makeCall',
extraInfo: {
attemptForUserInfo: Auth.fullInfo,
name,
...args,
},
}, failureString);
}
reject(failureString);
}
});
2017-06-03 03:25:02 +08:00
}