room groups and grouping.

This commit is contained in:
2023-09-06 20:25:57 +02:00
parent 07c9398414
commit 4fc7d2d475
7 changed files with 315 additions and 90 deletions
+26 -2
View File
@@ -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