Former-commit-id: b020f58232ec821fe8d8fc2d7e3c23af03c0b88b
TangShanKaiPing
wanggang 6 years ago
parent fc0914de48
commit 94d86c8f29

@ -12,6 +12,7 @@ namespace IoT.Shared.DeviceServices.Onvif
public string DiscoveryXml { get; set; }
public string GetCapabilitiesXml { get; set; }
public string DeviceUrl { get; set; }
public string Ip { get; set; }
public string Id { get; set; }
public string MediaUrl { get; set; }
public string GetProfilesXml { get; set; }
@ -36,6 +37,7 @@ namespace IoT.Shared.DeviceServices.Onvif
this.Id = doc.Descendants()
.FirstOrDefault(o => o.Name.LocalName == "EndpointReference").Elements()
.FirstOrDefault(o => o.Name.LocalName == "Address").Value.Replace("urn:uuid:", "").Replace("-", "");
this.Ip = Regex.Match(this.DeviceUrl, "//([^/]*)/").Groups[1].Value;
}
public void ParseCapabilities()
@ -48,6 +50,10 @@ namespace IoT.Shared.DeviceServices.Onvif
public void ParseProfiles()
{
if (string.IsNullOrEmpty(this.GetProfilesXml))
{
return;
}
var doc = XDocument.Parse(this.GetProfilesXml);
foreach (var item in doc.Descendants().Where(o => o.Name.LocalName == "Profiles"))
{

@ -89,6 +89,8 @@ namespace IoT.Shared.DeviceServices.Onvif
continue;
}
Console.WriteLine(ipCamera.DeviceUrl);
try
{
using (var scope = _applicationServices.CreateScope())
{
var productNumber = "onvifcamera";
@ -123,13 +125,14 @@ namespace IoT.Shared.DeviceServices.Onvif
{
Name = "摄像头",
Number = ipCamera.Id,
Ip = ipCamera.Ip,
Icon = "camera",
ProductId = product.Id,
NodeId = node.Id
};
var fileName = $"ffmpeg-{Helper.Instance.GetRunTime()}{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "")}";
var file = Path.Combine(this._env.WebRootPath, fileName);
device.AddorUpdateData(device.CreateData("Push", "", DeviceDataType.String, "推流"));
device.AddorUpdateData(device.CreateData("Push", "", DeviceDataType.String, "推流"));
device.AddorUpdateData(device.CreateData("Record", "否", DeviceDataType.String, "录像"));
device.AddorUpdateData(device.CreateData("ffmpeg.file", file, DeviceDataType.String, "ffmpeg路径", hidden: true));
device.AddorUpdateData(device.CreateData("ffmpeg.args", this._configuration["ffmpeg.args"], DeviceDataType.String, "ffmpeg.args", hidden: true));
@ -141,6 +144,7 @@ namespace IoT.Shared.DeviceServices.Onvif
device.AddorUpdateData(device.CreateData("subhls", $"http://{this._configuration["stream.hls"]}/live/sub{ipCamera.Id}.m3u8", DeviceDataType.String, "子码流hls"));
device.ConnectId = this._configuration["connectId"];
deviceRepo.Add(device);
deviceRepo.SaveChanges();
}
var profiles = this._onvifDeviceManagement.GetProfiles(ipCamera.DeviceUrl, ipCamera.MediaUrl);
var needAuth = false;
@ -194,6 +198,8 @@ namespace IoT.Shared.DeviceServices.Onvif
device.AddorUpdateData(device.CreateData("MainSnapshotUri", ipCamera.MainSnapshotUri, DeviceDataType.String, "主码流截图地址"));
device.AddorUpdateData(device.CreateData("SubStreamUri", ipCamera.SubStreamUri, DeviceDataType.String, "子码流地址"));
device.AddorUpdateData(device.CreateData("SubSnapshotUri", ipCamera.SubSnapshotUri, DeviceDataType.String, "子码流截图地址"));
try
{
var jpgBytes = ScreenShot(device);
using (var stream = new MemoryStream(jpgBytes))
{
@ -211,6 +217,11 @@ namespace IoT.Shared.DeviceServices.Onvif
}
}
}
}
catch (Exception ex)
{
ex.PrintStack();
}
deviceRepo.SaveChanges();
var deviceDto = device.To<EditDeviceModel>();
deviceDto.ProductNumber = product.Number;
@ -226,6 +237,11 @@ namespace IoT.Shared.DeviceServices.Onvif
this.SendToServer(Methods.EditDataResponse, dataList);
}
}
catch (Exception ex)
{
ex.PrintStack();
}
}
}
catch (Exception ex)
{

@ -13,7 +13,7 @@ namespace IoTNode
public static void Main(string[] args)
{
var host = "localhost";
var stream = "localhost";
var stream = "192.168.3.124";
WebHost.CreateDefaultBuilder(args)
.Run<Startup>(new List<EFConfigurationValue> {
new EFConfigurationValue { Id = "id", Value= "根据设备编号生成的授权码" },

@ -110,6 +110,7 @@ namespace IoTCenter.Controllers
.Include(o => o.Scenes)
.Include(o => o.Devices)
.ThenInclude(o => o.Data)
.Where(o => o.Number == number)
.FirstOrDefault(o => o.Number == number);
return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
}

@ -4,7 +4,7 @@
<div class="row" v-if="ViewModel">
<div class="col-md-6">
<select class="form-control" id="camera" @change="CameraSelected">
<option v-for="c in GetCameras()" :value="c.Number">{{c.Name}}</option>
<option v-for="c in GetCameras()" :value="c.Number">{{c.DisplayName||c.Name}}</option>
</select>
<div style="width:100%;height:265px;margin:0;padding:0;background:#000;">
<video id="flvPlayer" class="video" muted controls autoplay style="width:100%;max-width:100%;height:100%;"></video>

Loading…
Cancel
Save