实时通讯bug解决

main
xuan 1 month ago
parent a6c74706a7
commit 0f196ca887

@ -82,7 +82,8 @@
</template>
<script>
// import RecycleScroller from 'vue-virtual-scroller';
// import * as SockJS from 'sockjs-client';
// import { Stomp } from "stompjs/lib/stomp.js";
import HonneyBtn from './HonneyBtn.vue';
import ChatCard from './ChatCard.vue';
import ChatList from './ChatList.vue';
@ -177,6 +178,7 @@ export default {
this.get_friendsInfoList()
this.long_poll_serve()
// this.websocket_serve()
},
components:{
HonneyBtn,
@ -185,6 +187,25 @@ export default {
ChatList
},
methods:{
// async websocket_serve(){
// const socket = new SockJS('https://911fb0525ms3.vicp.fun//loveforest/ws');
// const stompClient = Stomp.over(socket);
// const userId = getUserId()
// stompClient.connect({}, function (frame) {
// console.log('Connected: ' + frame);
// // receiverId ID
// const receiverId = userId; // ID
// //
// stompClient.subscribe('/user/' + receiverId + '/queue/unread-messages', function (message) {
// const unreadMessage = JSON.parse(message.body);
// console.log('New unread message: ', unreadMessage);
// //
// });
// });
// },
async long_poll_serve(){
try{
const UserId = getUserId()
@ -200,14 +221,18 @@ export default {
console.log(senderId)
for(let i = 0;i<this.friendsInfoList.length;i++){
if(this.friendsInfoList[i].id == senderId){
let response2 = await axios.get(`/messages/chat/${UserId}/${senderId}`,{
headers:{Authorization : token}
})
if(this.friendsInfoList[i].chatHistory.slice(-1)[0].time == response2.data[response2.data.length-1].timestamp.replace('T',' ')){
break
}
console.log(this.friendsInfoList[i].chatHistory.slice(-1),response2.data[response2.data.length-1].timestamp.replace('T',' '))
if(this.chatWith != this.friendsInfoList[i].name){
this.friendsInfoList[i].unreading_num += 1
this.new_msg_nums += 1
}
let tempt_chat = {name:'',content:'',time:''}
let response2 = await axios.get(`/messages/chat/${UserId}/${senderId}`,{
headers:{Authorization : token}
})
tempt_chat.name = this.friendsInfoList[i].name
tempt_chat.content = response2.data[response2.data.length-1].content
tempt_chat.time = response2.data[response2.data.length-1].timestamp.replace('T',' ')

Loading…
Cancel
Save