Fix websocket path

This commit is contained in:
Christoph Hagen 2021-12-23 11:16:03 +01:00
parent 07d22e2de5
commit 15d2b3d670
2 changed files with 9 additions and 3 deletions

View File

@ -4,12 +4,17 @@
const apiPath = "/schafkopf" 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 }) return fetch(apiPath + "/player/register/" + name, { method: 'POST', body: password })
.then(convertServerResponse) .then(convertServerResponse)
} }
async function performDeletePlayerRequest(name, password){ async function performDeletePlayerRequest(name, password) {
return fetch(apiPath + "/player/delete/" + name, { method: 'POST', body: password }) return fetch(apiPath + "/player/delete/" + name, { method: 'POST', body: password })
.then(convertServerResponse) .then(convertServerResponse)
.then(function(value) {}) .then(function(value) {})

View File

@ -174,7 +174,8 @@ function leaveTable() {
} }
function openSocket(token) { 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.onopen = function(e) {
socket.send(token); socket.send(token);