UNPKG

fcc-core

Version:

Fusion communication center.

321 lines (308 loc) 10.6 kB
import Cookies from 'js-cookie' import http from '../../../utils/ajaxRequest/instance' import encrypt from '../../../utils/encrypt' import makeXmlRequestStr from './makeXmlRequestStr' import { language } from '../../../config' import createLongin from './loginIn' import { changeEmployeeStatus } from '../../../utils/nats/natsApi' import { natsSubscribe } from '../../../utils/nats/natsSubscribe' // import { sendGlassPiontCallMessage, callAccept } from '../../../utils/webServiceSocket/messageSocketApi' import { callAccept } from '../../../utils/webServiceSocket/messageSocketApi' // import { reject } from 'core-js/fn/promise' export default async function (xw, param) { xw.icpBaseUrl = xw.getSysParam('ICP_BASE_URL') // icp管理台的根路径,exe内嵌页面都基于这个路径。值取得是 系统参数 ICP_BASE_URL xw.timeout = +(xw.getSysParam('CORE_TIMEOUT') || 60000) // 系统超时时长 await loginWebService(xw, param) // 登录 WebService await xw.nats.open(xw) // 建立 nats 连接 // await xw.webServiceSocket.open(xw) // 建立会议信息连接 await openExe(xw) // 启动并连接 exe console.log(xw.public) if (xw.public.IM) await openIM(xw) // 启动并连接 im await openServiceSocket(xw) // 启动并连接 webServiceSocket await loginIn(xw) // 登录华为平台(签入) // nats监听 natsSubscribe(xw) console.log('融合通讯中台登录成功1') // 标记登录成功 xw.agentState = '1' // 监听预约入会事件处理 await listenJoinMeeting(xw) heart(xw) // 心跳检查 systemListen(xw) // 监听系统事件 } // 登录 WebService async function loginWebService (xw, param) { const { userAccount, token, userId } = param let kencPassword = '' let kencKey = '' const ZT_SERVLCE = xw.getSysParam('ZT_SERVLCE') // 1是IAM统一认证 2对外 3对内 console.log(`ZT_SERVLCE:${ZT_SERVLCE}`) Cookies.set('account', userAccount, { expires: 720 }) await xw.validate(param, { token: [ { type: 'string' } ], userId: [ { type: 'string' } ], userAccount: [ { type: 'string' } ] }) if (ZT_SERVLCE === '2') { // 内部调用 const { data } = await xw.ajaxRequest([{ service: 'E1203601', isHttp: true, USER_ACCOUNT: userAccount }]) kencPassword = data[0].USER_PASS const params = { USER_ACCOUNT: userAccount, TRD_PWD: kencPassword, VALIDATECODE: '', // 验证码!!!!!!!!!!!!!!! OP_LANGUAGE: language // 语言类型 } let requestXmlStr = encrypt(makeXmlRequestStr([params]), kencKey + '') let result = await http({ apiType: 'UCC', method: 'post', url: '/njdf_login?encoderType=des', text: true, data: requestXmlStr }) result = result['data'] if (result['IRETCODE'] === '0') { // 登录成功 console.log(document.cookie) if (result.ROLE_INFO && result.ROLE_INFO.length) { // 如果当前帐号有多种角色,取第一种 result.CURR_ROLE = result.ROLE_INFO[0].ROLE_CODE } else { result.CURR_ROLE = 1 } xw.userInfo = result xw.public.userInfo = { // 暴露给中台用户的用户信息 USER_ACCOUNT: result.USER_ACCOUNT, USER_CODE: result.USER_CODE, USER_NAME: result.USER_NAME, ORG_ID: result.ORG_ID, ROLE_INFO: result.ROLE_INFO } } else { throw new xw.BaseException(501, `登录失败了,原因:${result.IRETINFO}`) } } else if (ZT_SERVLCE === '1') { // I AM 方案 let result = await http({ apiType: 'UCC', method: 'post', url: `/njdf_services/SSOLogin`, data: { token, userId } }) result = result['data'] if (result['code'] === '0') { // 登录成功 result = result['data'][0] if (result.ROLE_INFO && result.ROLE_INFO.length) { // 如果当前帐号有多种角色,取第一种 result.CURR_ROLE = result.ROLE_INFO[0].ROLE_CODE } else { result.CURR_ROLE = 1 } xw.userInfo = result xw.public.userInfo = { // 暴露给中台用户的用户信息 USER_ACCOUNT: result.USER_ACCOUNT, USER_CODE: result.USER_CODE, USER_NAME: result.USER_NAME, ORG_ID: result.ORG_ID, ROLE_INFO: result.ROLE_INFO } } else { throw new xw.BaseException(501, `登录失败了,原因:${result.msg}`) } } } // 启动并连接 exe async function openExe (xw) { await new Promise((resolve, reject) => { xw.exe.open(() => { // 启动并连接 exe if (xw.exe.socketErr) { // exe 出错了 reject(new xw.BaseException(511)) } else { resolve() } }) }) } async function openIM (xw) { console.log('openIM', xw) await new Promise((resolve, reject) => { xw.im.init(() => { resolve() }, () => {}, xw) }) } async function openServiceSocket (xw) { await new Promise((resolve, reject) => { xw.webServiceSocket.open(() => { if (xw.webServiceSocket.socketErr) { reject(new xw.BaseException(514)) } else { resolve() } }) }) } // 登录华为平台(签入) async function loginIn (xw) { const huawei = createLongin(xw) await huawei.loginIn(xw.exe) } function heart (xw) { // nats 心跳检查 let USER_STATUS_HEART_CHECK = xw.getSysParam('USER_STATUS_HEART_CHECK') ? xw.getSysParam('USER_STATUS_HEART_CHECK') : 10 // let natsInterval = xw.heartInterval = setInterval(() => { if (xw.agentState !== '3') { changeEmployeeStatus(xw.agentState, xw, false) // exe心跳检查 xw.exe.emit('HeartbeatDetection', {}) } }, USER_STATUS_HEART_CHECK * 1000) xw.exe.on('OnHeartbeatDetection', data => { if (data.resultCode !== 0) { changeEmployeeStatus('3', xw) // window.app.$store.commit('M_SYS_LOGIN_STATUS', { dispatch: false, monitor: false, cluster: false }) xw.sysLoginStatus = { dispatch: false, monitor: false, cluster: false, phone: false } } }) } // 系统监听事件 function systemListen (xw) { // webServiceSocket 监听 122 点呼走会议---vc xw.webServiceSocket.on('122', (data) => { const content = JSON.parse(htmlEscapeBack(data.content)) console.log(content) if (xw.getSysParam('PLATFORM_VERSON') === '2') { xw.exe.emit('SetVideoCallUseConf', { isCaller: '0', // 主叫1 被叫0 callId: '' }) } // else { // const params = { // 眼镜会议的exe参数 // resId: xw.userInfo.ICP_CODE, // memberInfo: [{ // memberId: content.ICP_CODE, // memberName: content.USER_NAME, // isMute: '1', // isCamera: '0', // isWatchOnly: '0' // }] // } // sendGlassPiontCallMessage(content.USER_CODE, xw) // 点呼之前发送信息给对端 // xw.exe.emit('CreateGlassConf', params) // } }) // webServiceSocket 监听 333 点呼走会议 --- icp xw.webServiceSocket.on('333', data => { console.log('333', data) const content = data.content const memberInfo = [ { memberId: content.ICP_CODE, memberName: content.USER_NAME, isMute: '1', isCamera: '0', glassNum: '', isWatchOnly: '0' } ] xw.ajaxRequest([{ service: 'E2601501', CREATE_MEET_FLAG: '1', MEETING_NAME: '移动点呼会议', MEETING_TYPE: 1, // 1 融合会议 MEDIAENCRYPTTYPE: 0, DURATION: 1000, HOST_USER: xw.userInfo.USER_CODE, MEET_START_ID: xw.userInfo.USER_CODE, MEMBERS: [], // 与会人员 CONTINUOUSPRESENCEMODE: '0' }]).then(res => { if (res.code === '0') { const meetingData = res.data[0] xw.exe.emit('CreateICPConfUseVideoCall', { resId: xw.userInfo.ICP_CODE, isVideo: '1', memberInfo }).once('OnCreateConf', result => { if (result.resultCode === 0) { meetingData.MEETING_ID = result.data.confId callAccept(data.sendId, meetingData, xw) } }) } }) }) } let htmlEscapeBack = html => { const reg = /(&lt;)|(&gt;)|(&amp;)|(&quot;)/g return html.replace(reg, function (match) { switch (match) { case '&lt;': return '<' case '&gt;': return '>' case '&amp;': return '&' case '&quot;': return '"' } }) } // 监听加入预约会议事件 let listenJoinMeeting = (xw) => { xw.exe.on('OnCalleeJoinConf', (res) => { xw.exe.emit('WriteBrowserLog', { logStr: 'OnCalleeJoinConf' }) if (res.resultCode === 0) { // 调用后台接口修改会议入会信息(入参内部会议ID,ICP会议ID) let MEETING = res.data.confId xw.ajaxRequest([{ service: 'E2601329', MEETING_ID: MEETING }]) .then(res => { xw.exe.emit('WriteBrowserLog', { logStr: `调用E2601329结果:${JSON.stringify(res)}` }) let location = {} console.log('走到这里了') let USER_CODE = res.data[0].CREATE_USER let MDP_MEETING_SNO = res.data[0].MEETING_SNO let MDP_MEETING_NAME = res.data[0].MEETING_SNO let MEETING_ID = res.data[0].MEETING_ID console.log(xw.userInfo.USER_CODE, USER_CODE) if (+USER_CODE === +xw.userInfo.USER_CODE) { let url = xw.icpBaseUrl + 'exe/implant-meeting?USER_CODE=' + xw.userInfo.USER_CODE + '&LANGUAGE=ZH_CN&MDP_MEETING_SNO=' + MDP_MEETING_SNO + '&ROLE_ID=' + xw.userInfo.CURR_ROLE + '&MEET_PLAN_TYPE=&MDP_MEETING_ID=' + MEETING_ID xw.exe.emit('SetConfUrl', { confName: MDP_MEETING_NAME, confUrl: url, locX: location ? location.locX : '', locY: location ? location.locY : '', width: location ? location.width : '', height: location ? location.height : '' }) } else { console.log('你不是主席') } }) .catch(() => { console.log('发生错误了') }) } else { console.log('发生错误了') } }) }