fix: api/list add channelcout,KeepAliveTime

This commit is contained in:
pg
2025-02-27 17:26:11 +08:00
committed by pggiroro
parent 61607d54fc
commit ae3e76b20b
6 changed files with 1018 additions and 1017 deletions

View File

@@ -95,19 +95,19 @@ func (gb *GB28181ProPlugin) List(ctx context.Context, req *pb.GetDevicesRequest)
} }
pbDevices = append(pbDevices, &pb.Device{ pbDevices = append(pbDevices, &pb.Device{
Id: d.DeviceID, DeviceID: d.DeviceID,
Name: d.Name, Name: d.Name,
Manufacturer: d.Manufacturer, Manufacturer: d.Manufacturer,
Model: d.Model, Model: d.Model,
Owner: d.Owner, Status: string(d.Status),
Status: string(d.Status), Online: d.Online,
Online: d.Online, Longitude: d.Longitude,
Longitude: d.Longitude, Latitude: d.Latitude,
Latitude: d.Latitude, RegisterTime: timestamppb.New(d.RegisterTime),
GpsTime: timestamppb.New(d.GpsTime), UpdateTime: timestamppb.New(d.UpdateTime),
RegisterTime: timestamppb.New(d.RegisterTime), KeepAliveTime: timestamppb.New(d.KeepaliveTime),
UpdateTime: timestamppb.New(d.UpdateTime), ChannelCount: int32(d.ChannelCount),
Channels: pbChannels, Channels: pbChannels,
}) })
} }
@@ -176,16 +176,14 @@ func (gb *GB28181ProPlugin) GetDevice(ctx context.Context, req *pb.GetDeviceRequ
}) })
} }
resp.Data = &pb.Device{ resp.Data = &pb.Device{
Id: d.DeviceID, DeviceID: d.DeviceID,
Name: d.Name, Name: d.Name,
Manufacturer: d.Manufacturer, Manufacturer: d.Manufacturer,
Model: d.Model, Model: d.Model,
Owner: d.Owner,
Status: string(d.Status), Status: string(d.Status),
Online: d.Online, Online: d.Online,
Longitude: d.Longitude, Longitude: d.Longitude,
Latitude: d.Latitude, Latitude: d.Latitude,
GpsTime: timestamppb.New(d.GpsTime),
RegisterTime: timestamppb.New(d.RegisterTime), RegisterTime: timestamppb.New(d.RegisterTime),
UpdateTime: timestamppb.New(d.UpdateTime), UpdateTime: timestamppb.New(d.UpdateTime),
Channels: channels, Channels: channels,
@@ -273,19 +271,18 @@ func (gb *GB28181ProPlugin) GetDevices(ctx context.Context, req *pb.GetDevicesRe
} }
pbDevice := &pb.Device{ pbDevice := &pb.Device{
Id: d.DeviceID, DeviceID: d.DeviceID,
Name: d.Name, Name: d.Name,
Manufacturer: d.Manufacturer, Manufacturer: d.Manufacturer,
Model: d.Model, Model: d.Model,
Owner: d.Owner, Status: string(d.Status),
Status: string(d.Status), Online: d.Online,
Online: d.Online, Longitude: d.Longitude,
Longitude: d.Longitude, Latitude: d.Latitude,
Latitude: d.Latitude, RegisterTime: timestamppb.New(d.RegisterTime),
GpsTime: timestamppb.New(d.GpsTime), UpdateTime: timestamppb.New(d.UpdateTime),
RegisterTime: timestamppb.New(d.RegisterTime), KeepAliveTime: timestamppb.New(d.KeepaliveTime),
UpdateTime: timestamppb.New(d.UpdateTime), Channels: pbChannels,
Channels: pbChannels,
} }
pbDevices = append(pbDevices, pbDevice) pbDevices = append(pbDevices, pbDevice)
} }

View File

