diff --git a/Public/api.js b/Public/api.js index 2bd4e39..457a647 100644 --- a/Public/api.js +++ b/Public/api.js @@ -4,12 +4,17 @@ const apiPath = "/schafkopf" -async function performRegisterPlayerRequest(name, password){ +function webSocketPath() { + const prefix = (window.location.protocol === "https:") ? "wss://" : "ws://" + return prefix + window.location.host + apiPath + "/session/start" +} + +async function performRegisterPlayerRequest(name, password) { return fetch(apiPath + "/player/register/" + name, { method: 'POST', body: password }) .then(convertServerResponse) } -async function performDeletePlayerRequest(name, password){ +async function performDeletePlayerRequest(name, password) { return fetch(apiPath + "/player/delete/" + name, { method: 'POST', body: password }) .then(convertServerResponse) .then(function(value) {}) diff --git a/Public/game.js b/Public/game.js index 4cbb8b1..721362a 100644 --- a/Public/game.js +++ b/Public/game.js @@ -174,7 +174,8 @@ function leaveTable() { } function openSocket(token) { - socket = new WebSocket(((window.location.protocol === "https:") ? "wss://" : "ws://") + window.location.host + "/session/start") + const socketPath = webSocketPath() + socket = new WebSocket(socketPath) socket.onopen = function(e) { socket.send(token);