Compare commits
11 Commits
0.16.1
...
058d232d2b
| Author | SHA1 | Date | |
|---|---|---|---|
| 058d232d2b | |||
|
|
67dcf6274c | ||
| 02869fff8b | |||
|
|
ef073afd5e | ||
| 92a7bc0586 | |||
|
|
352b7fd3ff | ||
| 3a62fbc129 | |||
| d8b3904cbc | |||
|
|
c1960a4e33 | ||
| 93e5af7402 | |||
|
|
fa900a3b56 |
21
CHANGELOG.md
21
CHANGELOG.md
@@ -129,3 +129,24 @@
|
||||
* Update Dockerfile for multi-platform support and add nginx configuration ([e972f1c](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/e972f1c4321ec2633e2989dbdaa714774632c495))
|
||||
* Update Dockerfile for multi-platform support and add nginx configuration ([37b88a1](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/37b88a108c71e20fc2caee950acd23cf2bb81190))
|
||||
## [0.0.0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/compare/0.16.0...0.0.0) (2026-01-06)
|
||||
## [0.0.0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/compare/0.16.1...0.0.0) (2026-01-07)
|
||||
## [0.0.0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/compare/0.16.2...0.0.0) (2026-01-07)
|
||||
|
||||
### Features
|
||||
|
||||
* Add caching headers for env.js in Nginx configuration ([93e5af7](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/93e5af7402edb9fb9662e37d9b2b8c48d250c36e))
|
||||
## [0.0.0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/compare/0.17.0...0.0.0) (2026-01-07)
|
||||
|
||||
### Features
|
||||
|
||||
* Add caching headers for env.js in Nginx configuration ([d8b3904](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/d8b3904cbc8b08ed9522d7b9b4fa8af79bc75def))
|
||||
## [0.0.0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/compare/0.18.0...0.0.0) (2026-01-07)
|
||||
|
||||
### Features
|
||||
|
||||
* Update joinGame endpoint to accept gameId as a path parameter ([92a7bc0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/92a7bc05866b77053ebb1d074ad207be8348f9d6))
|
||||
## [0.0.0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/compare/0.19.0...0.0.0) (2026-01-07)
|
||||
|
||||
### Features
|
||||
|
||||
* Enhance user state management with polling and WebSocket connection handling ([02869ff](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/02869fff8b448cde73369679c9b38bc99fb771ff))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Vite App</title>
|
||||
<title>Knockout-Whist</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
@@ -8,6 +8,13 @@ server {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /env.js {
|
||||
root /usr/share/nginx/html;
|
||||
default_type application/javascript;
|
||||
expires -1;
|
||||
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
84
src/App.vue
84
src/App.vue
@@ -1,8 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { RouterView } from 'vue-router'
|
||||
import { onMounted, onUnmounted } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { onMounted, onUnmounted, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useUserInfo } from "@/composables/useUserInfo";
|
||||
import { useIngame } from "@/composables/useIngame";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useWebSocket } from "@/composables/useWebsocket";
|
||||
import { useQuasar } from "quasar";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const info = useUserInfo();
|
||||
|
||||
const handleOnlineStatusChange = () => {
|
||||
if (navigator.onLine) {
|
||||
@@ -11,12 +19,84 @@ const handleOnlineStatusChange = () => {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let interval: number | null = null;
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('online', handleOnlineStatusChange);
|
||||
|
||||
// Continuously check user state every 10 seconds
|
||||
interval = window.setInterval(async () => {
|
||||
if (navigator.onLine && route.name !== 'login' && route.name !== 'offline') {
|
||||
await info.requestState();
|
||||
if (!info.username && route.name !== 'login') {
|
||||
router.push({ name: 'login' });
|
||||
}
|
||||
}
|
||||
}, 10000);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('online', handleOnlineStatusChange);
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
});
|
||||
|
||||
watch(() => info.gameId, (newGameId) => {
|
||||
if (newGameId && route.name !== 'game') {
|
||||
router.push({ name: 'game' });
|
||||
}
|
||||
});
|
||||
|
||||
const ig = useIngame()
|
||||
const { isWsConnected } = storeToRefs(ig)
|
||||
const wb = useWebSocket()
|
||||
const $q = useQuasar();
|
||||
|
||||
watch(isWsConnected, (connected) => {
|
||||
if (!connected && info.gameId && route.name === 'game') {
|
||||
showReconnectDialog();
|
||||
}
|
||||
});
|
||||
|
||||
function showReconnectDialog() {
|
||||
$q.dialog({
|
||||
title: 'Connection Lost',
|
||||
message: 'The connection to the game server was lost. Would you like to reconnect?',
|
||||
persistent: true,
|
||||
ok: {
|
||||
label: 'Reconnect',
|
||||
color: 'positive'
|
||||
},
|
||||
cancel: {
|
||||
label: 'Quit',
|
||||
color: 'negative'
|
||||
}
|
||||
}).onOk(() => {
|
||||
reconnect();
|
||||
}).onCancel(() => {
|
||||
router.replace("/");
|
||||
});
|
||||
}
|
||||
|
||||
async function reconnect() {
|
||||
try {
|
||||
await wb.connect();
|
||||
$q.notify({
|
||||
message: 'Reconnected successfully!',
|
||||
color: 'positive',
|
||||
icon: 'check'
|
||||
});
|
||||
} catch (err) {
|
||||
$q.notify({
|
||||
message: 'Failed to reconnect. Please try again.',
|
||||
color: 'negative',
|
||||
icon: 'error'
|
||||
});
|
||||
showReconnectDialog();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -25,9 +25,8 @@ function triggerWiggle(index: number) {
|
||||
function handlePlayCard(index: number | null) {
|
||||
if (index === null) return
|
||||
|
||||
wb.sendAndWait("PlayCard", { cardindex: index }).catch((error) => {
|
||||
wb.sendAndWait((<GameInfo>wi.data)?.self?.dogLife ? "PlayDogCard" : "PlayCard", { cardindex: index }).catch((error) => {
|
||||
triggerWiggle(index)
|
||||
|
||||
$q.notify({
|
||||
message: error.message,
|
||||
color: "negative",
|
||||
@@ -45,7 +44,13 @@ function onBeforeLeave(el: Element) {
|
||||
element.style.height = height;
|
||||
}
|
||||
function handleSkipDogLife() {
|
||||
//TODO: Add some animation or feedback for skipping turn
|
||||
wb.sendAndWait("PlayDogCard", { cardindex: 'Skip' }).catch((error) => {
|
||||
$q.notify({
|
||||
message: error.message,
|
||||
color: "negative",
|
||||
position: "top"
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function getCardImagePath(cardPath: string) {
|
||||
|
||||
@@ -9,12 +9,17 @@ const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
||||
export const useIngame = defineStore('ingame', () => {
|
||||
const state: Ref<'Lobby' | 'InGame' | 'SelectTrump' | 'TieBreak' | 'FinishedMatch' | null> = ref(null);
|
||||
const data: Ref<GameInfo | LobbyInfo | TieInfo | TrumpInfo | WonInfo | null> = ref(null);
|
||||
const isWsConnected: Ref<boolean> = ref(false);
|
||||
|
||||
function setIngame(newState: 'Lobby' | 'InGame' | 'SelectTrump' | 'TieBreak' | 'FinishedMatch', newData: GameInfo | LobbyInfo | TieInfo | TrumpInfo | WonInfo) {
|
||||
state.value = newState;
|
||||
data.value = newData;
|
||||
}
|
||||
|
||||
function setWsConnected(connected: boolean) {
|
||||
isWsConnected.value = connected;
|
||||
}
|
||||
|
||||
async function requestGame(gameId: string) {
|
||||
await axios.get(`${api}/status/${gameId}`, {withCredentials: true}).then((response) => {
|
||||
setIngame(response.data.state, response.data.data);
|
||||
@@ -24,7 +29,8 @@ export const useIngame = defineStore('ingame', () => {
|
||||
function clearIngame() {
|
||||
state.value = null;
|
||||
data.value = null;
|
||||
isWsConnected.value = false;
|
||||
}
|
||||
|
||||
return { state, data, requestGame, setIngame, clearIngame };
|
||||
return { state, data, isWsConnected, requestGame, setIngame, clearIngame, setWsConnected };
|
||||
});
|
||||
|
||||
@@ -21,10 +21,19 @@ export const useUserInfo = defineStore('userInfo', () => {
|
||||
async function requestState() {
|
||||
await axios.get(`${api}/status`, {withCredentials: true}).then((response) => {
|
||||
console.log("STATUS DATA:" + response.data.status + response.data.inGame)
|
||||
username.value = response.data.username;
|
||||
if (response.data.gameId) {
|
||||
console.log("GAMEID:" + response.data.gameId)
|
||||
gameId.value = response.data.gameId;
|
||||
if (response.data.status === 'authenticated') {
|
||||
username.value = response.data.username;
|
||||
userId.value = response.data.userId;
|
||||
if (response.data.gameId) {
|
||||
console.log("GAMEID:" + response.data.gameId)
|
||||
gameId.value = response.data.gameId;
|
||||
} else {
|
||||
gameId.value = null;
|
||||
}
|
||||
} else {
|
||||
username.value = null;
|
||||
userId.value = null;
|
||||
gameId.value = null;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -73,8 +73,12 @@ router.beforeEach(async (to, from, next) => {
|
||||
if (isOnline) {
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${api}/userInfo`, { withCredentials: true });
|
||||
info.setUserInfo(response.data.username, response.data.userId);
|
||||
await info.requestState();
|
||||
|
||||
if (!info.username) {
|
||||
info.clearUserInfo();
|
||||
return next('/login');
|
||||
}
|
||||
|
||||
return next({ name: 'mainmenu' });
|
||||
|
||||
@@ -92,11 +96,17 @@ router.beforeEach(async (to, from, next) => {
|
||||
|
||||
if (!to.meta.requiresAuth) return next();
|
||||
try {
|
||||
await axios.get(`${api}/userInfo`, { withCredentials: true }).then(
|
||||
res => {
|
||||
info.setUserInfo(res.data.username, res.data.userId);
|
||||
}
|
||||
);
|
||||
await info.requestState();
|
||||
|
||||
if (!info.username) {
|
||||
info.clearUserInfo();
|
||||
return next('/login');
|
||||
}
|
||||
|
||||
if (info.gameId && to.name !== 'game') {
|
||||
return next({ name: 'game' });
|
||||
}
|
||||
|
||||
next();
|
||||
} catch (err) {
|
||||
info.clearUserInfo();
|
||||
|
||||
@@ -160,14 +160,15 @@ function setupSocketHandlers(socket: WebSocket) {
|
||||
stopHeartbeat();
|
||||
failAllPending("WebSocket closed");
|
||||
|
||||
if (uState) {
|
||||
uState.setWsConnected(false);
|
||||
}
|
||||
|
||||
if (ev.wasClean) {
|
||||
console.log(`[WS] Closed cleanly: code=${ev.code} reason=${ev.reason}`);
|
||||
} else {
|
||||
console.warn("[WS] Connection died");
|
||||
}
|
||||
|
||||
// You redirect here — if you don’t want auto reconnect, keep as is.
|
||||
router.replace("/");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -191,6 +192,9 @@ export function connectWebSocket(url?: string): Promise<void> {
|
||||
const prevOnError = ws!.onerror;
|
||||
ws!.onopen = (ev) => {
|
||||
if (prevOnOpen) prevOnOpen.call(ws!, ev);
|
||||
if (uState) {
|
||||
uState.setWsConnected(true);
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
ws!.onerror = (err) => {
|
||||
@@ -207,6 +211,9 @@ export function connectWebSocket(url?: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
ws!.onopen = () => {
|
||||
console.log("[WS] Connected");
|
||||
if (uState) {
|
||||
uState.setWsConnected(true);
|
||||
}
|
||||
startHeartbeat();
|
||||
resolve();
|
||||
};
|
||||
@@ -224,6 +231,9 @@ export function disconnectWebSocket(code = 1000, reason = "Client disconnect") {
|
||||
ws.close(code, reason);
|
||||
} catch {}
|
||||
ws = null;
|
||||
if (uState) {
|
||||
uState.setWsConnected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ref } from 'vue';
|
||||
import { useQuasar } from 'quasar';
|
||||
import { useRouter } from 'vue-router';
|
||||
import axios from "axios";
|
||||
import {useUserInfo} from "@/composables/useUserInfo";
|
||||
|
||||
const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
||||
const lobbyName = ref('');
|
||||
@@ -11,13 +12,14 @@ const playerAmount = ref(2);
|
||||
const $q = useQuasar();
|
||||
const isLoading = ref(false);
|
||||
const router = useRouter();
|
||||
const info = useUserInfo();
|
||||
const createGameQuasar = async () => {
|
||||
if (!lobbyName.value) {
|
||||
$q.notify({ message: 'Lobby-Name wird benötigt', color: 'red', position: 'top', icon: 'cancel' });
|
||||
return;
|
||||
}
|
||||
isLoading.value = true;
|
||||
axios.post(`${api}/createGame`, {lobbyname: lobbyName.value, playeramount: playerAmount.value.toString()}, {withCredentials: true}).then((response) => {
|
||||
axios.post(`${api}/createGame`, {lobbyname: lobbyName.value, playeramount: playerAmount.value.toString()}, {withCredentials: true}).then(async (response) => {
|
||||
const responseData = response.data
|
||||
console.log("Response" + responseData.status)
|
||||
$q.notify({
|
||||
@@ -26,12 +28,12 @@ const createGameQuasar = async () => {
|
||||
icon: 'check_circle',
|
||||
position: 'top'
|
||||
});
|
||||
await info.requestState();
|
||||
router.replace("/game")
|
||||
}).catch((err) => {
|
||||
console.log("ERROR:" + err)
|
||||
}).finally(() =>
|
||||
isLoading.value = false
|
||||
)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import LobbyComponent from "@/components/lobby/LobbyComponent.vue";
|
||||
import {storeToRefs} from "pinia";
|
||||
import {useQuasar} from "quasar";
|
||||
import router from "@/router";
|
||||
import {ref, watch} from "vue";
|
||||
|
||||
const wb = useWebSocket()
|
||||
const ig = useIngame()
|
||||
@@ -20,7 +21,6 @@ ui.requestState().then(() => {
|
||||
$q.notify({
|
||||
message: "You're not in any game!",
|
||||
color: "negative"
|
||||
|
||||
})
|
||||
router.replace("/")
|
||||
} else {
|
||||
|
||||
@@ -1,28 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import {ref} from "vue";
|
||||
import {ref, onUnmounted} from "vue";
|
||||
import { useRouter } from 'vue-router';
|
||||
import {useQuasar} from "quasar";
|
||||
import axios from "axios";
|
||||
import {useUserInfo} from "@/composables/useUserInfo";
|
||||
const router = useRouter();
|
||||
const info = useUserInfo();
|
||||
const lobbyCode = ref('');
|
||||
const isLoading = ref(false);
|
||||
const $q = useQuasar();
|
||||
const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
||||
|
||||
let pollInterval: number | null = null;
|
||||
|
||||
onUnmounted(() => {
|
||||
if (pollInterval) {
|
||||
clearInterval(pollInterval);
|
||||
}
|
||||
});
|
||||
|
||||
const startGameQuasar = async() => {
|
||||
if (!lobbyCode.value) {
|
||||
$q.notify({ message: 'Lobby-Name wird benötigt', color: 'red', position: 'top', icon: 'cancel' });
|
||||
return;
|
||||
}
|
||||
isLoading.value = true;
|
||||
axios.post(`${api}/joinGame`, {gameId: lobbyCode.value.toString()}, {withCredentials: true}).then(response => {
|
||||
const responseData = response.data
|
||||
axios.post(`${api}/joinGame/${lobbyCode.value.toString()}`, {}, {withCredentials: true}).then(() => {
|
||||
$q.notify({
|
||||
message: `Lobby "${lobbyCode.value}" erfolgreich gefunden`,
|
||||
color: 'green-6',
|
||||
icon: 'check_circle',
|
||||
position: 'top'
|
||||
});
|
||||
router.replace("/game")
|
||||
|
||||
// Start polling until gameId is set
|
||||
pollInterval = window.setInterval(async () => {
|
||||
await info.requestState();
|
||||
if (info.gameId) {
|
||||
if (pollInterval) {
|
||||
clearInterval(pollInterval);
|
||||
pollInterval = null;
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
|
||||
}).catch(() => {
|
||||
$q.notify({
|
||||
message: `Lobby "${lobbyCode.value}" nicht gefunden`,
|
||||
@@ -30,9 +51,8 @@ const startGameQuasar = async() => {
|
||||
icon: 'cancel',
|
||||
position: 'top'
|
||||
})
|
||||
}).finally(() =>
|
||||
isLoading.value = false
|
||||
)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
MAJOR=0
|
||||
MINOR=16
|
||||
PATCH=1
|
||||
MINOR=20
|
||||
PATCH=0
|
||||
|
||||
Reference in New Issue
Block a user