Ask questions about the websocket chat record of the front-end chat.

problem description

the company currently needs to use the customer service chat function. It uses vue+element to manage the background. The actual situation is as follows:

  • at present, an API with ws protocol in the background can connect websocket to chat. The background interface is similar to this: ws://host/chat?id=xx&page=x&limit=xx where page is the page number parameter, and limit gets the number of messages per page. That means I can pass page and limit to get previous chat records
  • I am calling the ws protocol interface in the create hook function, starting with page=1 , limit=10 , and then scrolling up to the top to change page=page+1 to continue to request ws protocol interface.

problems

am I doing the right thing? Because in this way, every time I scroll to the top, I will create a new websocket connection, and whenever I finish getting the message record, I have to close this websocket connection immediately, and if there is a new message coming, both websocket connections will push the message to me, and a message will be repeated twice, right?

places to ask for advice

I don"t know if you have made similar requirements, how to solve them, and do you want to save the chat records at the front end? Where is the right place to exist, how much data can the browser store, and which storage is better? Thank you in advance here

Apr.22,2021

websocket is designed to push messages to you in real time, not for you to use as ajax to get historical messages. You are getting historical news from the backstage. Why do you keep chat records at the front desk? As soon as the page opens and connects to websocket, you don't have to close it.


A room conversation is fine with a ws connection.
every time the data is passed, you render the tag. Do you need anything to save?


chat records are not pushed, they should be obtained by yourself, and have nothing to do with websocket

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c461-2c304.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c461-2c304.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?