@@ -32,7 +32,6 @@ type Device struct {
Name string // 设备名 Name string // 设备名
Manufacturer string // 生产厂商 Manufacturer string // 生产厂商
Model string // 型号 Model string // 型号
Owner string // 所有者
Firmware string // 固件版本 Firmware string // 固件版本
Transport string // 传输协议UDP/TCP Transport string // 传输协议UDP/TCP
StreamMode string // 数据流传输模式UDP:udp传输/TCP-ACTIVEtcp主动模式/TCP-PASSIVEtcp被动模式 StreamMode string // 数据流传输模式UDP:udp传输/TCP-ACTIVEtcp主动模式/TCP-PASSIVEtcp被动模式
@@ -68,8 +67,7 @@ type Device struct {
Recipient sip.Uri `gorm:"-:all"` Recipient sip.Uri `gorm:"-:all"`
channels util.Collection[string, *Channel] `gorm:"-:all"` channels util.Collection[string, *Channel] `gorm:"-:all"`
mediaIp string mediaIp string
GpsTime time.Time // gps时间 Longitude, Latitude string // 经度,纬度
Longitude, Latitude string // 经度,纬度
eventChan chan any eventChan chan any
client *sipgo.Client client *sipgo.Client
dialogClient *sipgo.DialogClient dialogClient *sipgo.DialogClient
@@ -126,7 +124,7 @@ func (d *Device) onMessage(req *sip.Request, tx sip.ServerTransaction, msg *gb28
} }
} }
// 更新当前设备的通道数 // 更新当前设备的通道数
d.ChannelCount = len(msg.DeviceChannelList) d.ChannelCount = msg.SumNum
d.UpdateTime = time.Now() d.UpdateTime = time.Now()
if err := d.plugin.DB.Save(d).Error; err != nil { if err := d.plugin.DB.Save(d).Error; err != nil {
d.Error("save device failed", "error", err) d.Error("save device failed", "error", err)
@@ -146,6 +144,7 @@ func (d *Device) onMessage(req *sip.Request, tx sip.ServerTransaction, msg *gb28
d.Name = msg.DeviceName d.Name = msg.DeviceName
d.Manufacturer = msg.Manufacturer d.Manufacturer = msg.Manufacturer
d.Model = msg.Model d.Model = msg.Model
d.Firmware = msg.Firmware
// 更新设备信息到数据库 // 更新设备信息到数据库
if d.plugin.DB != nil { if d.plugin.DB != nil {
d.UpdateTime = time.Now() d.UpdateTime = time.Now()

View File

@@ -44,7 +44,7 @@ type GB28181ProPlugin struct {
m7s.Plugin m7s.Plugin
AutoInvite bool `default:"true" desc:"自动邀请"` AutoInvite bool `default:"true" desc:"自动邀请"`
Serial string `default:"34020000002000000001" desc:"sip 服务 id"` //sip 服务器 id, 默认 34020000002000000001 Serial string `default:"34020000002000000001" desc:"sip 服务 id"` //sip 服务器 id, 默认 34020000002000000001
Realm string `default:"3402000000" desc:"sip 服务域"` //sip 服务器域,默认 3402000000 Realm string `default:"3402000000" desc:"sip 服务域"` //sip 服务器域,默认 3402000000
Username string Username string
Password string Password string
Sip SipConfig Sip SipConfig
@@ -510,23 +510,24 @@ func (gb *GB28181ProPlugin) StoreDevice(deviceid string, req *sip.Request) (d *D
now := time.Now() now := time.Now()
d = &Device{ d = &Device{
DeviceID: deviceid, DeviceID: deviceid,
CreateTime: now, CreateTime: now,
UpdateTime: now, UpdateTime: now,
RegisterTime: now, RegisterTime: now,
Status: DeviceRegisterStatus, KeepaliveTime: now,
Online: true, Status: DeviceRegisterStatus,
StreamMode: "UDP", // 默认UDP传输 Online: true,
Charset: "GB2312", // 默认GB2312字符集 StreamMode: "UDP", // 默认UDP传输
GeoCoordSys: "WGS84", // 默认WGS84坐标系 Charset: "GB2312", // 默认GB2312字符集
Transport: req.Transport(), // 传输协议 GeoCoordSys: "WGS84", // 默认WGS84坐标系
IP: hostname, Transport: req.Transport(), // 传输协议
Port: port, IP: hostname,
HostAddress: hostname + ":" + portStr, Port: port,
LocalIP: host, HostAddress: hostname + ":" + portStr,
mediaIp: host, LocalIP: host,
Expires: int(expSec), mediaIp: host,
eventChan: make(chan any, 10), Expires: int(expSec),
eventChan: make(chan any, 10),
Recipient: sip.Uri{ Recipient: sip.Uri{
Host: hostname, Host: hostname,
Port: port, Port: port,

File diff suppressed because it is too large Load Diff

View File

@@ -488,25 +488,25 @@ message Channel {
int32 RegisterWay = 12; int32 RegisterWay = 12;
int32 Secrecy =13; int32 Secrecy =13;
string Status =14; string Status =14;
google.protobuf.Timestamp gpsTime=15; google.protobuf.Timestamp GpsTime=15;
string Longitude = 16; string Longitude = 16;
string Latitude = 17; string Latitude = 17;
} }
message Device { message Device {
string id = 1; string DeviceID = 1;
string name = 2; string Name = 2;
string manufacturer = 3; string Manufacturer = 3;
string model = 4; string Model = 4;
string owner = 5; string Longitude = 5;
google.protobuf.Timestamp gpsTime=6; string Latitude = 6;
string longitude = 7; string Status = 9;
string latitude = 8; google.protobuf.Timestamp RegisterTime=10;
string status = 9; google.protobuf.Timestamp UpdateTime=11;
google.protobuf.Timestamp registerTime=10; google.protobuf.Timestamp KeepAliveTime=12;
google.protobuf.Timestamp updateTime=11; int32 ChannelCount = 13;
repeated Channel channels = 12; bool Online = 14;
bool online = 13; repeated Channel Channels = 15;
} }
message ResponseList { message ResponseList {

View File

@@ -119,6 +119,7 @@ type (
Manufacturer string Manufacturer string
Model string Model string
Channel string Channel string
Firmware string
DeviceChannelList []DeviceChannel `xml:"DeviceList>Item"` DeviceChannelList []DeviceChannel `xml:"DeviceList>Item"`
RecordList struct { RecordList struct {
Num int `xml:"Num,attr"` Num int `xml:"Num,attr"`