client Ordner als normale Dateien hinzugefügt
This commit is contained in:
parent
b3a5da292e
commit
bb058bb989
3 changed files with 44 additions and 1 deletions
1
client
1
client
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 9cbce7415d2429d2132afb3b1d985c09f6ddd7f2
|
||||
34
client/client.js
Normal file
34
client/client.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @returns {Promise<{server_ip: string, server_port: number}>}
|
||||
*/
|
||||
async function getServerConfig() {
|
||||
const response = await fetch('/api/ip');
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
getServerConfig()
|
||||
.then(data => {
|
||||
const websocketIp = data.server_ip;
|
||||
const websocketPort = data.server_port;
|
||||
const ws = new WebSocket(`ws://${websocketIp}:${websocketPort}`);
|
||||
|
||||
ws.onopen = function() {
|
||||
console.log("WebSocket ist geöffnet");
|
||||
ws.send(JSON.stringify({"data_message": "Server Adresse: " + websocketIp + ":" + websocketPort}));
|
||||
};
|
||||
|
||||
ws.onmessage = function(messageEvent) {
|
||||
console.log(messageEvent.data);
|
||||
};
|
||||
|
||||
ws.onclose = function() {
|
||||
console.log("WebSocket wurde geschlossen");
|
||||
};
|
||||
|
||||
ws.onerror = function(errorEvent) {
|
||||
console.error("WebSocket-Fehler: ", errorEvent);
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching settings:', error);
|
||||
});
|
||||
10
client/index.html
Normal file
10
client/index.html
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Websocket Client</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="/client/client.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in a new issue