Private
Public Access
Dynamically generate WebSocket URLs based on current domain to support both HTTP and HTTPS environments.
Dynamic Branch Deploy / build-and-deploy (push) Successful in 2m24s
Dynamic Branch Deploy / build-and-deploy (push) Successful in 2m24s
This commit is contained in:
1 parent
fa59070c4a
commit
d7c2e8dc85
2 files changed
+15
-4
No files matched your search
@@ -20,14 +20,20 @@ type WebSocketMessage struct {
|
||||
|
||||
// wsConn verwaltet die WebSocket-Verbindung im Browser
|
||||
type wsConn struct {
|
||||
ws js.Value
|
||||
ws js.Value
|
||||
messagesChan chan []byte
|
||||
connected bool
|
||||
connected bool
|
||||
}
|
||||
|
||||
// connectToServer verbindet sich über WebSocket mit dem Gateway
|
||||
func (g *Game) connectToServer() {
|
||||
serverURL := "ws://localhost:8080/ws"
|
||||
// Automatisch die richtige WebSocket-URL basierend auf der aktuellen Domain
|
||||
protocol := "ws:"
|
||||
if js.Global().Get("location").Get("protocol").String() == "https:" {
|
||||
protocol = "wss:"
|
||||
}
|
||||
host := js.Global().Get("location").Get("host").String()
|
||||
serverURL := protocol + "//" + host + "/ws"
|
||||
log.Printf("🔌 Verbinde zu WebSocket-Gateway: %s", serverURL)
|
||||
|
||||
ws := js.Global().Get("WebSocket").New(serverURL)
|
||||
|
||||
Reference in new issue
Block a user