const socket = new WebSocket('wss://game.example.com/ws/updates');
socket.onopen = function () {
setInterval(function() {
if (socket.bufferedAmount == 0)
socket.send(getUpdateData());
}, 50);
};
socket.onmessage = function(event) {
handleUpdateData(event.data);
};
socket.onclose = function(event) {
onSocketClose(event);
};
socket.onerror = function(event) {
onSocketError(event);
};