UNPKG

fcc-core

Version:

Fusion communication center.

145 lines (137 loc) 4.82 kB
import ajaxRequest from '../utils/ajaxRequest' import { xwsToEvents, XwEvent } from '../events' import BaseException from '../errors/base-exception' import Validator from '../utils/validator' import nats from '../utils/nats' import ExeSocket from '../utils/exeSocket' import IMSocket from '../utils/imSocket' import WebServiceSocket from '../utils/webServiceSocket/webServiceSocket' import { language } from '../config' // 暴露给用户的融合通讯中台对象类 class XW { constructor (options = {}) { this.baseUrl = '' // 指向融合通讯中台的服务器地址(通常为代理路径) const { pointToPointCall, meeting, phone, IM, monitor, cluster } = options this.pointToPointCall = pointToPointCall || false this.meeting = meeting || false this.phone = phone || false this.IM = IM || false this.monitor = monitor || false // this.cluster = cluster || false const xw = new Proxy(this, { set (target, p, value) { if (p === 'userInfo') { // 写入用户基本信息 return Reflect.defineProperty(target, p, { value, writable: true }) } else if (p === 'baseUrl') { return Reflect.defineProperty(target, p, { value, writable: false }) } return false } }) xws.set(xw, new XWPrivate(xw)) return xw } } // 融合通讯内部开发者使用的中台对象类 class XWPrivate { constructor (xw) { this.public = xw // 暴露给用户的融合通讯中台对象 this.dictList = dictList // 数据字典集合 this.sysParam = sysParam // 系统参数 this.userInfo = {} // 用户信息 this.heartInterval = null // 心跳 this.BaseException = BaseException // 基础的错误类,用于给用户提示错误信息 this.nats = nats // nats 服务 this.ucc = {} // 话务对象 this.agentState = '3' // 当前登录人员在华为平台的状态 1:在线且空闲 2:在线且忙碌 3:离线 this.SEND_ICP_CODE = '' // 被叫方ICP_CODE this.memberStatus = {} // 状态对象 this.sysLoginStatus = { // exe登录各个系统的状 dispatch: false, cluster: false, monitor: false, phone: false } this.icpBaseUrl = '' // icp管理台的根路径,exe内嵌页面都基于这个路径。值取得是 系统参数 ICP_BASE_URL this.timeout = 60000 // 系统超时时长 this.exe = new ExeSocket(this) // 与exe的连接对象 this.im = IMSocket // 与im的连接对象 this.webServiceSocket = new WebServiceSocket(this) xwsToEvents.set(this, new XwEvent(this)) } // 参数校验方法,第一个参数为要校验的对象,第二个参数为校验的描述对象 async validate (source, descriptor) { await new Validator(descriptor).validate(source) } // 与 webService 建立 http 连接的方法 ajaxRequest (req) { return ajaxRequest(req, this) } // 派发中台事件给用户 emit (eventType, payload) { xwsToEvents.get(this).emit(eventType, payload) } // 获取数据字典 getDict (key, val) { return getDict(key, val) } // 获取系统参数 getSysParam (key) { return getSysParam(key) } } // 创建的融合通讯中台实例集合 const xws = new Map() const dictList = {} const sysParam = {} // 获取数据字典 function getDict (key, val) { if (key) { if (dictList) { if (dictList[key]) { let dict = dictList[key][language.toUpperCase()] // 此处由于数据库里存的字段名全为大写(包括语言名代号也是大写),所以前端也统一转成大写 !!!!!!!!!!!!!!!!!!!!!!!!! if (dict) { if (val) { for (let i = 0; i < dict.length; i++) { if (dict[i]['DICT_ITEM'] === val) { return dict[i]['DICT_ITEM_NAME'] } } } else { if (val === '') { return '' } return dict } } } } } else { console.error('getters.getDict:获取数据字典需要传入字典key值。') } } // 获取系统参数 function getSysParam (key) { if (key) { if (sysParam) { if (sysParam[key]) { if (sysParam[key][0]) { return sysParam[key][0]['PARAM_VAL'] } } } } else { console.error('getters.getSysParam:获取系统参数需要传入系统参数key值。') } } // 开发环境 xws 挂到 window 上,方便调试 if (process.env.NODE_ENV === 'development') { window.xws = xws } export { XW, XWPrivate, xws }