UNPKG

mtl-js-sdk

Version:

138 lines (116 loc) 4.9 kB
"use strict"; function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } define(function () { var __NCC = 'NCC'; function openXYChatView(obj) { var _obj = obj || {}; YYEsnBridge.registerHandler({ mtlDataCallBack: obj.callback }); // xiaoyou_params: { //小友机器人必要参数,必传 // tenantid: "qa56zqg7", //租户id 申请机器人后获得 // appcode: "nccloud", //应用id // yhtuserid: "b9d3d30d-e110-41a1-99b9-f9ed8b4d771e" //友互通id // }, var data = { callback: 'mtlDataCallBack', autoClose: _obj.autoClose, xiaoyou_params: JSON.stringify(_obj.xiaoyou_params), success: function success(res) { _obj.success && _obj.success(res); }, fail: function fail(res) { _obj.fail && _obj.fail(res); }, complete: function complete(res) { _obj.complete && _obj.complete(res); } }; execEsnBridge('openXYChatView', data); // YYEsnBridge.do('openXYChatView', data); } function closeXYChatView(obj) { var _obj = obj || {}; var data = { success: function success(res) { _obj.success && _obj.success(res); }, fail: function fail(res) { _obj.fail && _obj.fail(res); }, complete: function complete(res) { _obj.complete && _obj.complete(res); } }; execEsnBridge('closeXYChatView', data); // YYEsnBridge.do('closeXYChatView', data); } function getXYVersion(obj) { var _obj = obj || {}; var data = { success: function success(res) { _obj.success && _obj.success(res); }, fail: function fail(res) { _obj.fail && _obj.fail(res); }, complete: function complete(res) { _obj.complete && _obj.complete(res); } }; execEsnBridge('getXYVersion', data); // YYEsnBridge.do('getXYVersion', data); } function execEsnBridge(method, source) { var data = _objectSpread({}, source, { fail: function fail(error) { source.fail(getErrormsg(method, error)); } }); YYEsnBridge["do"](__NCC + method, data); } /** * 400 参数不合法 401 用户无权限访问 405 APP无权限进行此项操作,如打开照相机,APP未取得授权 406 文件大小超出限制 500 http请求错误 501 http服务器错误 1001 无网络 1002 解析错误 1003 用户取消 -1 未知错误 -2 界面超时 -1000 未找到对应方法 * @param {*} error */ function getErrormsg(method, error) { var esnError = { code: -1, message: errmsg }; if (_typeof(error) === "object") { var code = error.errCode; var msg = ""; if (code == 1003) { msg = "用户取消"; } else if (code == -1000) { msg = "未找到对应方法"; } else if (code == 405) { msg = "APP无权限进行此项操作,如打开照相机,APP未取得授权"; } else if (code == 401) { msg = "用户无权限访问"; } esnError.code = code; esnError.message = msg || JSON.stringify(error); } var errmsg = "\u8C03\u7528\u53CB\u7A7A\u95F4 ".concat(__NCC + method, " \u65B9\u6CD5,\u8FD4\u56DE\u9519\u8BEF\u4FE1\u606F\uFF1A ").concat(esnError.message); esnError.message = errmsg; console.error(errmsg); return esnError; } return { openXYChatView: openXYChatView, closeXYChatView: closeXYChatView, getXYVersion: getXYVersion }; });