mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-09-26 23:05:55 +08:00
feat: devicelist add trasnport,ip,port
This commit is contained in:
@@ -111,26 +111,35 @@ func (gb *GB28181Plugin) List(ctx context.Context, req *pb.GetDevicesRequest) (*
|
||||
})
|
||||
|
||||
pbDevices = append(pbDevices, &pb.Device{
|
||||
DeviceId: d.DeviceId,
|
||||
Name: d.CustomName,
|
||||
Manufacturer: d.Manufacturer,
|
||||
Model: d.Model,
|
||||
Status: string(d.Status),
|
||||
Online: d.Online,
|
||||
Longitude: d.Longitude,
|
||||
Latitude: d.Latitude,
|
||||
RegisterTime: timestamppb.New(d.RegisterTime),
|
||||
UpdateTime: timestamppb.New(d.UpdateTime),
|
||||
KeepAliveTime: timestamppb.New(d.KeepaliveTime),
|
||||
ChannelCount: int32(d.ChannelCount),
|
||||
Channels: pbChannels,
|
||||
MediaIp: d.MediaIp,
|
||||
SipIp: d.SipIp,
|
||||
Password: d.Password,
|
||||
StreamMode: string(d.StreamMode),
|
||||
DeviceId: d.DeviceId,
|
||||
Name: d.CustomName,
|
||||
Manufacturer: d.Manufacturer,
|
||||
Model: d.Model,
|
||||
Status: string(d.Status),
|
||||
Online: d.Online,
|
||||
Longitude: d.Longitude,
|
||||
Latitude: d.Latitude,
|
||||
RegisterTime: timestamppb.New(d.RegisterTime),
|
||||
UpdateTime: timestamppb.New(d.UpdateTime),
|
||||
KeepAliveTime: timestamppb.New(d.KeepaliveTime),
|
||||
ChannelCount: int32(d.ChannelCount),
|
||||
Channels: pbChannels,
|
||||
MediaIp: d.MediaIp,
|
||||
SipIp: d.SipIp,
|
||||
Password: d.Password,
|
||||
StreamMode: string(d.StreamMode),
|
||||
Transport: d.Transport,
|
||||
Ip: d.IP,
|
||||
Port: int32(d.Port),
|
||||
BroadcastPushAfterAck: d.BroadcastPushAfterAck,
|
||||
})
|
||||
}
|
||||
|
||||
// 按deviceId对设备列表进行排序
|
||||
sort.Slice(pbDevices, func(i, j int) bool {
|
||||
return pbDevices[i].DeviceId < pbDevices[j].DeviceId
|
||||
})
|
||||
|
||||
resp.Code = 0
|
||||
resp.Message = "success"
|
||||
resp.Data = pbDevices
|
||||
|
@@ -47,10 +47,6 @@ func (d *DeviceKeepaliveTickTask) Tick(any) {
|
||||
if d.device.KeepaliveInterval >= 5 {
|
||||
keepaliveSeconds = d.device.KeepaliveInterval
|
||||
}
|
||||
d.Debug("keepLiveTick", "deviceID", d.device.DeviceId,
|
||||
"keepaliveTime", d.device.KeepaliveTime,
|
||||
"interval", d.device.KeepaliveInterval,
|
||||
"count", d.device.KeepaliveCount)
|
||||
if timeDiff := time.Since(d.device.KeepaliveTime); timeDiff > time.Duration(d.device.KeepaliveCount*keepaliveSeconds)*time.Second {
|
||||
d.device.Online = false
|
||||
d.device.Status = DeviceOfflineStatus
|
||||
@@ -94,7 +90,7 @@ type Device struct {
|
||||
Password string // 密码
|
||||
SipIp string // SIP交互IP(设备访问平台的IP)
|
||||
AsMessageChannel bool // 是否作为消息通道
|
||||
BroadcastPushAfterAck bool // 控制语音对讲流程,释放收到ACK后发流
|
||||
BroadcastPushAfterAck bool `gorm:"default:false" default:"false"` // 控制语音对讲流程,释放收到ACK后发流
|
||||
DeletedAt gorm.DeletedAt `yaml:"-"`
|
||||
// 删除强关联字段
|
||||
// channels []gb28181.DeviceChannel `gorm:"foreignKey:DeviceDBID;references:ID"` // 设备通道列表
|
||||
@@ -203,7 +199,6 @@ func (c *catalogHandlerTask) Run() (err error) {
|
||||
d := c.d
|
||||
msg := c.msg
|
||||
catalogReq, exists := d.catalogReqs.Get(msg.SN)
|
||||
d.Debug("into catalog", "msg.SN", msg.SN, "exists", exists)
|
||||
if !exists {
|
||||
// 创建新的目录请求
|
||||
catalogReq = &CatalogRequest{
|
||||
@@ -214,7 +209,6 @@ func (c *catalogHandlerTask) Run() (err error) {
|
||||
Promise: util.NewPromise(context.Background()),
|
||||
}
|
||||
d.catalogReqs.Set(catalogReq)
|
||||
d.Debug("into catalog", "msg.SN", msg.SN, "d.catalogReqs", d.catalogReqs.Length)
|
||||
}
|
||||
|
||||
// 添加响应并获取是否是第一个响应
|
||||
@@ -223,7 +217,6 @@ func (c *catalogHandlerTask) Run() (err error) {
|
||||
// 更新设备信息到数据库
|
||||
// 如果是第一个响应,将所有通道状态标记为OFF
|
||||
if isFirst {
|
||||
d.Debug("将所有通道状态标记为OFF", "deviceId", d.DeviceId)
|
||||
// 标记所有通道为OFF状态
|
||||
d.channels.Range(func(channel *Channel) bool {
|
||||
if channel.DeviceChannel != nil {
|
||||
@@ -242,7 +235,6 @@ func (c *catalogHandlerTask) Run() (err error) {
|
||||
if c.CustomChannelId == "" {
|
||||
c.CustomChannelId = c.ChannelId
|
||||
}
|
||||
d.Debug("msg.DeviceList.DeviceChannelList range", "c.ChannelId", c.ChannelId, "c.Status", c.Status)
|
||||
// 使用 Save 进行 upsert 操作
|
||||
d.addOrUpdateChannel(c)
|
||||
catalogReq.TotalCount++
|
||||
@@ -251,21 +243,9 @@ func (c *catalogHandlerTask) Run() (err error) {
|
||||
// 更新当前设备的通道数
|
||||
d.ChannelCount = msg.SumNum
|
||||
d.UpdateTime = time.Now()
|
||||
d.Debug("save channel", "deviceid", d.DeviceId, " d.channels.Length", d.channels.Length, "d.ChannelCount", d.ChannelCount, "d.UpdateTime", d.UpdateTime)
|
||||
|
||||
// 删除所有状态为OFF的通道
|
||||
// d.channels.Range(func(channel *Channel) bool {
|
||||
// if channel.DeviceChannel != nil && channel.DeviceChannel.Status == gb28181.ChannelOffStatus {
|
||||
// d.Debug("删除不存在的通道", "channelId", channel.ID)
|
||||
// d.channels.RemoveByKey(channel.ID)
|
||||
// d.plugin.channels.RemoveByKey(channel.ID)
|
||||
// }
|
||||
// return true
|
||||
// })
|
||||
|
||||
// 在所有通道都添加完成后,检查是否完成接收
|
||||
if catalogReq.IsComplete() {
|
||||
d.Debug("IsComplete")
|
||||
catalogReq.Resolve()
|
||||
d.catalogReqs.RemoveByKey(msg.SN)
|
||||
}
|
||||
@@ -273,7 +253,6 @@ func (c *catalogHandlerTask) Run() (err error) {
|
||||
}
|
||||
|
||||
func (d *Device) onMessage(req *sip.Request, tx sip.ServerTransaction, msg *gb28181.Message) (err error) {
|
||||
d.plugin.Debug("into onMessage", "deviceid is ", d.DeviceId, "msg is", msg)
|
||||
source := req.Source()
|
||||
hostname, portStr, _ := net.SplitHostPort(source)
|
||||
port, _ := strconv.Atoi(portStr)
|
||||
@@ -285,11 +264,6 @@ func (d *Device) onMessage(req *sip.Request, tx sip.ServerTransaction, msg *gb28
|
||||
d.Port = port
|
||||
d.HostAddress = hostname + ":" + portStr
|
||||
var body []byte
|
||||
//d.Online = true
|
||||
//if d.Status != DeviceOnlineStatus {
|
||||
// d.Status = DeviceOnlineStatus
|
||||
//}
|
||||
//d.Debug("OnMessage", "cmdType", msg.CmdType, "body", string(req.Body()))
|
||||
switch msg.CmdType {
|
||||
case "Keepalive":
|
||||
d.KeepaliveInterval = int(time.Since(d.KeepaliveTime).Seconds())
|
||||
@@ -297,7 +271,6 @@ func (d *Device) onMessage(req *sip.Request, tx sip.ServerTransaction, msg *gb28
|
||||
d.KeepaliveInterval = 60
|
||||
}
|
||||
d.KeepaliveTime = time.Now()
|
||||
d.Debug("into keeplive,deviceid is ", d.DeviceId, "d.KeepaliveTime is", d.KeepaliveTime, "d.KeepaliveInterval is", d.KeepaliveInterval)
|
||||
if d.plugin.DB != nil {
|
||||
if err := d.plugin.DB.Model(d).Updates(map[string]interface{}{
|
||||
"keepalive_interval": d.KeepaliveInterval,
|
||||
@@ -399,7 +372,6 @@ func (d *Device) onMessage(req *sip.Request, tx sip.ServerTransaction, msg *gb28
|
||||
d.UpdateTime = time.Now()
|
||||
case "DeviceInfo":
|
||||
// 主设备信息
|
||||
d.Info("DeviceInfo message", "body", req.Body(), "d.Name", d.Name, "d.DeviceId", d.DeviceId, "msg.DeviceName", msg.DeviceName)
|
||||
if msg.DeviceName != "" {
|
||||
d.Name = msg.DeviceName
|
||||
if d.CustomName == "" {
|
||||
@@ -646,7 +618,6 @@ func (d *Device) addOrUpdateChannel(c gb28181.DeviceChannel) {
|
||||
// 更新通道信息
|
||||
channel.DeviceChannel = &c
|
||||
d.channels.Range(func(channel *Channel) bool {
|
||||
d.Debug("range d.channels", "channel.ChannelId", channel.ChannelId, "channel.status", channel.Status)
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
|
@@ -917,29 +917,33 @@ func (x *Channel) GetLatitude() string {
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
DeviceId string `protobuf:"bytes,1,opt,name=deviceId,proto3" json:"deviceId,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Manufacturer string `protobuf:"bytes,3,opt,name=manufacturer,proto3" json:"manufacturer,omitempty"`
|
||||
Model string `protobuf:"bytes,4,opt,name=model,proto3" json:"model,omitempty"`
|
||||
Longitude string `protobuf:"bytes,5,opt,name=longitude,proto3" json:"longitude,omitempty"`
|
||||
Latitude string `protobuf:"bytes,6,opt,name=latitude,proto3" json:"latitude,omitempty"`
|
||||
Status string `protobuf:"bytes,7,opt,name=status,proto3" json:"status,omitempty"`
|
||||
MediaIp string `protobuf:"bytes,8,opt,name=mediaIp,proto3" json:"mediaIp,omitempty"`
|
||||
RegisterTime *timestamppb.Timestamp `protobuf:"bytes,9,opt,name=registerTime,proto3" json:"registerTime,omitempty"`
|
||||
UpdateTime *timestamppb.Timestamp `protobuf:"bytes,10,opt,name=updateTime,proto3" json:"updateTime,omitempty"`
|
||||
KeepAliveTime *timestamppb.Timestamp `protobuf:"bytes,11,opt,name=keepAliveTime,proto3" json:"keepAliveTime,omitempty"`
|
||||
ChannelCount int32 `protobuf:"varint,12,opt,name=channelCount,proto3" json:"channelCount,omitempty"`
|
||||
Online bool `protobuf:"varint,13,opt,name=online,proto3" json:"online,omitempty"`
|
||||
Channels []*Channel `protobuf:"bytes,14,rep,name=channels,proto3" json:"channels,omitempty"`
|
||||
SipIp string `protobuf:"bytes,15,opt,name=sipIp,proto3" json:"sipIp,omitempty"`
|
||||
StreamMode string `protobuf:"bytes,16,opt,name=streamMode,proto3" json:"streamMode,omitempty"`
|
||||
Password string `protobuf:"bytes,17,opt,name=password,proto3" json:"password,omitempty"`
|
||||
SubscribeCatalog bool `protobuf:"varint,18,opt,name=subscribeCatalog,proto3" json:"subscribeCatalog,omitempty"`
|
||||
SubscribePosition bool `protobuf:"varint,19,opt,name=subscribePosition,proto3" json:"subscribePosition,omitempty"`
|
||||
SubscribeAlarm bool `protobuf:"varint,20,opt,name=subscribeAlarm,proto3" json:"subscribeAlarm,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
DeviceId string `protobuf:"bytes,1,opt,name=deviceId,proto3" json:"deviceId,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Manufacturer string `protobuf:"bytes,3,opt,name=manufacturer,proto3" json:"manufacturer,omitempty"`
|
||||
Model string `protobuf:"bytes,4,opt,name=model,proto3" json:"model,omitempty"`
|
||||
Longitude string `protobuf:"bytes,5,opt,name=longitude,proto3" json:"longitude,omitempty"`
|
||||
Latitude string `protobuf:"bytes,6,opt,name=latitude,proto3" json:"latitude,omitempty"`
|
||||
Status string `protobuf:"bytes,7,opt,name=status,proto3" json:"status,omitempty"`
|
||||
MediaIp string `protobuf:"bytes,8,opt,name=mediaIp,proto3" json:"mediaIp,omitempty"`
|
||||
RegisterTime *timestamppb.Timestamp `protobuf:"bytes,9,opt,name=registerTime,proto3" json:"registerTime,omitempty"`
|
||||
UpdateTime *timestamppb.Timestamp `protobuf:"bytes,10,opt,name=updateTime,proto3" json:"updateTime,omitempty"`
|
||||
KeepAliveTime *timestamppb.Timestamp `protobuf:"bytes,11,opt,name=keepAliveTime,proto3" json:"keepAliveTime,omitempty"`
|
||||
ChannelCount int32 `protobuf:"varint,12,opt,name=channelCount,proto3" json:"channelCount,omitempty"`
|
||||
Online bool `protobuf:"varint,13,opt,name=online,proto3" json:"online,omitempty"`
|
||||
Channels []*Channel `protobuf:"bytes,14,rep,name=channels,proto3" json:"channels,omitempty"`
|
||||
SipIp string `protobuf:"bytes,15,opt,name=sipIp,proto3" json:"sipIp,omitempty"`
|
||||
StreamMode string `protobuf:"bytes,16,opt,name=streamMode,proto3" json:"streamMode,omitempty"`
|
||||
Password string `protobuf:"bytes,17,opt,name=password,proto3" json:"password,omitempty"`
|
||||
SubscribeCatalog bool `protobuf:"varint,18,opt,name=subscribeCatalog,proto3" json:"subscribeCatalog,omitempty"`
|
||||
SubscribePosition bool `protobuf:"varint,19,opt,name=subscribePosition,proto3" json:"subscribePosition,omitempty"`
|
||||
SubscribeAlarm bool `protobuf:"varint,20,opt,name=subscribeAlarm,proto3" json:"subscribeAlarm,omitempty"`
|
||||
Transport string `protobuf:"bytes,21,opt,name=transport,proto3" json:"transport,omitempty"`
|
||||
Ip string `protobuf:"bytes,22,opt,name=ip,proto3" json:"ip,omitempty"`
|
||||
Port int32 `protobuf:"varint,23,opt,name=port,proto3" json:"port,omitempty"`
|
||||
BroadcastPushAfterAck bool `protobuf:"varint,24,opt,name=broadcastPushAfterAck,proto3" json:"broadcastPushAfterAck,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *Device) Reset() {
|
||||
@@ -1112,6 +1116,34 @@ func (x *Device) GetSubscribeAlarm() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Device) GetTransport() string {
|
||||
if x != nil {
|
||||
return x.Transport
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Device) GetIp() string {
|
||||
if x != nil {
|
||||
return x.Ip
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Device) GetPort() int32 {
|
||||
if x != nil {
|
||||
return x.Port
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Device) GetBroadcastPushAfterAck() bool {
|
||||
if x != nil {
|
||||
return x.BroadcastPushAfterAck
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type ResponseList struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
|
||||
@@ -6332,7 +6364,7 @@ const file_gb28181_proto_rawDesc = "" +
|
||||
"\x06status\x18\x10 \x01(\tR\x06status\x124\n" +
|
||||
"\agpsTime\x18\x11 \x01(\v2\x1a.google.protobuf.TimestampR\agpsTime\x12\x1c\n" +
|
||||
"\tlongitude\x18\x12 \x01(\tR\tlongitude\x12\x1a\n" +
|
||||
"\blatitude\x18\x13 \x01(\tR\blatitude\"\xdd\x05\n" +
|
||||
"\blatitude\x18\x13 \x01(\tR\blatitude\"\xd5\x06\n" +
|
||||
"\x06Device\x12\x1a\n" +
|
||||
"\bdeviceId\x18\x01 \x01(\tR\bdeviceId\x12\x12\n" +
|
||||
"\x04name\x18\x02 \x01(\tR\x04name\x12\"\n" +
|
||||
@@ -6358,7 +6390,11 @@ const file_gb28181_proto_rawDesc = "" +
|
||||
"\bpassword\x18\x11 \x01(\tR\bpassword\x12*\n" +
|
||||
"\x10subscribeCatalog\x18\x12 \x01(\bR\x10subscribeCatalog\x12,\n" +
|
||||
"\x11subscribePosition\x18\x13 \x01(\bR\x11subscribePosition\x12&\n" +
|
||||
"\x0esubscribeAlarm\x18\x14 \x01(\bR\x0esubscribeAlarm\"d\n" +
|
||||
"\x0esubscribeAlarm\x18\x14 \x01(\bR\x0esubscribeAlarm\x12\x1c\n" +
|
||||
"\ttransport\x18\x15 \x01(\tR\ttransport\x12\x0e\n" +
|
||||
"\x02ip\x18\x16 \x01(\tR\x02ip\x12\x12\n" +
|
||||
"\x04port\x18\x17 \x01(\x05R\x04port\x124\n" +
|
||||
"\x15broadcastPushAfterAck\x18\x18 \x01(\bR\x15broadcastPushAfterAck\"d\n" +
|
||||
"\fResponseList\x12\x12\n" +
|
||||
"\x04code\x18\x01 \x01(\x05R\x04code\x12\x18\n" +
|
||||
"\amessage\x18\x02 \x01(\tR\amessage\x12&\n" +
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -607,6 +607,10 @@ message Device {
|
||||
bool subscribeCatalog = 18;
|
||||
bool subscribePosition = 19;
|
||||
bool subscribeAlarm = 20;
|
||||
string transport = 21;
|
||||
string ip = 22;
|
||||
int32 port = 23;
|
||||
bool broadcastPushAfterAck =24;
|
||||
}
|
||||
|
||||
message ResponseList {
|
||||
|
Reference in New Issue
Block a user