设备状态变化

This commit is contained in:
xugo
2025-03-09 16:58:54 +08:00
parent f6cc59b8e6
commit 7bd5a119dd
3 changed files with 5 additions and 14 deletions

View File

@@ -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"

View File

@@ -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()

View File

@@ -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
})