diff --git a/pkg/gbs/keepalive.go b/pkg/gbs/keepalive.go index 80a8383..30338f9 100644 --- a/pkg/gbs/keepalive.go +++ b/pkg/gbs/keepalive.go @@ -23,19 +23,6 @@ func (g *GB28181API) sipMessageKeepalive(ctx *sip.Context) { return } - // device, ok := _activeDevices.Get(ctx.DeviceID) - // if !ok { - // device = Devices{DeviceID: ctx.DeviceID} - // if err := db.Get(db.DBClient, &device); err != nil { - // logrus.Warnln("Device Keepalive not found ", u.DeviceID, err) - // } - // } - - ipc, ok := g.svr.memoryStorer.Load(ctx.DeviceID) - if ok { - g.svr.memoryStorer.Store(ctx.DeviceID, ipc) - } - if err := g.svr.memoryStorer.Change(ctx.DeviceID, func(d *gb28181.Device) { d.KeepaliveAt = orm.Now() d.IsOnline = msg.Status == "OK" || msg.Status == "ON" diff --git a/pkg/gbs/register.go b/pkg/gbs/register.go index 22c0399..4d191aa 100644 --- a/pkg/gbs/register.go +++ b/pkg/gbs/register.go @@ -157,6 +157,7 @@ func (g GB28181API) login(ctx *sip.Context, expire string) { g.svr.memoryStorer.Change(ctx.DeviceID, func(d *gb28181.Device) { d.IsOnline = true d.RegisteredAt = orm.Now() + d.KeepaliveAt = orm.Now() d.Expires, _ = strconv.Atoi(expire) }, func(d *Device) { d.conn = ctx.Request.GetConnection() diff --git a/pkg/gbs/server.go b/pkg/gbs/server.go index 2e879dc..deeda40 100644 --- a/pkg/gbs/server.go +++ b/pkg/gbs/server.go @@ -93,7 +93,10 @@ func (s *Server) startTickerCheck() { return true } - if now.Sub(value.LastKeepaliveAt) >= 3*60*time.Second || value.conn == nil { + if sub := now.Sub(value.LastKeepaliveAt); sub >= 3*60*time.Second || value.conn == nil { + fmt.Println(now) + fmt.Println(sub) + fmt.Println(value.LastKeepaliveAt) s.gb.logout(key, func(d *gb28181.Device) { d.IsOnline = false })