room groups and grouping.
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var zeroUUID = uuid.UUID{
|
||||
@@ -57,11 +58,34 @@ func New(addr string) (lucifer3.Service, error) {
|
||||
defer svc.removeSub(sub)
|
||||
defer ws.Close()
|
||||
|
||||
for patch := range sub {
|
||||
err := ws.WriteJSON(patch)
|
||||
lastSent := time.Now()
|
||||
patches := make([]uistate.Patch, 0, 128)
|
||||
for {
|
||||
patch := <-sub
|
||||
since := time.Now().Sub(lastSent)
|
||||
patches = append(patches[:0], patch)
|
||||
|
||||
if since < time.Millisecond*950 {
|
||||
waitCh := time.NewTimer(time.Millisecond*1000 - since)
|
||||
waiting := true
|
||||
|
||||
for waiting {
|
||||
select {
|
||||
case patch, ok := <-sub:
|
||||
patches = append(patches, patch)
|
||||
waiting = ok
|
||||
case <-waitCh.C:
|
||||
waiting = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err := ws.WriteJSON(patches)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
lastSent = time.Now()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user