From f7f3e67417ba7c96e312adeaaa6314e2c7a74c8a Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Fri, 2 Feb 2024 18:25:33 -0600 Subject: [PATCH] websocket messages are json --- site/src/App.vue | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/site/src/App.vue b/site/src/App.vue index 851f672..9badfc5 100644 --- a/site/src/App.vue +++ b/site/src/App.vue @@ -37,7 +37,7 @@ const toggleDark = useToggle(dark); const theme = computed(() => dark.value ? 'dark' : 'light'); const themeIcon = computed(() => dark.value ? 'mdi-moon-waxing-crescent' : 'mdi-white-balance-sunny'); -const { status, data, send, open } = useWebSocket(`wss://${window.location.host}/queue`, { immediate: false }); +const { status, data, send, open } = useWebSocket(`wss://${window.location.host}/queue`, { immediate: false }); const game = ref(null); const dealer = ref(null); watchEffect(() => { @@ -46,14 +46,15 @@ watchEffect(() => { dealer.value = null; return; } - if ('id' in data.value) { + const m = JSON.parse(data.value) as Game | GameStart; + if ('id' in m) { // Game start. - dealer.value = data.value.dealer; - history.replaceState(null, '', `${window.origin}/game/${data.value.id}`); + dealer.value = m.dealer; + history.replaceState(null, '', `${window.origin}/game/${m.id}`); return; } // Game state update. - game.value = data.value as Game; + game.value = m as Game; }); const playing = computed(() => game.value != null);