diff --git a/app.js b/app.js index 0d71de8..f0b5542 100644 --- a/app.js +++ b/app.js @@ -250,6 +250,7 @@ mesh = new MeshNet(); mesh.playerName = name; mesh.names.set(mesh.myPeerId, name || mesh.myPeerId.slice(0, 8)); + mesh.onchat = (peerId, text) => addChatMessage(mesh.getPeerName(peerId), text); mesh.onpeerconnect = pid => { renderPlayers('host-player-list'); @@ -316,6 +317,7 @@ mesh = new MeshNet(); mesh.playerName = name; mesh.names.set(mesh.myPeerId, name || mesh.myPeerId.slice(0, 8)); + mesh.onchat = (peerId, text) => addChatMessage(mesh.getPeerName(peerId), text); show('join'); $('join-answer-section').hidden = true; $('join-scan-status').textContent = 'QR-Code scannen...'; @@ -406,4 +408,28 @@ show('start'); }); + /* ─── Debug chat ─── */ + const chatInput = $('debug-chat-text'); + const chatMessages = $('debug-chat-messages'); + + function addChatMessage(from, text) { + if (!chatMessages) return; + const div = document.createElement('div'); + div.textContent = `${from}: ${text}`; + chatMessages.appendChild(div); + chatMessages.scrollTop = chatMessages.scrollHeight; + } + + $('debug-chat-send').addEventListener('click', () => { + const text = chatInput.value.trim(); + if (!text || !mesh) return; + mesh.broadcast({ type: 'chat', text }); + addChatMessage('Du', text); + chatInput.value = ''; + }); + + chatInput.addEventListener('keydown', e => { + if (e.key === 'Enter') $('debug-chat-send').click(); + }); + })(); diff --git a/index.html b/index.html index 32c3acb..13de288 100644 --- a/index.html +++ b/index.html @@ -121,6 +121,13 @@ +