fix: add platform from config.yaml,add example into default/config.yaml

This commit is contained in:
pggiroro
2025-06-06 08:59:25 +08:00
parent 67186cd669
commit 7282f1f44d
3 changed files with 66 additions and 40 deletions

View File

@@ -15,13 +15,33 @@ gb28181:
sip:
listenaddr:
- udp::5060
# pull:
# live/test: dump/34020000001320000001
onsub:
pull:
^\d{20}/\d{20}$: $0
^gb_\d+/(.+)$: $1
# .* : $0
platforms:
- enable: false #是否启用平台
name: "测试平台" #平台名称
servergbid: "34020000002000000002" #上级平台GBID
servergbdomain: "3402000000" #上级平台GB域
serverip: 192.168.1.106 #上级平台IP
serverport: 5061 #上级平台端口
devicegbid: "34020000002000000001" #本平台设备GBID
deviceip: 192.168.1.106 #本平台设备IP
deviceport: 5060 #本平台设备端口
username: "34020000002000000001" #SIP账号
password: "123456" #SIP密码
expires: 3600 #注册有效期,单位秒
keeptimeout: 60 #注册保持超时时间,单位秒
civilCode: "340200" #行政区划代码
manufacturer: "Monibuca" #设备制造商
model: "GB28181" #设备型号
address: "江苏南京" #设备地址
register_way: 1
platformchannels:
- platformservergbid: "34020000002000000002" #上级平台GBID
channeldbid: "34020000001110000003_34020000001320000005" #通道DBID,格式为设备ID_通道ID
mp4:
# enable: false
# publish:

View File

@@ -44,7 +44,11 @@ type Dialog struct {
}
func (d *Dialog) GetCallID() string {
return d.session.InviteRequest.CallID().Value()
if d.session != nil && d.session.InviteRequest != nil && d.session.InviteRequest.CallID() != nil {
return d.session.InviteRequest.CallID().Value()
} else {
return ""
}
}
func (d *Dialog) GetPullJob() *m7s.PullJob {
@@ -126,7 +130,7 @@ func (d *Dialog) Start() (err error) {
if !d.IsLive() {
startTime, endTime, err := util.TimeRangeQueryParse(url.Values{"start": []string{d.start}, "end": []string{d.end}})
if err != nil {
d.Stop(errors.New("parse end time error"))
return errors.New("parse end time error")
}
sdpInfo = append(sdpInfo, fmt.Sprintf("t=%d %d", startTime.Unix(), endTime.Unix()))
} else {
@@ -163,7 +167,7 @@ func (d *Dialog) Start() (err error) {
"a=connection:new",
)
case "UDP":
d.Stop(errors.New("do not support udp mode"))
return errors.New("do not support udp mode")
default:
sdpInfo = append(sdpInfo,
"a=setup:passive",
@@ -238,7 +242,7 @@ func (d *Dialog) Start() (err error) {
//}
// 最后添加Content-Length头部
if err != nil {
d.gb.Error("invite error", err)
return errors.New("dialog invite error" + err.Error())
}
return
}
@@ -247,9 +251,8 @@ func (d *Dialog) Run() (err error) {
d.Channel.Info("before WaitAnswer")
err = d.session.WaitAnswer(d.gb, sipgo.AnswerOptions{})
d.Channel.Info("after WaitAnswer")
d.gb.Error(" WaitAnswer error", err)
if err != nil {
return
return errors.New("wait answer error" + err.Error())
}
inviteResponseBody := string(d.session.InviteResponse.Body())
d.Channel.Info("inviteResponse", "body", inviteResponseBody)

View File

@@ -377,45 +377,48 @@ func (gb *GB28181Plugin) checkPlatform() {
// 遍历所有平台进行初始化和注册
for _, platformModel := range platformModels {
// 创建Platform实例
platform := NewPlatform(platformModel, gb, true)
if platformModel.Enable {
if platformModel.PlatformChannels != nil && len(platformModel.PlatformChannels) > 0 {
for i := range platformModel.PlatformChannels {
channelDbId := platformModel.PlatformChannels[i].ChannelDBID
if channelDbId != "" {
if channel, ok := gb.channels.Get(channelDbId); ok {
platform.channels.Set(channel)
}
}
}
} else {
// 查询通道列表
var channels []gb28181.DeviceChannel
if gb.DB != nil {
if err := gb.DB.Table("gb28181_channel gc").
Select(`gc.*`).
Joins("left join gb28181_platform_channel gpc on gc.id=gpc.channel_db_id").
Where("gpc.platform_server_gb_id = ? and gc.status='ON'", platformModel.ServerGBID).
Find(&channels).Error; err != nil {
gb.Error("<UNK>", "error", err.Error())
}
if channels != nil && len(channels) > 0 {
for i := range channels {
if channel, ok := gb.channels.Get(channels[i].ID); ok {
// 创建Platform实例
platform := NewPlatform(platformModel, gb, true)
if platformModel.PlatformChannels != nil && len(platformModel.PlatformChannels) > 0 {
for i := range platformModel.PlatformChannels {
channelDbId := platformModel.PlatformChannels[i].ChannelDBID
if channelDbId != "" {
if channel, ok := gb.channels.Get(channelDbId); ok {
platform.channels.Set(channel)
}
}
}
} else {
// 查询通道列表
var channels []gb28181.DeviceChannel
if gb.DB != nil {
if err := gb.DB.Table("gb28181_channel gc").
Select(`gc.*`).
Joins("left join gb28181_platform_channel gpc on gc.id=gpc.channel_db_id").
Where("gpc.platform_server_gb_id = ? and gc.status='ON'", platformModel.ServerGBID).
Find(&channels).Error; err != nil {
gb.Error("<UNK>", "error", err.Error())
}
if channels != nil && len(channels) > 0 {
for i := range channels {
if channel, ok := gb.channels.Get(channels[i].ID); ok {
platform.channels.Set(channel)
}
}
}
}
}
//go platform.Unregister()
//if err != nil {
// gb.Error("unregister err ", err)
//}
// 添加到任务系统
gb.AddTask(platform)
gb.Info("平台初始化完成", "ID", platformModel.ServerGBID, "Name", platformModel.Name)
}
//go platform.Unregister()
//if err != nil {
// gb.Error("unregister err ", err)
//}
// 添加到任务系统
gb.AddTask(platform)
gb.Info("平台初始化完成", "ID", platformModel.ServerGBID, "Name", platformModel.Name)
}
}