|
|
|
@ -51,6 +51,8 @@ func (ch *CaddyHugo) DeltaWebsocket(w http.ResponseWriter, r *http.Request) (int |
|
|
|
|
return http.StatusBadRequest, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
conn.SetReadDeadline(time.Time{}) |
|
|
|
|
|
|
|
|
|
doc, err := ch.doc(r) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Println(err) |
|
|
|
@ -115,7 +117,7 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) { |
|
|
|
|
|
|
|
|
|
err := conn.ReadJSON(&message) |
|
|
|
|
if err != nil { |
|
|
|
|
errCh <- err |
|
|
|
|
errCh <- fmt.Errorf("error reading message from client conn: %v", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
ch.ObserveLTime(message.LTime) |
|
|
|
@ -127,7 +129,7 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) { |
|
|
|
|
|
|
|
|
|
err = client.PushDeltas(message.Deltas...) |
|
|
|
|
if err != nil { |
|
|
|
|
errCh <- err |
|
|
|
|
errCh <- fmt.Errorf("error pushing deltas into document: %v", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -141,9 +143,17 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) { |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
for { |
|
|
|
|
select { |
|
|
|
|
case err := <-errCh: |
|
|
|
|
fmt.Println(err) |
|
|
|
|
return 500, err |
|
|
|
|
default: |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
select { |
|
|
|
|
case <-timer.C: |
|
|
|
|
conn.WriteJSON(ch.Message()) |
|
|
|
|
resetTimer(idlePing) |
|
|
|
|
case <-readMessagesCh: |
|
|
|
|
resetTimer(idlePingShort) |
|
|
|
|
case <-wroteMessagesCh: |
|
|
|
|