2016-07-11 21:45:24 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2017-04-20 22:12:14 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-10-21 03:01:07 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2016-05-14 00:17:00 +08:00
|
|
|
|
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) {
|
2017-04-20 22:12:14 +08:00
|
|
|
check(name, String);
|
2016-05-13 00:10:20 +08:00
|
|
|
|
2017-10-26 07:11:06 +08:00
|
|
|
const { credentials } = Auth;
|
2016-05-13 00:10:20 +08:00
|
|
|
|
2017-04-20 22:12:14 +08:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
Meteor.call(name, credentials, ...args, (error, result) => {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
2017-04-26 21:53:01 +08:00
|
|
|
|
|
|
|
resolve(result);
|
2017-04-20 22:12:14 +08:00
|
|
|
});
|
|
|
|
});
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|
2016-05-13 00:10:20 +08:00
|
|
|
|
2017-04-20 22:12:14 +08:00
|
|
|
/**
|
|
|
|
* Send the request to the server via Meteor.call and treat the error to a default callback.
|
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 call(name, ...args) {
|
2017-04-26 21:53:01 +08:00
|
|
|
return makeCall(name, ...args).catch((e) => {
|
2017-10-13 02:53:33 +08:00
|
|
|
notify(`Ops! Error while executing ${name}`, 'error');
|
2017-04-26 21:53:01 +08:00
|
|
|
throw e;
|
|
|
|
});
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|
2016-05-13 00:10:20 +08:00
|
|
|
|
2017-10-24 20:58:46 +08:00
|
|
|
export function log(type = 'error', message, ...args) {
|
2017-10-26 07:11:06 +08:00
|
|
|
const { credentials } = Auth;
|
2017-04-28 21:47:07 +08:00
|
|
|
const userInfo = window.navigator;
|
2017-10-24 20:58:46 +08:00
|
|
|
const clientInfo = {
|
|
|
|
language: userInfo.language,
|
|
|
|
userAgent: userInfo.userAgent,
|
2017-10-26 07:12:17 +08:00
|
|
|
screenSize: { width: window.screen.width, height: window.screen.height },
|
2017-10-24 20:58:46 +08:00
|
|
|
windowSize: { width: window.innerWidth, height: window.innerHeight },
|
|
|
|
bbbVersion: Meteor.settings.public.app.bbbServerVersion,
|
|
|
|
location: window.location.href,
|
|
|
|
};
|
2018-06-20 01:36:12 +08:00
|
|
|
const logContents = { ...args };
|
|
|
|
const topic = typeof logContents[0] ? logContents[0].topic : null;
|
2017-04-28 21:47:07 +08:00
|
|
|
|
2018-06-20 01:36:12 +08:00
|
|
|
const messageOrStack = message.stack || message.message || JSON.stringify(message);
|
|
|
|
console.debug(`CLIENT LOG (${topic ? type.toUpperCase() + '.' + topic : type.toUpperCase()}): `, messageOrStack, ...args);
|
2017-04-29 01:12:08 +08:00
|
|
|
|
2017-10-24 20:58:46 +08:00
|
|
|
Meteor.call('logClient', type, messageOrStack, {
|
|
|
|
clientInfo,
|
2017-04-29 01:12:08 +08:00
|
|
|
credentials,
|
2017-10-24 20:58:46 +08:00
|
|
|
...args,
|
|
|
|
});
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|