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
wherepage
is the page number parameter, andlimit
gets the number of messages per page. That means I can passpage
andlimit
to get previous chat records - I am calling the
ws protocol
interface in thecreate
hook function, starting withpage=1
,limit=10
, and then scrolling up to the top to changepage=page+1
to continue to requestws 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