mirror of
https://github.com/gowvp/gb28181.git
synced 2026-04-22 23:17:19 +08:00
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package gbs
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/gowvp/gb28181/pkg/gbs/sip"
|
|
// "github.com/panjjo/gosip/db"
|
|
)
|
|
|
|
// MessageNotify 心跳包xml结构
|
|
type MessageNotify struct {
|
|
CmdType string `xml:"CmdType"`
|
|
SN int `xml:"SN"`
|
|
DeviceID string `xml:"DeviceID"`
|
|
Status string `xml:"Status"`
|
|
Info string `xml:"Info"`
|
|
}
|
|
|
|
func sipMessageKeepalive(u Devices, body []byte) error {
|
|
message := &MessageNotify{}
|
|
if err := sip.XMLDecode(body, message); err != nil {
|
|
// logrus.Errorln("Message Unmarshal xml err:", err, "body:", string(body))
|
|
return err
|
|
}
|
|
device, ok := _activeDevices.Get(u.DeviceID)
|
|
if !ok {
|
|
device = Devices{DeviceID: u.DeviceID}
|
|
// if err := db.Get(db.DBClient, &device); err != nil {
|
|
// logrus.Warnln("Device Keepalive not found ", u.DeviceID, err)
|
|
// }
|
|
}
|
|
if message.Status == "OK" {
|
|
device.ActiveAt = time.Now().Unix()
|
|
_activeDevices.Store(u.DeviceID, u)
|
|
} else {
|
|
device.ActiveAt = -1
|
|
_activeDevices.Delete(u.DeviceID)
|
|
}
|
|
go notify(notifyDevicesAcitve(u.DeviceID, message.Status))
|
|
// _, err := db.UpdateAll(db.DBClient, new(Devices), map[string]interface{}{"deviceid=?": u.DeviceID}, Devices{
|
|
// Host: u.Host,
|
|
// Port: u.Port,
|
|
// Rport: u.Rport,
|
|
// RAddr: u.RAddr,
|
|
// Source: u.Source,
|
|
// URIStr: u.URIStr,
|
|
// ActiveAt: device.ActiveAt,
|
|
// })
|
|
// return err
|
|
return nil
|
|
}
|