mirror of
https://github.com/gowvp/gb28181.git
synced 2025-09-26 19:41:19 +08:00
设备状态变化
This commit is contained in:
@@ -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"
|
||||
|
@@ -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()
|
||||
|
@@ -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
|
||||
})
|
||||
|
Reference in New Issue
Block a user