diff --git a/.env b/.env new file mode 100644 index 0000000..a8f6152 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +VUE_APP_BASE_URL = https://k8s-horse-gateway.mashibing.cn +VUE_APP_STATIC_URL = https://k8s-shop-app.mashibing.cn +#VUE_APP_IM_URL = ws://192.168.10.94:8090 +VUE_APP_IM_URL = wss://k8s-horse-gateway.mashibing.cn \ No newline at end of file diff --git a/.env.bate b/.env.bate new file mode 100644 index 0000000..b223a6f --- /dev/null +++ b/.env.bate @@ -0,0 +1,3 @@ +VUE_APP_BASE_URL = https://you-gateway.mashibing.com +VUE_APP_STATIC_URL = https://you-gateway.mashibing.com +VUE_APP_IM_URL = wss://you-gateway.mashibing.com \ No newline at end of file diff --git a/.env.prod b/.env.prod new file mode 100644 index 0000000..b223a6f --- /dev/null +++ b/.env.prod @@ -0,0 +1,3 @@ +VUE_APP_BASE_URL = https://you-gateway.mashibing.com +VUE_APP_STATIC_URL = https://you-gateway.mashibing.com +VUE_APP_IM_URL = wss://you-gateway.mashibing.com \ No newline at end of file diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..16b6a5e --- /dev/null +++ b/.env.test @@ -0,0 +1,3 @@ +VUE_APP_BASE_URL = https://k8s-horse-gateway.mashibing.com +VUE_APP_STATIC_URL = https://k8s-shop-app.mashibing.com +VUE_APP_IM_URL = wss://k8s-horse-gateway.mashibing.cn \ No newline at end of file diff --git a/env.config.js b/env.config.js index e06c206..3e547a6 100644 --- a/env.config.js +++ b/env.config.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-05-05 14:40:00 * @LastEditors: ch - * @LastEditTime: 2022-05-26 19:04:26 + * @LastEditTime: 2022-06-09 11:25:44 * @Description: 根据git分支生成对应环境的环境变量 * 开发时如果环境变量换了,可以不用重启服务,直接运行node env.config.js即可 */ @@ -13,6 +13,7 @@ const envConfig = { dev : { baseUrl: 'https://k8s-horse-gateway.mashibing.cn', staticUrl : 'https://k8s-shop-app.mashibing.cn', + // imUrl : 'ws://192.168.10.94:8090' imUrl : 'wss://k8s-horse-gateway.mashibing.cn' }, test : { diff --git a/src/common/api/im.js b/src/common/api/im.js index 48358ac..60668d6 100644 --- a/src/common/api/im.js +++ b/src/common/api/im.js @@ -1,48 +1,16 @@ -// /* -// * @Author: ch -// * @Date: 2022-05-18 15:21:10 -// * @LastEditors: ch -// * @LastEditTime: 2022-05-18 17:24:37 -// * @Description: file content -// */ -// import { MsbSkt } from "../utils/webSkt"; -// import { CreateUUID } from '@/common/utils'; +/* + * @Author: ch + * @Date: 2022-05-27 17:44:36 + * @LastEditors: ch + * @LastEditTime: 2022-06-09 11:34:36 + * @Description: file content + */ +import {ToAsyncAwait, MsbRequestTk} from '@/common/utils'; +const BASE_URL = '/mall/im'; -// /** -// * 系统消息心跳 -// */ -// export const ApiSktSysHeart = () => MsbSkt.send({ -// traceId: CreateUUID(), -// traceType: '0', -// content: { text: "ping" } -// }); - -// /** -// * 获取系统通知会话 -// * @param {*} content -// */ -// export const ApiSktSysGetSession = (content) => MsbSkt.send({ -// traceId: CreateUUID(), -// traceType: '1', -// content -// }); - -// /** -// * 获取系统消息历史消息 -// * @param {*} content -// */ -// export const ApiSktSysGetHistory = (content) => MsbSkt.send({ -// traceId: CreateUUID(), -// traceType: '2', -// content -// }); - -// /** -// * 系统消息已读 -// * @param {*} content -// */ -// export const ApiSktSysGetHistory = (content) => MsbSkt.send({ -// traceId: CreateUUID(), -// traceType: '6', -// content -// }); \ No newline at end of file +/** + * 获取soket登录秘钥 + */ +export const ApiGetSoketTicket = () => ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/ticket`, { + ticketType: 'CONNECT_TICKET' +})); diff --git a/src/common/plugins/msbIm.js b/src/common/plugins/msbIm.js index 75986a4..b977b9b 100644 --- a/src/common/plugins/msbIm.js +++ b/src/common/plugins/msbIm.js @@ -2,362 +2,482 @@ * @Author: ch * @Date: 2022-05-18 14:54:47 * @LastEditors: ch - * @LastEditTime: 2022-05-24 22:51:47 + * @LastEditTime: 2022-06-14 17:24:14 * @Description: file content */ import { CreateUUID, FormatDate, ToAsyncAwait } from "@/common/utils"; -const connect = Symbol('connect'), - send = Symbol('send'), - onResponse = Symbol('onResponse'), - onMessage = Symbol('onMessage'), - updateData = Symbol('updateData') - ; -export default class MsbIm { - option = { - ioKey : 'traceId', - reconnect: true, - logout : false - } - socket = null; - queue = {}; - interceptors = { - dataChangeBefore: null, - dataChangeAfter: null, - onLogout : null, - onMessage: null - - }; - sessionData = []; - curSessionId = null; - - constructor(option) { - this.option = { - ...this.option, - ...option - } - } - /** - * 创建连接返回一个Promise 创建成功并成功打开连接算连接成功 - * @param {*} option - */ - - [connect](option) { - return new Promise((resolve, reject) => { - this.socket = uni.connectSocket({ - ...option, - fail(e){ - reject(e); - } - }); - this.socket.onOpen(() => { - this.socket.onMessage(async (res) => { - const result = JSON.parse(res.data); - if (result.content?.payload) { - result.content.payload = JSON.parse(result.content.payload); - } - // 401主动退出 - if (result.code === 401) { - this.logout(); - return false; - } - this.interceptors.onMessage && this.interceptors.onMessage(result); - // 处理服务端主动推送的消息 - this[onMessage](result); - - // 如果再消息堆里有此消息回调,则执行回调,并删除 - const cbk = this.queue[result[this.option.ioKey]]; - if (cbk) { - cbk(result.code !== 200 ? {error:result} : {result:result}); - delete this.queue[result[this.option.ioKey]]; - } - }) - resolve(this.socket); - }); - this.socket.onClose(() => { - if (this.option.reconnect && !this.option.logout) { - this[connect](); - } - this.option.logout = false; - }); - }); - } - /** - * 向服务端发送消息||请求,返回一个Promise对象,收到ioKey对应的消息会算一个同步完成 - * @param {*} data - */ - [send](data) { - return new Promise((resolve, reject) => { - this.queue[data[this.option.ioKey]] = ({result, error}) => { - if (result) { - resolve(result); - } else { - reject(error); - } - }; - this.socket.send({ - data : JSON.stringify(data), - fail(e) { - reject({error : e}); - } - }); - }) - } - /** - * 服务端推送消息,只处理服务端主动推送的消息 - * @param {*} data - */ - [onMessage](data) { - // 判断非服务端主动推送消息不做处理 - if (data[this.option.ioKey] || data.code !== 200) { - return false; - } - let ctx = data.content; - let historyData = [...this.sessionData], - newData = []; - const hisIndex = historyData.findIndex(i => i.id === ctx.sessionId); - if(hisIndex >= 0){ - // 存在会话往现有会话增加一条消息,并修改最后一条消息为当前消息 - const curHisData = historyData[hisIndex]; - curHisData.messageList.push(ctx); - curHisData.lastMessage = ctx; - // 不在当前会话窗口则向会话消息加1条未读 - if(ctx.sessionId !== this.curSessionId){ - curHisData.unreadCount++; - } - newData = historyData; - }else{ - // 会话列表不存在,则创建一个会话 - newData = [...historyData, { - fromAvatar : ctx.fromAvatar, - fromId : ctx.fromId, - fromNickname : ctx.fromNickname, - id : ctx.id, - lastMessage : ctx, - messageList : [ctx], - unreadCount : 1 - }] - } - this.setSessionData(newData) - - } - init (config) { - return new Promise((resolve, reject) => { - const heart = () => { - setTimeout(async () => { - await this[send]({ - traceId: CreateUUID(), - traceType: '0', - content: { text: "ping" } - }).catch((e)=>{}); - heart(); - },5000) - } - this[connect]({ - ...config, - }).then(() => { - heart(); - resolve(this); - }).catch((e)=>{}); - }) - - } - logout() { - this.option.logout = true; - this.socket.close(); - this.interceptors.onLogout && this.interceptors.onLogout(); - } - /** - * 设置数据 - */ - setSessionData(data) { - this.interceptors.dataChangeBefore && this.interceptors.dataChangeBefore(data, this.sessionData); - this.sessionData = data; - this.interceptors.dataChangeAfter && this.interceptors.dataChangeAfter(this.sessionData); - } - /** - * 设置当前聊天窗口 - * Data为Session数据 - * @param {*} data - */ - setCurSessionId(id) { - this.curSessionId = id; - } - /** - * 获取会话列表 - * @param {*} params - */ - async getSessionList(params) { - - let {error, result} = await ToAsyncAwait(this[send]({ - traceId: CreateUUID(), - traceType : 1, - ...params - })); - if (error) { - return Promise.reject(error); - } - const { content } = result; - content.sessionVOS.forEach(item => { - if (item.lastMessage) { - item.lastMessage.payload = JSON.parse(item.lastMessage.payload || {}); - } - let historyData = this.sessionData; - let hisIndex = historyData.findIndex(i => i.id === item.id); - if(hisIndex >= 0){ - historyData[hisIndex].lastMessage = item.lastMessage; - historyData[hisIndex].unreadCount++; - this.setSessionData(historyData) - }else{ - item.messageList = []; - const newData = [...historyData, item] - this.setSessionData(newData); - } - }); - return Promise.resolve(result); - } - /** - * 获取会话的历史消息记录 - * @param {*} params - */ - async getHistoryMsg(params) { - const {error, result} = await ToAsyncAwait(this[send]({ - traceId: CreateUUID(), - traceType: 23, - ...params - })); - if (error) { - return Promise.reject(error); - } - const { content } = result; - if (content.length) { - let newData = this.sessionData; - const hisIdx = newData.findIndex(i => i.id === content[0].sessionId); - content.forEach(item => { - item.payload = JSON.parse(item.payload) - }) - newData[hisIdx].messageList = newData[hisIdx].messageList.concat(content); - this.setSessionData(newData); - } - return Promise.resolve(result); - - } - /** - * 会话已读 - * @param {*} params - */ - async setRead (params){ - await this[send]({ - traceId : CreateUUID(), - traceType : "6", - ...params - }); - let newData = this.sessionData.map(item => { - if (item.id == params.content.sessionId) { - item.unreadCount = 0; - } - return item; - }); - - this.setSessionData(newData); - } - /** - * 发送消息 - * @param {*} params - */ - async sendMsg(params) { - const index = this.sessionData.findIndex(i => i.id === this.curSessionId) - let curSession = this.sessionData[index]; - // 临时消息体 - let par = { - ...params, - traceId: CreateUUID(), - traceType: 20, - } - let msgCtx = { - ...params.content, - ...par, - fromId: params.fromId, - createTimeStamp : (new Date()).getTime(), - sendStatus : 'loading' - } - // 点发送,立即把消息加入消息列表,标记为发送中状态 - curSession.messageList.push(msgCtx); - // 超过时间未返回视为发送失败 - this.timerStatus(msgCtx); - const { error, result } = await ToAsyncAwait(this[send](par)); - // 接到通知,标记消息是否发送成功 - for (let i = curSession.messageList.length; i--;) { - const item = curSession.messageList[i]; - if (item[this.option.ioKey] === par[this.option.ioKey]) { - curSession.messageList[i].sendStatus = msgCtx.sendStatus = error ? 'fail' : 'success'; - break; - } - } - let newData = [...this.sessionData]; - newData[index] = curSession; - this.setSessionData(newData); - if (error) { - return Promise.reject(error); - } +import './potoReq'; +import './protoRsp' +const connect = Symbol('connect'); +const send = Symbol('send'); +const onMessage = Symbol('onMessage'); +const fromatPotoReq = (traceId, traceType, content) => { + let messageModel = new proto.ReqModel(); + messageModel.setTraceid(traceId); + messageModel.setTracetype(traceType); + content && messageModel.setContent(JSON.stringify(content)); + return messageModel.serializeBinary(); + }, + fromatPotoRsp = (data) => { + const res = proto.RspModel.deserializeBinary(new Uint8Array(data)); + let ctx = res.getContent(); + ctx = ctx ? JSON.parse(ctx) : {}; + if (ctx.payload) { + ctx.payload = JSON.parse(ctx.payload); + } + return { + content: ctx, + traceId: res.getTraceid(), + traceType: res.getTracetype(), + code: res.getCode(), + message: res.getMessage(), + }; + }; - return Promise.resolve(result); - } - /** - * 发送失败时,重新发送 - * @param {*} params - */ - async resend(params) { - params.sendStatus = 'loading'; - this.timerStatus(params) - const { error, result } = await ToAsyncAwait(this[send]({ - traceId: params.traceId, - traceType: params.traceType, - content : params.content - })); - params.createTimeStamp = result.createTimeStamp; - if (error) { - params.sendStatus = 'fail'; - return Promise.reject(error); - } - params.sendStatus = 'success'; - return Promise.resolve(result); - } - timerStatus(msg) { - - setTimeout(() => { - if (msg.sendStatus === 'loading') { - msg.sendStatus = 'fail'; - delete this.queue[msg.traceId]; - } - }, 3000); - } - /** - * 主动创建会话 - * @param {*} params - */ - async createSession (params){ - const { result, error } = await ToAsyncAwait(this[send]({ - traceId : CreateUUID(), - traceType : 21, - ...params - })); - if (error) { - return Promise.reject(error); - } - const { content } = result; - let historyData = this.sessionData; - let curSession = historyData.find(i => i.id === content.id); - if (!curSession) { - curSession = { - ...content, - unreadCount: 0, - messageList : [] - } - const newData = [...historyData, curSession]; - this.setSessionData(newData); - } - return Promise.resolve(result); - } - -} \ No newline at end of file +class MsbIm { + defaultOption = { + ioKey: 'traceId', + reconnect: true, + }; + socket = null; + isOpen = false; + queue = {}; + interceptors = { + dataChangeBefore: null, + dataChangeAfter: null, + onClose: null, + onMessage: null, + }; + sessionData = []; + curSessionId = null; + constructor(option) { + this.option = { + ...this.defaultOption, + ...option, + }; + } + + /** + * 创建连接返回一个Promise 创建成功并成功打开连接算连接成功 + * @param {*} option + */ + [connect](option) { + return new Promise((resolve, reject) => { + const open = () => { + console.log('[im] open'); + this.isOpen = true; + resolve(this.socket); + }; + const message = async (res) => { + const result = fromatPotoRsp(res.data); + this.interceptors.onMessage && this.interceptors.onMessage(result); + // 处理服务端主动推送的消息 + this[onMessage](result); + + // 如果再消息堆里有此消息回调,则执行回调,并删除 + const cbk = this.queue[result[this.option.ioKey]]; + + if (cbk) { + cbk(result.code !== 200 ? { error: result } : { result: result }); + delete this.queue[result[this.option.ioKey]]; + } + }; + const close = () => { + console.log('[im] close'); + this.interceptors.onClose && this.interceptors.onClose(); + }; + let isUni = false; + try { + isUni = uni; + } catch (e) { + isUni = false; + } + if (isUni) { + this.socket = uni.connectSocket({ + ...this.option, + fail(e) { + reject(e); + }, + }); + this.socket.onOpen(() => { + open(); + this.socket.onMessage((res) => { + message(res); + }); + }); + this.socket.onClose(() => { + close(); + }); + } else if (WebSocket) { + try { + this.socket = new WebSocket(this.option.url); + this.socket.binaryType = 'arraybuffer'; + this.socket.onopen = () => { + open(); + }; + this.socket.onmessage = (res) => { + message(res); + }; + this.socket.onclose = () => { + close(); + }; + } catch (e) { + reject(e); + } + } + }); + } + /** + * 向服务端发送消息||请求,返回一个Promise对象,收到ioKey对应的消息会算一个同步完成 + * @param {*} data + */ + [send](data) { + return new Promise((resolve, reject) => { + if (!this.isOpen) { + return reject('连接未打开'); + } + this.queue[data[this.option.ioKey]] = ({ result, error }) => { + if (result) { + resolve(result); + } else { + reject(error); + } + }; + + const par = fromatPotoReq(data.traceId, data.traceType, data.content); + + let isUni = false; + try { + isUni = uni; + } catch (e) { + isUni = false; + } + if (isUni) { + this.socket.send({ + data: par, + fail(e) { + reject({ error: e }); + }, + }); + } else if (WebSocket) { + this.socket.send(par); + } + }); + } + /** + * 服务端推送消息,只处理服务端主动推送的消息 + * @param {*} data + */ + [onMessage](data) { + // 判断非服务端主动推送消息不做处理 + if (data[this.option.ioKey] || data.code !== 200) { + return false; + } + console.log('[im] 主动接收的消息', data); + let ctx = data.content; + let historyData = [...this.sessionData], + newData = []; + const hisIndex = historyData.findIndex((i) => i.id === ctx.sessionId); + if (hisIndex >= 0) { + // 存在会话往现有会话增加一条消息,并修改最后一条消息为当前消息 + const curHisData = historyData[hisIndex]; + curHisData.messageList.push(ctx); + curHisData.lastMessage = ctx; + // 不在当前会话窗口则向会话消息加1条未读 + if (ctx.sessionId !== this.curSessionId) { + curHisData.unreadCount++; + } else { + this.setRead({ + content: { + sessionId: this.curSessionId, + }, + }); + } + newData = historyData; + } else { + // 会话列表不存在,则创建一个会话 + newData = [ + ...historyData, + { + fromAvatar: ctx.session.fromAvatar, + fromId: ctx.session.fromId, + fromNickname: ctx.session.fromNickname, + id: ctx.sessionId, + lastMessage: ctx, + messageList: [ctx], + updateTimeStamp: ctx.createTimeStamp, + unreadCount: 1, + }, + ]; + } + this.setSessionData(newData); + } + init(config) { + return new Promise((resolve, reject) => { + const heart = () => { + // 要优化 心跳没回复需要重连 + setTimeout(async () => { + if (this.isOpen) { + await this[send]({ + traceId: CreateUUID(), + traceType: 0, + content: { text: 'ping' }, + }); + } + heart(); + }, 1000); + }; + this.option = { + ...this.option, + ...config, + }; + this[connect]() + .then((res) => { + resolve(res); + heart(); + }) + .catch((e) => { + console.log('eeeee', e); + }); + }); + } + /** + * 设置数据 + */ + setSessionData(data) { + let newData = JSON.parse(JSON.stringify(data)); + this.interceptors.dataChangeBefore && this.interceptors.dataChangeBefore(newData, this.sessionData); + this.sessionData = newData; + this.interceptors.dataChangeAfter && this.interceptors.dataChangeAfter(this.sessionData); + } + /** + * 设置当前聊天窗口 + * Data为Session数据 + * @param {*} data + */ + setCurSessionId(id) { + this.curSessionId = id; + } + /** + * 获取会话列表 + * @param {*} params + */ + async getSessionList(params) { + const par = { + traceId: CreateUUID(), + traceType: 1, + ...params, + }; + + console.log('[im] 获取会话列表--start', par); + let { error, result } = await ToAsyncAwait(this[send](par)); + console.log('[im] 获取会话列表--end', result, error); + if (error) { + return Promise.reject(error); + } + const { content } = result; + // let newData = []; + + content.sessionVOS.forEach((item) => { + if (item.lastMessage) { + item.lastMessage.payload = JSON.parse(item.lastMessage.payload || {}); + } + let historyData = this.sessionData; + let hisIndex = historyData.findIndex((i) => i.id === item.id); + if (hisIndex < 0) { + item.messageList = []; + } + // let historyData = this.sessionData; + // let hisIndex = historyData.findIndex((i) => i.id === item.id); + // if (hisIndex >= 0) { + // historyData[hisIndex].lastMessage = item.lastMessage; + // historyData[hisIndex].unreadCount++; + // newData.push(historyData[hisIndex]); + // } else { + // item.messageList = []; + // newData = [...newData, item]; + // } + }); + this.setSessionData(content.sessionVOS); + return Promise.resolve(result); + } + /** + * 获取会话的历史消息记录 + * @param {*} params + */ + async getHistoryMsg() { + const curSessionIdx = this.sessionData.findIndex((i) => i.id === this.curSessionId); + const curSession = this.sessionData[curSessionIdx]; + console.log(curSession, this.curSessionId, 'this.curSessionId'); + const msgList = curSession.messageList || []; + const par = { + traceId: CreateUUID(), + traceType: 2, + content: { + sessionId: this.curSessionId, + topMessageId: msgList.length ? msgList[0].id : null, + }, + }; + console.log('[im] 获取会话历史消息--start', par); + const { error, result } = await ToAsyncAwait(this[send](par)); + console.log('[im] 获取会话历史消息--end', result, error); + if (error) { + return Promise.reject(error); + } + const { content } = result; + if (content.length) { + let newData = this.sessionData; + content.forEach((item) => { + item.payload = JSON.parse(item.payload); + }); + newData[curSessionIdx].messageList = content.concat(newData[curSessionIdx].messageList); + this.setSessionData(newData); + } + return Promise.resolve(result); + } + /** + * 会话已读 + * @param {*} params + */ + async setRead(params) { + const par = { + traceId: CreateUUID(), + traceType: '6', + ...params, + }; + console.log('[im] 会话已读--start', par); + const { error, result } = await this[send](par); + console.log('[im] 会话已读--end', result, error); + + let newData = this.sessionData.map((item) => { + if (item.id == params.content.sessionId) { + item.unreadCount = 0; + } + return item; + }); + + this.setSessionData(newData); + } + /** + * 发送消息 + * @param {*} params + */ + async sendMsg(params) { + const index = this.sessionData.findIndex((i) => i.id === this.curSessionId); + let curSession = this.sessionData[index]; + // 临时消息体 + let par = { + ...params, + traceId: CreateUUID(), + traceType: 3, + }; + let msgCtx = { + ...params.content, + ...par, + createTimeStamp: new Date().getTime(), + sendStatus: 'loading', + }; + if (typeof msgCtx.payload === 'string') { + msgCtx.payload = JSON.parse(msgCtx.payload); + } + // 点发送,立即把消息加入消息列表,标记为发送中状态 + curSession.lastMessage = msgCtx; + curSession.messageList.push(msgCtx); + this.setSessionData(this.sessionData); + + // 超过时间未返回视为发送失败 + this.timerStatus(msgCtx); + + console.log('[im] 发送消息--start', par); + const { error, result } = await ToAsyncAwait(this[send](par)); + console.log('[im] 发送消息--end', result, error); + // 接到通知,标记消息是否发送成功 + for (let i = curSession.messageList.length; i--; ) { + const item = curSession.messageList[i]; + if (item[this.option.ioKey] === par[this.option.ioKey]) { + curSession.messageList[i].sendStatus = msgCtx.sendStatus = error ? 'fail' : 'success'; + break; + } + } + let newData = [...this.sessionData]; + curSession.lastMessage = msgCtx; + newData[index] = curSession; + this.setSessionData(newData); + if (error) { + return Promise.reject(error); + } + + return Promise.resolve(result); + } + /** + * 发送失败时,重新发送 + * @param {*} params + */ + async resend(params) { + params.sendStatus = 'loading'; + this.timerStatus(params); + + console.log('[im] 重新发送消息--start', params); + const { error, result } = await ToAsyncAwait( + this[send]({ + traceId: params.traceId, + traceType: params.traceType, + content: params.content, + }) + ); + console.log('[im] 重新发送消息--end', result, error); + params.createTimeStamp = result.createTimeStamp; + if (error) { + params.sendStatus = 'fail'; + return Promise.reject(error); + } + params.sendStatus = 'success'; + return Promise.resolve(result); + } + timerStatus(msg) { + setTimeout(() => { + if (msg.sendStatus === 'loading') { + msg.sendStatus = 'fail'; + delete this.queue[msg.traceId]; + } + }, 3000); + } + /** + * 主动创建会话 + * @param {*} params + */ + async createSession(params) { + const par = { + traceId: CreateUUID(), + traceType: 9, + ...params, + }; + console.log('[im] 主动创建会话--start', par); + const { result, error } = await ToAsyncAwait(this[send](par)); + console.log('[im] 主动创建会话--end', result, error); + if (error) { + return Promise.reject(error); + } + const { content } = result; + let historyData = this.sessionData; + let curSession = historyData.find((i) => i.id === content.id); + if (!curSession) { + curSession = { + ...content, + unreadCount: 0, + messageList: [], + }; + const newData = [...historyData, curSession]; + this.setSessionData(newData); + } + return Promise.resolve(result); + } + close() { + this.socket.close(); + this.socket = null; + this.isOpen = false; + this.setSessionData([]); + } +} +export default MsbIm; \ No newline at end of file diff --git a/src/common/plugins/potoReq.js b/src/common/plugins/potoReq.js new file mode 100644 index 0000000..3b7c03a --- /dev/null +++ b/src/common/plugins/potoReq.js @@ -0,0 +1 @@ +(()=>{var __webpack_modules__={19:function(__unused_webpack_module,exports,__webpack_require__){var $jscomp=$jscomp||{};$jscomp.scope={},$jscomp.findInternal=function(e,t,o){e instanceof String&&(e=String(e));for(var r=e.length,n=0;n=r}}),"es6","es3"),$jscomp.polyfill("Array.prototype.find",(function(e){return e||function(e,t){return $jscomp.findInternal(this,e,t).v}}),"es6","es3"),$jscomp.polyfill("String.prototype.startsWith",(function(e){return e||function(e,t){var o=$jscomp.checkStringArgs(this,e,"startsWith");e+="";var r=o.length,n=e.length;t=Math.max(0,Math.min(0|t,o.length));for(var s=0;s=n}}),"es6","es3"),$jscomp.polyfill("String.prototype.repeat",(function(e){return e||function(e){var t=$jscomp.checkStringArgs(this,null,"repeat");if(0>e||1342177279>>=1)&&(t+=t);return o}}),"es6","es3");var COMPILED=!0,goog=goog||{};goog.global=this||self,goog.isDef=function(e){return void 0!==e},goog.isString=function(e){return"string"==typeof e},goog.isBoolean=function(e){return"boolean"==typeof e},goog.isNumber=function(e){return"number"==typeof e},goog.exportPath_=function(e,t,o){e=e.split("."),o=o||goog.global,e[0]in o||void 0===o.execScript||o.execScript("var "+e[0]);for(var r;e.length&&(r=e.shift());)!e.length&&goog.isDef(t)?o[r]=t:o=o[r]&&o[r]!==Object.prototype[r]?o[r]:o[r]={}},goog.define=function(e,t){if(!COMPILED){var o=goog.global.CLOSURE_UNCOMPILED_DEFINES,r=goog.global.CLOSURE_DEFINES;o&&void 0===o.nodeType&&Object.prototype.hasOwnProperty.call(o,e)?t=o[e]:r&&void 0===r.nodeType&&Object.prototype.hasOwnProperty.call(r,e)&&(t=r[e])}return t},goog.FEATURESET_YEAR=2012,goog.DEBUG=!0,goog.LOCALE="en",goog.TRUSTED_SITE=!0,goog.STRICT_MODE_COMPATIBLE=!1,goog.DISALLOW_TEST_ONLY_CODE=COMPILED&&!goog.DEBUG,goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING=!1,goog.provide=function(e){if(goog.isInModuleLoader_())throw Error("goog.provide cannot be used within a module.");if(!COMPILED&&goog.isProvided_(e))throw Error('Namespace "'+e+'" already declared.');goog.constructNamespace_(e)},goog.constructNamespace_=function(e,t){if(!COMPILED){delete goog.implicitNamespaces_[e];for(var o=e;(o=o.substring(0,o.lastIndexOf(".")))&&!goog.getObjectByName(o);)goog.implicitNamespaces_[o]=!0}goog.exportPath_(e,t)},goog.getScriptNonce=function(e){return e&&e!=goog.global?goog.getScriptNonce_(e.document):(null===goog.cspNonce_&&(goog.cspNonce_=goog.getScriptNonce_(goog.global.document)),goog.cspNonce_)},goog.NONCE_PATTERN_=/^[\w+/_-]+[=]{0,2}$/,goog.cspNonce_=null,goog.getScriptNonce_=function(e){return(e=e.querySelector&&e.querySelector("script[nonce]"))&&(e=e.nonce||e.getAttribute("nonce"))&&goog.NONCE_PATTERN_.test(e)?e:""},goog.VALID_MODULE_RE_=/^[a-zA-Z_$][a-zA-Z0-9._$]*$/,goog.module=function(e){if(!goog.isString(e)||!e||-1==e.search(goog.VALID_MODULE_RE_))throw Error("Invalid module identifier");if(!goog.isInGoogModuleLoader_())throw Error("Module "+e+" has been loaded incorrectly. Note, modules cannot be loaded as normal scripts. They require some kind of pre-processing step. You're likely trying to load a module via a script tag or as a part of a concatenated bundle without rewriting the module. For more info see: https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide.");if(goog.moduleLoaderState_.moduleName)throw Error("goog.module may only be called once per module.");if(goog.moduleLoaderState_.moduleName=e,!COMPILED){if(goog.isProvided_(e))throw Error('Namespace "'+e+'" already declared.');delete goog.implicitNamespaces_[e]}},goog.module.get=function(e){return goog.module.getInternal_(e)},goog.module.getInternal_=function(e){if(!COMPILED){if(e in goog.loadedModules_)return goog.loadedModules_[e].exports;if(!goog.implicitNamespaces_[e])return null!=(e=goog.getObjectByName(e))?e:null}return null},goog.ModuleType={ES6:"es6",GOOG:"goog"},goog.moduleLoaderState_=null,goog.isInModuleLoader_=function(){return goog.isInGoogModuleLoader_()||goog.isInEs6ModuleLoader_()},goog.isInGoogModuleLoader_=function(){return!!goog.moduleLoaderState_&&goog.moduleLoaderState_.type==goog.ModuleType.GOOG},goog.isInEs6ModuleLoader_=function(){if(goog.moduleLoaderState_&&goog.moduleLoaderState_.type==goog.ModuleType.ES6)return!0;var e=goog.global.$jscomp;return!!e&&"function"==typeof e.getCurrentModulePath&&!!e.getCurrentModulePath()},goog.module.declareLegacyNamespace=function(){if(!COMPILED&&!goog.isInGoogModuleLoader_())throw Error("goog.module.declareLegacyNamespace must be called from within a goog.module");if(!COMPILED&&!goog.moduleLoaderState_.moduleName)throw Error("goog.module must be called prior to goog.module.declareLegacyNamespace.");goog.moduleLoaderState_.declareLegacyNamespace=!0},goog.declareModuleId=function(e){if(!COMPILED){if(!goog.isInEs6ModuleLoader_())throw Error("goog.declareModuleId may only be called from within an ES6 module");if(goog.moduleLoaderState_&&goog.moduleLoaderState_.moduleName)throw Error("goog.declareModuleId may only be called once per module.");if(e in goog.loadedModules_)throw Error('Module with namespace "'+e+'" already exists.')}if(goog.moduleLoaderState_)goog.moduleLoaderState_.moduleName=e;else{var t=goog.global.$jscomp;if(!t||"function"!=typeof t.getCurrentModulePath)throw Error('Module with namespace "'+e+'" has been loaded incorrectly.');t=t.require(t.getCurrentModulePath()),goog.loadedModules_[e]={exports:t,type:goog.ModuleType.ES6,moduleId:e}}},goog.setTestOnly=function(e){if(goog.DISALLOW_TEST_ONLY_CODE)throw e=e||"",Error("Importing test-only code into non-debug environment"+(e?": "+e:"."))},goog.forwardDeclare=function(e){},COMPILED||(goog.isProvided_=function(e){return e in goog.loadedModules_||!goog.implicitNamespaces_[e]&&goog.isDefAndNotNull(goog.getObjectByName(e))},goog.implicitNamespaces_={"goog.module":!0}),goog.getObjectByName=function(e,t){e=e.split("."),t=t||goog.global;for(var o=0;o>>0),goog.uidCounter_=0,goog.getHashCode=goog.getUid,goog.removeHashCode=goog.removeUid,goog.cloneObject=function(e){var t=goog.typeOf(e);if("object"==t||"array"==t){if("function"==typeof e.clone)return e.clone();for(var o in t="array"==t?[]:{},e)t[o]=goog.cloneObject(e[o]);return t}return e},goog.bindNative_=function(e,t,o){return e.call.apply(e.bind,arguments)},goog.bindJs_=function(e,t,o){if(!e)throw Error();if(2{"use strict";class X{constructor(){if(new.target!=String)throw 1;this.x=42}}let q=Reflect.construct(X,[],String);if(q.x!=42||!(q instanceof String))throw 1;for(const a of[2,3]){if(a==2)continue;function f(z={a}){let a=0;return z.a}{function f(){return 0;}}return f()==3}})()')})),a("es7",(function(){return b("2 ** 2 == 4")})),a("es8",(function(){return b("async () => 1, true")})),a("es9",(function(){return b("({...rest} = {}), true")})),a("es_next",(function(){return!1})),{target:c,map:d}},goog.Transpiler.prototype.needsTranspile=function(e,t){if("always"==goog.TRANSPILE)return!0;if("never"==goog.TRANSPILE)return!1;if(!this.requiresTranspilation_){var o=this.createRequiresTranspilation_();this.requiresTranspilation_=o.map,this.transpilationTarget_=this.transpilationTarget_||o.target}if(e in this.requiresTranspilation_)return!!this.requiresTranspilation_[e]||!(!goog.inHtmlDocument_()||"es6"!=t||"noModule"in goog.global.document.createElement("script"));throw Error("Unknown language mode: "+e)},goog.Transpiler.prototype.transpile=function(e,t){return goog.transpile_(e,t,this.transpilationTarget_)},goog.transpiler_=new goog.Transpiler,goog.protectScriptTag_=function(e){return e.replace(/<\/(SCRIPT)/gi,"\\x3c/$1")},goog.DebugLoader_=function(){this.dependencies_={},this.idToPath_={},this.written_={},this.loadingDeps_=[],this.depsToLoad_=[],this.paused_=!1,this.factory_=new goog.DependencyFactory(goog.transpiler_),this.deferredCallbacks_={},this.deferredQueue_=[]},goog.DebugLoader_.prototype.bootstrap=function(e,t){function o(){r&&(goog.global.setTimeout(r,0),r=null)}var r=t;if(e.length){t=[];for(var n=0;n<\/script>",t.write(goog.TRUSTED_TYPES_POLICY_?goog.TRUSTED_TYPES_POLICY_.createHTML(r):r)}else{var n=t.createElement("script");n.defer=goog.Dependency.defer_,n.async=!1,n.type="text/javascript",(r=goog.getScriptNonce())&&n.setAttribute("nonce",r),goog.DebugLoader_.IS_OLD_IE_?(e.pause(),n.onreadystatechange=function(){"loaded"!=n.readyState&&"complete"!=n.readyState||(e.loaded(),e.resume())}):n.onload=function(){n.onload=null,e.loaded()},n.src=goog.TRUSTED_TYPES_POLICY_?goog.TRUSTED_TYPES_POLICY_.createScriptURL(this.path):this.path,t.head.appendChild(n)}}else goog.logToConsole_("Cannot use default debug loader outside of HTML documents."),"deps.js"==this.relativePath?(goog.logToConsole_("Consider setting CLOSURE_IMPORT_SCRIPT before loading base.js, or setting CLOSURE_NO_DEPS to true."),e.loaded()):e.pause()},goog.Es6ModuleDependency=function(e,t,o,r,n){goog.Dependency.call(this,e,t,o,r,n)},goog.inherits(goog.Es6ModuleDependency,goog.Dependency),goog.Es6ModuleDependency.prototype.load=function(e){if(goog.global.CLOSURE_IMPORT_SCRIPT)goog.global.CLOSURE_IMPORT_SCRIPT(this.path)?e.loaded():e.pause();else if(goog.inHtmlDocument_()){var t=goog.global.document,o=this;if(goog.isDocumentLoading_()){var r=function(e,o){e=o?'