Clear javascript Websocket buffer

I am trying to write javacript to get mjpeg using websocket. The client can select the video file to play.

The server sends mjpeg as an image one by one using json: {"Image": "base64_image"}

The problem occurs when a client tries to select another video. It takes more than 2 minutes to edit a new video file. (The server and client are in different countries, though.)

I know there is a delay, but the thing

The longer I open the previous video file, the slower the next video file is displayed.

I assume there is a data queue in the buffer. So my question is:

How can I flush this socket buffer in javascript?

or if it's not about the buffer, any idea what the problem is?

+4
source share
1 answer

Without any code example, the problem most likely is that your websocket client is flooded with a fire hose coming from the server.

Most likely, you could adjust this by getting a websocket client poll for the next frame when it is ready to process it. The advantage of this is that you could stop polling for frames for asset X and start polling for frames from asset Y.

Of course, it is assumed that the problem is related to the client side ... if it downloads all the videos on your server, etc. and canโ€™t โ€œreleaseโ€ the video to switch to another, then this is different on the server.

However, this is not a good use case for websites ... they are great for small data packages ... is this just an experiment?

0
source

Source: https://habr.com/ru/post/1483941/


All Articles