This commit is contained in:
2026-06-21 19:11:23 +02:00
parent 3fd2b8ade8
commit e9d77fbd05
11 changed files with 96 additions and 77 deletions
+16 -2
View File
@@ -1,4 +1,6 @@
import {defineStore} from 'pinia';
import {useAppStore} from "@/stores/app.ts";
import {useAuthStore} from "@/stores/auth.ts";
type GatewayStatus = 'disconnected' | 'connecting' | 'connected' | 'error'
@@ -15,9 +17,21 @@ export const useGatewayStore = defineStore('gateway', {
return
}
this.status = 'connecting'
const appStore = useAppStore()
const authStore = useAuthStore()
const wsUrl = `ws://localhost:3000/ws`
this.status = 'connecting'
const token = authStore.token
if (!token) {
this.status = 'error'
return
}
const apiUri = appStore.baseurl ? new URL(appStore.baseurl) : new URL(window.location.href)
const wsProtocol = apiUri.protocol === 'https:' ? 'wss:' : 'ws:'
const wsUrl = `${wsProtocol}//${apiUri.host}/ws/gateway?token=${encodeURIComponent(token)}`
const socket = new WebSocket(wsUrl)
socket.onopen = () => {