diff --git a/example/main.ts b/example/main.ts index b470839..a624a21 100644 --- a/example/main.ts +++ b/example/main.ts @@ -52,7 +52,7 @@ n.on('ready', () => { const el = document.getElementById('lobbies') if (el !== null) { el.innerHTML = '' - if (lobbies.length === 0) { + if (lobbies === null || lobbies.length === 0) { const li = document.createElement('li') li.innerHTML = 'no lobbies' el.appendChild(li) diff --git a/internal/signaling/handler.go b/internal/signaling/handler.go index d413d7b..4e414f5 100644 --- a/internal/signaling/handler.go +++ b/internal/signaling/handler.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "net/http" + "strings" "time" "github.com/koenbollen/logging" @@ -18,11 +19,6 @@ import ( const MaxConnectionTime = 1 * time.Hour func Handler(ctx context.Context, store stores.Store, cloudflare *cloudflare.CredentialsClient) http.HandlerFunc { - acceptOptions := &websocket.AcceptOptions{ - // Allow any origin/game to connect. - InsecureSkipVerify: true, - } - manager := &TimeoutManager{} go manager.Run(ctx) @@ -34,6 +30,17 @@ func Handler(ctx context.Context, store stores.Store, cloudflare *cloudflare.Cre ctx, cancel := context.WithTimeout(ctx, MaxConnectionTime) defer cancel() + userAgentLower := strings.ToLower(r.Header.Get("User-Agent")) + isSafari := strings.Contains(userAgentLower, "safari") && !strings.Contains(userAgentLower, "chrome") && !strings.Contains(userAgentLower, "android") + acceptOptions := &websocket.AcceptOptions{ + // Allow any origin/game to connect. + InsecureSkipVerify: true, + } + + if isSafari { + acceptOptions.CompressionMode = websocket.CompressionDisabled + } + conn, err := websocket.Accept(w, r, acceptOptions) if err != nil { util.ErrorAndAbort(w, r, http.StatusBadRequest, "", err)