This commit is contained in:
2023-12-02 18:44:35 +08:00
parent 460ede57d2
commit 3688c421dc
16 changed files with 251 additions and 128 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -593,6 +593,7 @@ export default {
msgTypeLabel = '[视频通话]'
}
var userInfo = store.state.userInfo;
const _userInfo = uni.getStorageSync("userInfo")
store.dispatch('createChatObj', {
userId: userId,
windowType: windowType,
@@ -655,7 +656,7 @@ export default {
userId: userInfo.userId,
personId: userInfo.userId,
nickName: userInfo.nickName,
portrait: userInfo.portrait,
portrait: _userInfo.photo,
msgType: msgType,
content: msgContent,
time: time,

View File

@@ -8,15 +8,14 @@ import lim from "@/common/imSdk/sdk-bridge.js";
import publicFc from '@/common/publicFc';
import localForage from 'localforage';
import { getCurrentInstance } from 'vue'
let __that = this
export default {
socketTask: null,
retimer: null,
// 连接WebSocket
connectSocket() {
connectSocket(successCallBack = null, errorCallBack = null) {
const ListenerMap = {
onSocketConnectEvent: (option, status, data) => {
@@ -24,16 +23,26 @@ export default {
},
onSocketErrorEvent: (error) => {
console.log("连接出现错误:" + userId);
this.socketTask = null
clearInterval(this.retimer)
this.retimer = null
console.log("开始定时重连");
this.retimer = setInterval(() => {
this.connectSocket()
}, 2000)
},
onSocketReConnectEvent: () => {
console.log("正在重连:");
},
onSocketCloseEvent: () => {
console.log("连接关闭:");
console.log(__that)
__that.$socketTask.socketTask=null;
__that.$socketTask.connectSocket()
this.socketTask = null
clearInterval(this.retimer)
this.retimer = null
console.log("开始定时重连");
this.retimer = setInterval(() => {
this.connectSocket()
}, 2000)
},
onSocketReConnectSuccessEvent: () => {
console.log("重连成功");
@@ -72,7 +81,7 @@ export default {
console.log(e)
console.log("接收到的ws格式化之后数据")
const _data = publicFc.formatMessage(e.data)
console.log(_data)
console.log(_data)
uni.$emit('onP2PMessage', _data);
store.dispatch('onP2PMessage', _data)
},
@@ -96,6 +105,8 @@ export default {
// 防止多次建立ws链接貌似还没有生效需要检查
if (this.socketTask != null) {
clearInterval(this.retimer)
this.retimer = null
return false
}
@@ -108,6 +119,11 @@ export default {
console.log('sdk 成功连接的回调, 可以使用 sdk 请求数据了.');
if (this.retimer != null) {
clearInterval(this.retimer)
this.retimer = null
}
sdk.getSingleUserInfo(userId).then(res => {
console.log("获取到自己的用户信息")
console.log(res)
@@ -199,4 +215,8 @@ export default {
console.log('关闭WebSocket');
}
},
reconnect() {
this.socketTask = null;
this.connectSocket()
}
}