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