From 6b18e79b954010ed10c2292477a7b76d6e002bea Mon Sep 17 00:00:00 2001 From: Eyuep Sueyruege Date: Tue, 12 Dec 2023 20:49:02 +0100 Subject: [PATCH] Update src/client/main.js --- src/client/main.js | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/client/main.js b/src/client/main.js index 64a97c8..1b9c944 100644 --- a/src/client/main.js +++ b/src/client/main.js @@ -5,12 +5,40 @@ function startGame(){ let mainfield = $("#mainfield"); mainfield.html('
Player 1
Player 4
Mitte
Dealer
Player 2
Player 3
'); - - } -function refresh(){ +const socket = new WebSocket('ws://192.168.178.24:3001'); +socket.addEventListener('open', (event) => { + console.log('WebSocket-Verbindung hergestellt'); +}); + +socket.addEventListener('message', (event) => { + const messageDiv = document.getElementById('message'); + messageDiv.innerHTML = `${event.data}`; + +}); -} \ No newline at end of file +socket.addEventListener('close', (event) => { + console.log('WebSocket-Verbindung getrennt'); +}); + + +// Funktion zum Vorlesen der Nachricht +function speakMessage() { + // Verwenden Sie die SpeechSynthesis-API, um die Nachricht vorzulesen + + let text = $('#message').html(); + + + const synth = window.speechSynthesis; + const utterance = new SpeechSynthesisUtterance(text); + synth.speak(utterance); + utterance.onend = function (){ + console.log("funktioniert"); + } + utterance.onerror= function (){ + alert("fehlschlag"); + } +}