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() {