Client-side "User Data Streams" WebSocket connection closes every 1~2minutes

I have made connection to the User Data Streams socket on the client-side of a javascript (ReactJS) application, using new WebSocket(wss://stream.binance.com:9443/ws/). I’m receiving messages from the user data stream, however it disconnects with type “close” every 1~2minutes.

The native javascript WebSocket API doesn’t have a ping or pong method, how do I receive the ping’s? I’m not seeing pings in the ws.onmessage method and when I try ws.send I receive an error that the message doesn’t have a “method” field.

Is the connection closing because it hasn’t received a pong, or is it unrelated?

I’ve been able to keep it open to 5minutes by requesting the “LIST_SUBSCRIPTIONS” endpoint every 60 seconds, as the above issue seems to be a browser specific issue where the sockets are closed if no activity is received within last minute or so.

So now the issue becomes, how do we keep the socket open more than 5minutes?

Just for reference on the ping/pong disconnection, the API doc says:

The websocket server will send a ping frame every 3 minutes. If the websocket server does not receive a pong frame back from the connection within a 10 minute period, the connection will be disconnected. Unsolicited pong frames are allowed.

As for keeping the socket open, maybe you can follow https://github.com/binance/binance-connector-node/blob/ef04ed3ddb139b9f0695af33e013a8516bef72ed/src/modules/websocket.js#L221 to write your code, or directly use the SDK (binance-connector-node).

Thanks @aisling for your response. Today it appears that with the browser fix, the socket is remaining open