Discard old history entries.
This commit is contained in:
+2
-16
@@ -147,7 +147,7 @@ type clientMessage struct {
|
||||
Permissions group.ClientPermissions `json:"permissions,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
Value string `json:"value,omitempty"`
|
||||
Time uint64 `json:"time,omitempty"`
|
||||
Time int64 `json:"time,omitempty"`
|
||||
Offer *webrtc.SessionDescription `json:"offer,omitempty"`
|
||||
Answer *webrtc.SessionDescription `json:"answer,omitempty"`
|
||||
Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`
|
||||
@@ -155,20 +155,6 @@ type clientMessage struct {
|
||||
Request rateMap `json:"request,omitempty"`
|
||||
}
|
||||
|
||||
func fromJSTime(tm uint64) time.Time {
|
||||
if tm == 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
return time.Unix(int64(tm)/1000, (int64(tm)%1000)*1000000)
|
||||
}
|
||||
|
||||
func toJSTime(tm time.Time) uint64 {
|
||||
if tm.Before(time.Unix(0, 0)) {
|
||||
return 0
|
||||
}
|
||||
return uint64((tm.Sub(time.Unix(0, 0)) + time.Millisecond/2) / time.Millisecond)
|
||||
}
|
||||
|
||||
type closeMessage struct {
|
||||
data []byte
|
||||
}
|
||||
@@ -1060,7 +1046,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
log.Printf("ICE: %v", err)
|
||||
}
|
||||
case "chat":
|
||||
tm := toJSTime(time.Now())
|
||||
tm := group.ToJSTime(time.Now())
|
||||
if m.Dest == "" {
|
||||
c.group.AddToChatHistory(
|
||||
m.Id, m.Username, tm, m.Kind, m.Value,
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package rtpconn
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestJSTime(t *testing.T) {
|
||||
tm := time.Now()
|
||||
js := toJSTime(tm)
|
||||
tm2 := fromJSTime(js)
|
||||
js2 := toJSTime(tm2)
|
||||
|
||||
if js != js2 {
|
||||
t.Errorf("%v != %v", js, js2)
|
||||
}
|
||||
|
||||
delta := tm.Sub(tm2)
|
||||
if delta < -time.Millisecond/2 || delta > time.Millisecond/2 {
|
||||
t.Errorf("Delta %v, %v, %v", delta, tm, tm2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user