update
This commit is contained in:
@@ -34,10 +34,18 @@ export const api = {
|
||||
}
|
||||
|
||||
export function wsVerbinden(onEvent) {
|
||||
const url = (import.meta.env.DEV ? 'ws://localhost:8000' : `ws://${location.host}`) + '/ws'
|
||||
// Protokoll an die Seite koppeln: HTTPS erlaubt nur wss:// (Mixed Content)
|
||||
const wsProto = location.protocol === 'https:' ? 'wss' : 'ws'
|
||||
const url = (import.meta.env.DEV ? 'ws://localhost:8000' : `${wsProto}://${location.host}`) + '/ws'
|
||||
let ws
|
||||
const verbinden = () => {
|
||||
ws = new WebSocket(url)
|
||||
try {
|
||||
ws = new WebSocket(url)
|
||||
} catch (e) {
|
||||
// nie den Aufrufer mitreißen (der SecurityError killte sonst den Poll)
|
||||
console.error('WebSocket nicht verfügbar:', e)
|
||||
return
|
||||
}
|
||||
ws.onopen = () => onEvent({ typ: 'verbunden' }) // nach Reconnect: Stand neu laden
|
||||
ws.onmessage = (e) => onEvent(JSON.parse(e.data))
|
||||
ws.onclose = () => setTimeout(verbinden, 2000)
|
||||
|
||||
Reference in New Issue
Block a user