Former-commit-id: 36119b14b94d4362be12b912f9b7626e57db6b1e
TangShanKaiPing
wanggang 5 years ago
parent a5aeb50131
commit 087a70cf96

@ -272,7 +272,31 @@ namespace IoTNode.DeviceServices.Onvif
}
}
private void StartPushToServer(Device camera)
public void StartPushToServer()
{
using var scope = _applicationServices.CreateScope();
var repo = scope.ServiceProvider.GetService<IRepository<Device>>();
var cameras = repo.ReadOnlyTable().Include(o => o.Data).Where(o => o.Name == "摄像头").ToList();
foreach (var camera in cameras)
{
try
{
if (camera.Data.Any(o => o.Key == "Push" && o.Value == "是"))
{
if (camera.Data.Any(o => o.Key == "NeedAuth" && o.Value == "否") || camera.Data.Any(o => o.Key == "HasAuth" && o.Value == "是"))
{
this.StartPushToServer(camera);
}
}
}
catch (Exception ex)
{
ex.PrintStack();
}
}
}
public void StartPushToServer(Device camera)
{
try
{
@ -337,6 +361,21 @@ namespace IoTNode.DeviceServices.Onvif
}
}
public void StopPushToServer()
{
foreach (var item in this._list.Keys)
{
try
{
this.StopPushToServer(item);
}
catch (Exception ex)
{
ex.PrintStack();
}
}
}
public void StopPushToServer(string key)
{
if (this._list.TryRemove(key, out Process process))

@ -1,14 +1,17 @@
using Application.Domain.Entities;
using CSScriptLib;
using Hangfire;
using Infrastructure.Application.Entites.Settings;
using Infrastructure.Events;
using Infrastructure.Extensions;
using IoTNode.DeviceServices.Onvif;
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
namespace IoTNode.Services
{
public class IoTNodeEventHandler :
IEventHander<EntityUpdatedEvent<Setting>>,
IEventHander<EntityInsertedEvent<SceneTimer>>,
IEventHander<EntityUpdatedEvent<SceneTimer>>,
IEventHander<EntityDeletedEvent<SceneTimer>>,
@ -16,11 +19,13 @@ namespace IoTNode.Services
{
private readonly ISceneTiggerService _sceneTiggerService;
private readonly IoTNodeJob _job;
private readonly OnvifService _onvifService;
public IoTNodeEventHandler(ISceneTiggerService sceneTiggerService, IoTNodeJob job)
public IoTNodeEventHandler(ISceneTiggerService sceneTiggerService, IoTNodeJob job, OnvifService onvifService)
{
this._sceneTiggerService = sceneTiggerService;
this._job = job;
this._onvifService = onvifService;
}
public void Handle(EntityInsertedEvent<SceneTimer> message)
@ -63,5 +68,15 @@ namespace IoTNode.Services
}
}
}
public void Handle(EntityUpdatedEvent<Setting> message)
{
if (message.Data.Name == "stream.rtmp" || message.Data.Name == "ffmpeg.args")
{
Task.Delay(1000);
this._onvifService.StopPushToServer();
this._onvifService.StartPushToServer();
}
}
}
}

@ -1,4 +1,4 @@
using System.Reflection;
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyInformationalVersion("1.0.0.4293")]
[assembly: AssemblyInformationalVersion("1.0.0.430")]
Loading…
Cancel
Save