Skip to content

Commit

Permalink
Set active subprotocol version for SG-side BlipSyncContext (received …
Browse files Browse the repository at this point in the history
…blipsync requests)
  • Loading branch information
bbrks committed Nov 22, 2023
1 parent 9ae26ae commit 7f13df8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion db/active_replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func connect(arc *activeReplicatorCommon, idSuffix string) (blipSender *blip.Sen
}

// set active subprotocol after handshake
bsc.activeCBMobileSubprotocol, err = ParseSubprotocolString(blipContext.ActiveSubprotocol())
err = bsc.SetActiveCBMobileSubprotocol(blipContext.ActiveSubprotocol())
if err != nil {
return nil, nil, err
}
Expand Down
24 changes: 13 additions & 11 deletions rest/blip_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,20 @@ func (h *handler) handleBLIPSync() error {
})
}

middleware(server).ServeHTTP(h.response, h.rq)

if ok := server.WaitUntilStarted(h.ctx()); ok {
subprotocol := blipContext.ActiveSubprotocol()
h.logStatus(http.StatusSwitchingProtocols, fmt.Sprintf("[%s] Upgraded to WebSocket protocol %s+%s%s", blipContext.ID, blip.WebSocketSubProtocolPrefix, subprotocol, h.formattedEffectiveUserName()))
err := ctx.SetActiveCBMobileSubprotocol(subprotocol)
if err != nil {
panic(err)
go func() {
if ok := server.WaitUntilStarted(h.ctx()); ok {
subprotocol := blipContext.ActiveSubprotocol()
h.logStatus(http.StatusSwitchingProtocols, fmt.Sprintf("[%s] Upgraded to WebSocket protocol %s+%s%s", blipContext.ID, blip.WebSocketSubProtocolPrefix, subprotocol, h.formattedEffectiveUserName()))
err := ctx.SetActiveCBMobileSubprotocol(subprotocol)
if err != nil {
panic(err)
}
} else {
base.InfofCtx(h.ctx(), base.KeyHTTP, "%s: --> BLIP+WebSocket connection closed before it was accepted", h.formatSerialNumber())
}
} else {
base.InfofCtx(h.ctx(), base.KeyHTTP, "%s: --> BLIP+WebSocket connection closed before it was accepted", h.formatSerialNumber())
}
}()

middleware(server).ServeHTTP(h.response, h.rq)

return nil
}
Expand Down

0 comments on commit 7f13df8

Please sign in to comment.