00);

                document.getElementById('connectBtn').disabled = true;
                document.getElementById('disconnectBtn').disabled = false;
            };

            socket.onmessage = function (event) {
                messagesReceived++;
                updateStats();

                try {
                    const data = JSON.parse(event.data);
                    addMessage('received', event.data, true);

                    if (data.type === 'welcome') {
                        addMessag