This commit is contained in:
2026-01-03 17:22:09 +00:00
parent 5ea8c0df23
commit 5b504d10bd
13 changed files with 581 additions and 480 deletions
-4
View File
@@ -1,15 +1,12 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { io } from 'socket.io-client'
import App from './App.vue'
import router from './router'
const apiDomain = import.meta.env.VITE_API_DOMAIN
const wsConnection = import.meta.env.VITE_WS_CONNECTION
console.log('[main.js] api domain', apiDomain)
console.log('[main.js] ws connection', wsConnection)
const app = createApp(App)
@@ -20,4 +17,3 @@ app.use(createPinia())
app.use(router)
app.mount('#app')
+8 -6
View File
@@ -12,7 +12,7 @@ export const useSocketStore = defineStore('websocket', () => {
const lastError = ref(null)
const currentGameId = ref(null)
const WS_URL = 'http://localhost:3000'
const WS_URL = import.meta.env.VITE_WS_CONNECTION || 'ws://localhost:3000'
const connect = () => {
if (socket.value?.connected) return
@@ -27,13 +27,15 @@ export const useSocketStore = defineStore('websocket', () => {
auth: { token: `Bearer ${token}` },
reconnection: true,
reconnectionAttempts: 5,
reconnectionDelay: 1000
reconnectionDelay: 1000,
})
console.log('[WebSocket] Attempting to connect to', WS_URL)
socket.value.on('connect', () => {
if (currentGameId.value) {
console.log("Reconnected to socket. Rejoining game...");
socket.emit("join-game", { gameId: currentGameId.value });
console.log('Reconnected to socket. Rejoining game...')
socket.emit('join-game', { gameId: currentGameId.value })
}
connected.value = true
@@ -122,8 +124,8 @@ export const useSocketStore = defineStore('websocket', () => {
disconnect,
joinGame,
playCard,
surrender,
surrender,
onTrickEnd,
onGameOver
onGameOver,
}
})