修改消息拉取记录

This commit is contained in:
2023-12-04 22:25:19 +08:00
parent 6f690c1987
commit d2a3af7f1f
4 changed files with 262 additions and 110 deletions

View File

@@ -92,6 +92,8 @@ export default {
isForce: "0", isForce: "0",
hasVideo: "1", hasVideo: "1",
callSessionId: "", callSessionId: "",
callStatus: "watting",//房间状态
callRoomInfoRequetTimes:0,//房间拉取次数
}; };
}, },
mounted() { mounted() {
@@ -434,7 +436,10 @@ export default {
}).then(res => { }).then(res => {
if (res.status == 200) { if (res.status == 200) {
this.generateVideoRoomStream(res.data.data) this.generateVideoRoomStream(res.data.data)
}else {
this.generateVideoRoomStream([])
} }
//TODO 增加网络异常时候的处理
}) })
}, },
leaveRoom() { leaveRoom() {
@@ -527,6 +532,14 @@ export default {
}) })
}, },
generateVideoRoomStream(videoList) { generateVideoRoomStream(videoList) {
this.callRoomInfoRequetTimes=this.callRoomInfoRequetTimes+1;
if(this.callRoomInfoRequetTimes>5){
if(videoList.length==0){
// 拉取5次房间列表之后如果房间里面视频流的数量为0则关掉房间
this.videoDownAction()
}
}
let hasUpdate = false; let hasUpdate = false;
if (this.oldVideoStreamList == null) { if (this.oldVideoStreamList == null) {
this.oldVideoStreamList = videoList; this.oldVideoStreamList = videoList;

View File

@@ -2,7 +2,7 @@ import http from '@/common/request'
import browser from '@/common/browser' import browser from '@/common/browser'
import store from '../store' import store from '../store'
import pinyin from '@/common/pinyin.js'; import pinyin from '@/common/pinyin.js';
import dayjs from "dayjs" import dayjs from "dayjs"
import localForage from 'localforage'; import localForage from 'localforage';
@@ -682,7 +682,7 @@ export default {
// TODO // TODO
// 发送完成之后设置消息状态 // 发送完成之后设置消息状态
//TODO //TODO
// msgSendType = 'error'; // msgSendType = 'error';
msgOffline.sendtype = msgSendType; msgOffline.sendtype = msgSendType;
msgOffline.msgId = "1231" msgOffline.msgId = "1231"
@@ -693,10 +693,23 @@ export default {
if (msgSendType == 'error') { if (msgSendType == 'error') {
chatWindowData.push(msgNotSend); chatWindowData.push(msgNotSend);
} }
// TODO 内网环境下特殊配置,消息返送出去之后不直接存储
/*
store.dispatch('updateChatById', { store.dispatch('updateChatById', {
userId: userId, userId: userId,
data: chatWindowData data: chatWindowData
}); });
*/
setTimeout(() => {
store.dispatch('updateChartHistoryFromServerLimit5', {
userId: userId,
data: {
}
});
}, 500)
store.dispatch('updateChatListInfoById', { store.dispatch('updateChatListInfoById', {
userId: userId, userId: userId,
data: msgList data: msgList
@@ -999,16 +1012,16 @@ export default {
}); });
// #endif // #endif
}, },
formatMessage(msg){ formatMessage(msg) {
msg.pushType="MSG" msg.pushType = "MSG"
var msgType="TEXT" var msgType = "TEXT"
var data = store.state.addressList var data = store.state.addressList
const fromUserData=data.find(item=>item.userId==msg.fromId) const fromUserData = data.find(item => item.userId == msg.fromId)
const _data=JSON.parse(msg.messageBody) const _data = JSON.parse(msg.messageBody)
// try{ // try{
// console.log("=======================formatMessage") // console.log("=======================formatMessage")
// console.log(_data) // console.log(_data)
@@ -1018,24 +1031,24 @@ export default {
// console.error(e) // console.error(e)
// //TODO handle the exception // //TODO handle the exception
// } // }
msg.msgContent={ msg.msgContent = {
msgType:_data.msgType, msgType: _data.msgType,
content:_data.content, content: _data.content,
disturb:false, disturb: false,
top:false, top: false,
} }
msg.windowType="SINGLE" msg.windowType = "SINGLE"
msg.createTime=msg.messageTime; msg.createTime = msg.messageTime;
msg.userId=msg.fromId; msg.userId = msg.fromId;
msg.fromInfo={ msg.fromInfo = {
userId:msg.fromId, userId: msg.fromId,
userType:1, userType: 1,
nickName:fromUserData?fromUserData.realname:msg.fromId, nickName: fromUserData ? fromUserData.realname : msg.fromId,
portrait:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png" portrait: "https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png"
}; };
msg.groupInfo={}; msg.groupInfo = {};
msg.msgId=msg.messageKey; msg.msgId = msg.messageKey;
return msg return msg

View File

@@ -5,7 +5,7 @@ import * as sdk from "@/common/imSdk/lim-sdk.js";
import lim from "@/common/imSdk/sdk-bridge.js"; import lim from "@/common/imSdk/sdk-bridge.js";
import localForage from 'localforage'; import localForage from 'localforage';
import dayjs from "dayjs" import dayjs from "dayjs"
const _im = lim.lim.im const _im = lim.lim.im
function sortBy(field) { function sortBy(field) {
@@ -138,13 +138,126 @@ const store = new Vuex.Store({
}) })
}) })
}, },
updateChartHistoryFromServerLimit5(context, data) {
updateChartHistoryFromServer(context, data) {
const _userId = uni.getStorageSync("userId") const _userId = uni.getStorageSync("userId")
const _userInfo = uni.getStorageSync("userInfo") const _userInfo = uni.getStorageSync("userInfo")
var retdata = publicFc.getKeyObjectStorage(_userId + '_' + 'chatData') var retdata = publicFc.getKeyObjectStorage(_userId + '_' + 'chatData')
var currentUserMsgList = retdata[data.userId].list var currentUserMsgList = retdata[data.userId].list
console.warn(currentUserMsgList)
// if
_im.getSingleUserInfo(data.userId).then((res) => {
var detail = res.data
let _msgList = {
fromInfo: {
nickName: detail.nickName,
portrait: detail.photo,
userId: detail.userId,
userType: detail.userType
},
groupInfo: {},
list: []
}
var _serverMsgList = []
_im.getChatMessageHistoryList(data.userId, 1, 5).then((res) => {
res.data.map((item) => {
item.messageBody = JSON.parse(item.messageBody)
var obj = {
content: item.messageBody.content,
messageKey: item.messageKey,
msgType: item.messageBody.msgType,
nickName: _userId == item.fromId ? "我" :
detail.nickName,
portrait: _userId == item.fromId ? _userInfo
.photo : detail.photo,
personId: item.fromId,
sendtype: "waiting",
time: item.createTime,
type: _userId == item.fromId ? 2 : 1,
userId: item.fromId,
windowType: "SINGLE"
}
var _arr = currentUserMsgList.filter(obj => obj
.messageKey === item.messageKey)
if (_arr.length == 0) {
_serverMsgList.push(obj)
}
})
const reversedServerMsgList = _serverMsgList.reverse();
console.log("新的未收消息数组")
console.log(reversedServerMsgList)
let newCurrentUserMsgList = currentUserMsgList.concat(
reversedServerMsgList)
_serverMsgList = currentUserMsgList.sort(sortBy('time'))
_msgList.list = newCurrentUserMsgList;
retdata[data.userId] = _msgList
uni.setStorageSync(_userId + '_' + 'chatData', JSON.stringify(
retdata));
context.dispatch('getchatDatalist');
if (reversedServerMsgList.length > 0) {
uni.$emit('PageScroll', {
msg: '页面更新'
})
}
const _obj = newCurrentUserMsgList[newCurrentUserMsgList
.length - 1]
try {
var _content = JSON.parse(_obj.content)
if (_obj.msgType == "CALL_video") {
_obj.content = "【视频通话】"
}
if (_obj.msgType == "CALL_voice") {
_obj.content = "【语音通话】"
}
//判断头像是谁的
context.dispatch('updateChatListInfoById', {
userId: data.userId,
data: {
content: _obj.content,
userId: data.userId,
personId: _userId,
nickName: detail.nickName,
portrait: _userId == _obj.fromId ? _userInfo
.photo : detail.photo,
time: dayjs(_obj.createTime).format(
"YYYY/MM/DD HH:mm:ss"),
num: 0,
windowType: 'SINGLE',
disturb: 'N', //是否静默消息
top: 'N', //是否置顶
userType: 'SINGLE'
}
})
} catch (e) {
console.log(e)
//TODO handle the exception
}
})
})
},
updateChartHistoryFromServer(context, data) {
const _userId = uni.getStorageSync("userId")
const _userInfo = uni.getStorageSync("userInfo")
var retdata = publicFc.getKeyObjectStorage(_userId + '_' + 'chatData')
// if // if
_im.getSingleUserInfo(data.userId).then((res) => { _im.getSingleUserInfo(data.userId).then((res) => {
@@ -161,69 +274,70 @@ const store = new Vuex.Store({
} }
var _serverMsgList = [] var _serverMsgList = []
_im.getChatMessageHistoryList(data.userId, 1, 100).then((res) => { _im.getChatMessageHistoryList(data.userId, 1, 100).then((res) => {
res.data.map((item)=>{ res.data.map((item) => {
item.messageBody=JSON.parse(item.messageBody) item.messageBody = JSON.parse(item.messageBody)
var obj={ var obj = {
content:item.messageBody.content, content: item.messageBody.content,
messageKey:item.messageKey, messageKey: item.messageKey,
msgType:item.messageBody.msgType, msgType: item.messageBody.msgType,
nickName:_userId==item.fromId?"我":detail.nickName, nickName: _userId == item.fromId ? "我" :
portrait:_userId==item.fromId?_userInfo.photo:detail.photo, detail.nickName,
personId:item.fromId, portrait: _userId == item.fromId ? _userInfo
sendtype:"waiting", .photo : detail.photo,
time:item.createTime, personId: item.fromId,
type:_userId==item.fromId?2:1, sendtype: "waiting",
userId:item.fromId, time: item.createTime,
windowType:"SINGLE" type: _userId == item.fromId ? 2 : 1,
} userId: item.fromId,
/* windowType: "SINGLE"
if(obj.msgType=="CALL_video"){ }
obj.content=JSON.parse(item.messageBody.content)
obj.content=JSON.parse(obj.content)
}
*/
_serverMsgList.push(obj)
})
_serverMsgList = _serverMsgList.sort(sortBy('time')) _serverMsgList.push(obj)
_msgList.list=_serverMsgList; })
retdata[data.userId] = _msgList
uni.setStorageSync(_userId + '_' + 'chatData', JSON.stringify(
retdata));
context.dispatch('getchatDatalist'); _serverMsgList = _serverMsgList.sort(sortBy('time'))
const _obj=_serverMsgList[_serverMsgList.length-1] _msgList.list = _serverMsgList;
var _content=JSON.parse(_obj.content) retdata[data.userId] = _msgList
uni.setStorageSync(_userId + '_' + 'chatData', JSON.stringify(
retdata));
if(_obj.msgType=="CALL_video"){ context.dispatch('getchatDatalist');
_obj.content="【视频通话】"
}
if(_obj.msgType=="CALL_voice"){ const _obj = _serverMsgList[_serverMsgList.length - 1]
_obj.content="【语音通话】"
}
//判断头像是谁的
context.dispatch('updateChatListInfoById',{ var _content = JSON.parse(_obj.content)
userId:data.userId,
data:{ if (_obj.msgType == "CALL_video") {
content:_obj.content, _obj.content = "【视频通话】"
userId: data.userId, }
personId: _userId,
nickName: detail.nickName, if (_obj.msgType == "CALL_voice") {
portrait:_userId==_obj.fromId?_userInfo.photo:detail.photo, _obj.content = "【语音通话】"
time: dayjs(_obj.createTime).format("YYYY/MM/DD HH:mm:ss"), }
num: 0, //判断头像是谁的
windowType: 'SINGLE',
disturb: 'N', //是否静默消息 context.dispatch('updateChatListInfoById', {
top: 'N', //是否置顶 userId: data.userId,
userType: 'SINGLE' data: {
} content: _obj.content,
}) userId: data.userId,
personId: _userId,
nickName: detail.nickName,
portrait: _userId == _obj.fromId ? _userInfo
.photo : detail.photo,
time: dayjs(_obj.createTime).format(
"YYYY/MM/DD HH:mm:ss"),
num: 0,
windowType: 'SINGLE',
disturb: 'N', //是否静默消息
top: 'N', //是否置顶
userType: 'SINGLE'
}
})
}) })
}) })

View File

@@ -1,9 +1,9 @@
<template> <template>
<view> <view>
<view class="chatNavBar"> <view class="chatNavBar">
<uni-nav-bar :leftIcon="isMobile==true?'left':''" <uni-nav-bar :leftIcon="isMobile==true?'left':''" @clickLeft="clickLeftHandler">
@clickLeft="clickLeftHandler"> <view class="navBarTitle">{{title}}</view>
<view class="navBarTitle">{{title}}</view></uni-nav-bar> </uni-nav-bar>
</view> </view>
<watermark></watermark> <watermark></watermark>
<uni-popup ref="popup" type="center"> <uni-popup ref="popup" type="center">
@@ -199,6 +199,10 @@
}, },
onLoad(e) { onLoad(e) {
uni.$on('PageScroll', ()=>{
this.scrolltoBottom()
})
// // 监听接收聊天信息 // // 监听接收聊天信息
uni.$on('onP2PMessage', this.onMessage) uni.$on('onP2PMessage', this.onMessage)
@@ -280,6 +284,8 @@
if (hd_gps_location != null) { if (hd_gps_location != null) {
this.isMobile = true this.isMobile = true
} }
// TODO PC开发
this.isMobile = true
if (this.chatListInfo && this.chatListInfo.nickName) { if (this.chatListInfo && this.chatListInfo.nickName) {
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
@@ -356,6 +362,7 @@
//如果当前消息发送人和当前窗口的聊天对象一致,则发送已读回执 //如果当前消息发送人和当前窗口的聊天对象一致,则发送已读回执
console.log("########### 此时需要发送已读回执 ###########") console.log("########### 此时需要发送已读回执 ###########")
this.$store.dispatch('sendP2PMessageReciveAck', message) this.$store.dispatch('sendP2PMessageReciveAck', message)
}, },
addMsg(e) { addMsg(e) {
this.msg += e; this.msg += e;
@@ -888,6 +895,11 @@
console.log("==============sdk:") console.log("==============sdk:")
console.log(this.talkTo.userId) console.log(this.talkTo.userId)
setTimeout(() => {
this.scrolltoBottom();
}, 1000)
// this.imsdk.lim.im.sendP2PMessage(this.imsdk.lim.im.createP2PTextMessage(this.talkTo.userId, e)) // this.imsdk.lim.im.sendP2PMessage(this.imsdk.lim.im.createP2PTextMessage(this.talkTo.userId, e))
// #endif // #endif
@@ -957,9 +969,8 @@
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.navBarTitle {
.navBarTitle{ width: 100%;
width: 100%;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
@@ -967,6 +978,7 @@
font-size: 16px !important; font-size: 16px !important;
font-weight: bold !important; font-weight: bold !important;
} }
.chatNavBar { .chatNavBar {
position: fixed; position: fixed;
top: 0; top: 0;