From f39c2cb204a56cb363e5f810fff4f267811634ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=B3=E9=A9=B9=20=E4=B8=87?= Date: Wed, 24 Jul 2024 20:38:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4=E4=B8=8A?= =?UTF-8?q?=E6=8A=A5=E7=B3=BB=E7=BB=9F=E7=9B=AE=E5=BD=95=E9=A1=B9=EF=BC=8C?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=9A=82=E6=9C=AA=E6=94=AF=E6=8C=81=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SipServer/Cascade/CascadeClient.cs | 32 +++++++++++++++++---------- SipServer/Cascade/CascadeManager.cs | 34 ++++++++++++++++++++++++++--- SipServer/GBClient.cs | 2 +- SipServer/Models/SuperiorChannel.cs | 11 +++++++++- 4 files changed, 62 insertions(+), 17 deletions(-) diff --git a/SipServer/Cascade/CascadeClient.cs b/SipServer/Cascade/CascadeClient.cs index 277f8c9..1eb93a2 100644 --- a/SipServer/Cascade/CascadeClient.cs +++ b/SipServer/Cascade/CascadeClient.cs @@ -272,24 +272,28 @@ protected internal void AddChannel(SuperiorChannel item) Model = item.Model, Owner = item.Owner, CivilCode = item.CivilCode, - Block = item.Block, + Block = Empty2Null(item.Block), Address = item.Address, - Parental = item.Parental ? 1 : 0, ParentID = item.ParentId, - BusinessGroupID = item.BusinessGroupId, - SafetyWay = item.SafetyWay, + BusinessGroupID = Empty2Null(item.BusinessGroupId), RegisterWay = item.RegisterWay, - CertNum = item.CertNum, - Certifiable = item.Certifiable ? 1 : 0, - ErrCode = item.ErrCode, - EndTime = item.EndTime?.ToTStr(), Secrecy = item.Secrecy ? 1 : 0, - IPAddress = item.Ipaddress, - Password = item.Password, + IPAddress = Empty2Null(item.Ipaddress), + Password = Empty2Null(item.Password), Status = item.Status, - Longitude = item.Longitude, - Latitude = item.Latitude, }; + if (item.IsDevice) + { + ci.Parental = item.Parental ? 1 : 0; + ci.SafetyWay = item.SafetyWay; + } + if (item.EndTime.HasValue) + { + ci.CertNum = item.CertNum; + ci.Certifiable = item.Certifiable ? 1 : 0; + ci.ErrCode = item.ErrCode; + ci.EndTime = item.EndTime.Value.ToTStr(); + } if (item.Port > 0) ci.Port = (ushort)item.Port; if (item.Longitude > 0) @@ -304,5 +308,9 @@ protected internal void RemoveChannel(string ChannelId) ditChild.TryRemove(ChannelId, out var citem); } + private static string Empty2Null(string val) + { + return string.IsNullOrEmpty(val) ? null : val; + } } } diff --git a/SipServer/Cascade/CascadeManager.cs b/SipServer/Cascade/CascadeManager.cs index 6e1aca8..ff7618b 100644 --- a/SipServer/Cascade/CascadeManager.cs +++ b/SipServer/Cascade/CascadeManager.cs @@ -90,15 +90,43 @@ public async Task Remove(params string[] ids) } async Task AddClient(TSuperiorInfo sinfo) { - var channels = await sipServer.DB.GetSuperiorChannels(sinfo.Id); + var tmp = await sipServer.DB.GetSuperiorChannels(sinfo.Id); + var id = sinfo.ClientId; + var ClientName = string.IsNullOrEmpty(sinfo.ClientName) ? sinfo.Name : sinfo.ClientName; + var root = new SuperiorChannel(new TCatalog + { + ChannelId = id, + DeviceId = id, + Name = ClientName, + Manufacturer = "RTVS", + Model = "gbsip", + Owner = "Owner", + CivilCode = id.Substring(0, 6), + Address = "Address", + RegisterWay = 1, + Secrecy = false, + }, + null, + false + ); + var channels = new List + { + //添加系统目录项 + root + }; + foreach (var channel in tmp) + { + channel.ParentId = id; + channels.Add(channel); + } CascadeClient client = new CascadeClient(this, sinfo.Id, SuperiorInfoEx.GetServerSipStr(sinfo), sinfo.ServerId, new GB28181.XML.DeviceInfo { DeviceID = sinfo.ClientId, - DeviceName = string.IsNullOrEmpty(sinfo.ClientName) ? sinfo.Name : sinfo.ClientName, + DeviceName = ClientName, Manufacturer = "RTVS", Model = "gbsip", Result = "OK", - Firmware = "v0.1" + Firmware = "v0.2" }, channels, authUsername: sinfo.Sipusername, password: sinfo.Sippassword, expiry: sinfo.Expiry, UserAgent: sipServer.UserAgent, EnableTraceLogs: sipServer.Settings.EnableSipLog, heartSec: sinfo.HeartSec, timeOutSec: sinfo.HeartTimeoutTimes * sinfo.HeartSec , localPort: sinfo.ClientPort); diff --git a/SipServer/GBClient.cs b/SipServer/GBClient.cs index 8314110..12d0d0f 100644 --- a/SipServer/GBClient.cs +++ b/SipServer/GBClient.cs @@ -419,7 +419,7 @@ async Task MessageProcess(SIPEndPoint localSipEndPoint, SIPEndPoint remoteEndPoi RegisterWay = item.RegisterWay.HasValue ? item.RegisterWay.Value : 1, SafetyWay = item.SafetyWay.HasValue ? item.SafetyWay.Value : 0, Secrecy = item.Secrecy == 1, - Status = item.Status, + Status = item.Status ?? "", Online = "ON".IgnoreEquals(item.Status), }; if (string.IsNullOrWhiteSpace(citem.ParentId) || citem.ParentId == ServerID) diff --git a/SipServer/Models/SuperiorChannel.cs b/SipServer/Models/SuperiorChannel.cs index 7985f9a..307beab 100644 --- a/SipServer/Models/SuperiorChannel.cs +++ b/SipServer/Models/SuperiorChannel.cs @@ -12,7 +12,11 @@ namespace SipServer.Models { public class SuperiorChannel : TCatalog { - public SuperiorChannel(TCatalog item, TSuperiorChannel channel) + public SuperiorChannel(TCatalog item, TSuperiorChannel channel) : this(item, channel, true) + { + + } + public SuperiorChannel(TCatalog item, TSuperiorChannel channel, bool isDevice) { ChannelId = item.ChannelId; DeviceId = item.DeviceId; @@ -50,6 +54,7 @@ public SuperiorChannel(TCatalog item, TSuperiorChannel channel) Enable = channel.Enable; CustomChannelId = channel.CustomChannelId; } + IsDevice = isDevice; } public ulong RowId { get; set; } /// @@ -64,6 +69,10 @@ public SuperiorChannel(TCatalog item, TSuperiorChannel channel) /// 自定义通道ID /// public string CustomChannelId { get; set; } + /// + /// 设备/目录 + /// + public bool IsDevice { get; set; } public string GetChannelId() {