Former-commit-id: fa49ed844da2a9896f308f94c9f2eb7f128c3875
TangShanKaiPing
wanggang 6 years ago
parent 0b22a69457
commit c6e7e75b57

@ -86,5 +86,8 @@
public const string DeleteIoTTiggerRequest = nameof(DeleteIoTTiggerRequest);
public const string DeleteIoTTiggerResponse = nameof(DeleteIoTTiggerResponse);
public const string UpdateDvr = nameof(UpdateDvr);
public const string UpdateCamera = nameof(UpdateCamera);
}
}

@ -6,10 +6,13 @@ using Infrastructure.Extensions;
using Infrastructure.Web.SignalR;
using IoT.Shared.Services;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Vibrant.InfluxDB.Client;
using Vibrant.InfluxDB.Client.Rows;
@ -32,6 +35,7 @@ namespace IoTCenter.Services
private readonly IRepository<IoTTimer> _iotTimerRepo;
private readonly IRepository<IoTTigger> _iotTiggerRepo;
private readonly DataService _dataService;
private readonly IHttpClientFactory _httpClientFactory;
public IoTCenterHub(IConfiguration cfg,
IEventPublisher eventPublisher,
@ -46,7 +50,8 @@ namespace IoTCenter.Services
IRepository<SceneCommand> sceneCommandRepo,
IRepository<IoTTimer> iotTimerRepo,
IRepository<IoTTigger> iotTiggerRepo,
DataService dataService)
DataService dataService,
IHttpClientFactory httpClientFactory)
{
this._cfg = cfg;
this._eventPublisher = eventPublisher;
@ -62,6 +67,7 @@ namespace IoTCenter.Services
this._iotTimerRepo = iotTimerRepo;
this._iotTiggerRepo = iotTiggerRepo;
this._dataService = dataService;
this._httpClientFactory = httpClientFactory;
}
public void ServerToClient(string method, string message, string toClient, string fromClient = null)
@ -272,11 +278,78 @@ namespace IoTCenter.Services
{
this.ServerToClient(method, message, to, from);
}
else if (method == Methods.UpdateDvr)
{
var model = message.FromJson<Data>();
this.UpdateDvr(model);
}
}
catch (Exception ex)
{
ex.PrintStack();
}
}
private void UpdateDvr(Data model)
{
try
{
var device = this._deviceRepo.ReadOnlyTable().Include(o => o.Node).FirstOrDefault(o => o.Id == model.DeviceId);
var number = device.Node.Number;
var url = this._cfg.GetValue<string>("srs", "http://localhost:1985");
var result = "";
var method = Methods.UpdateCamera;
if (model.Value == "是")
{
var url2 = url + $"/api/v1/raw?rpc=update&scope=dvr&value=__defaultVhost__&param=enable&data=live/main{device.Number}";
if (CallSrs(url2))
{
this.ServerToClient(method, model.ToJson(), number);
}
url2 = url + $"/api/v1/raw?rpc=update&scope=dvr&value=__defaultVhost__&param=enable&data=live/sub{device.Number}";
if (CallSrs(url2))
{
this.ServerToClient(method, model.ToJson(), number);
}
}
else
{
var url2 = url + $"/api/v1/raw?rpc=update&scope=dvr&value=__defaultVhost__&param=disable&data=live/main{device.Number}";
if (CallSrs(url2))
{
this.ServerToClient(method, model.ToJson(), number);
}
url2 = url + $"/api/v1/raw?rpc=update&scope=dvr&value=__defaultVhost__&param=disable&data=live/sub{device.Number}";
if (CallSrs(url2))
{
this.ServerToClient(method, model.ToJson(), number);
}
}
}
catch (Exception ex)
{
ex.PrintStack();
}
}
private bool CallSrs(string url)
{
var result = false;
try
{
var httpClient = this._httpClientFactory.CreateClient();
var response = httpClient.GetStringAsync(url).Result;
var json = JsonConvert.DeserializeObject<Dictionary<string, string>>(response);
if (json["code"] == "0")
{
result = true;
}
}
catch (Exception ex)
{
ex.PrintStack();
}
return result;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")]

@ -366,6 +366,12 @@ namespace IoT.Shared.Services
var id = message.FromJson<Guid>();
this.ExecCommand(id);
}
else if (method == Methods.UpdateCamera)
{
var model = message.FromJson<EditDataModel>();
dataService.Edit<Data, EditDataModel>(model);
this.ClientToServer(method, model, null);
}
}
catch (Exception ex)
{

@ -33,6 +33,7 @@ namespace IoTCenter
new EFConfigurationValue { Id = "influxdb:url", Value= $"http://{host}:8086"},
new EFConfigurationValue { Id = "influxdb:usr", Value= "admin"},
new EFConfigurationValue { Id = "influxdb:pwd", Value= "admin"},
new EFConfigurationValue { Id = "srs", Value= "http://localhost:1985"},
//
new EFConfigurationValue { Id = "name", Value= "物联网管控平台"},
new EFConfigurationValue { Id = "logo", Value= "/images/logo.png",Type= InputType.ImageUrl},

@ -198,6 +198,8 @@
<h3 class="card-title">{{model.DisplayName}}</h3>
<input type="hidden" id="camera" :value="model.Number" />
<div class="card-tools">
<button class="btn btn-success" v-on:click="CallApi(model.Number,'/Onvif/StartRecord')">开始录像</button>
<button class="btn btn-success" v-on:click="CallApi(model.Number,'/Onvif/StopRecord')">停止录像</button>
<button class="btn btn-success" v-on:click="CallApi(model.Number,'/Onvif/StartPush')">开始推流</button>
<button class="btn btn-success" v-on:click="CallApi(model.Number,'/Onvif/StopPush')">停止推流</button>
</div>

@ -102,7 +102,7 @@ namespace IoTNode.Controllers
{
return this.AsyncAction(() =>
{
this._deviceService.StartPush(number);
this._deviceService.SetPush(number, true);
});
}
@ -111,7 +111,25 @@ namespace IoTNode.Controllers
{
return this.AsyncAction(() =>
{
this._deviceService.StopPush(number);
this._deviceService.SetPush(number, false);
});
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
public ApiResponse StartRecord([SwaggerParameter("设备编号")]string number)
{
return this.AsyncAction(() =>
{
this._deviceService.SetRecordStart(number, true);
});
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
public ApiResponse StopRecord([SwaggerParameter("设备编号")]string number)
{
return this.AsyncAction(() =>
{
this._deviceService.SetRecordStart(number, false);
});
}
}

@ -568,7 +568,7 @@ namespace IoTNode.DeviceServices.Onvif
return hc.GetByteDigest(new Uri(url), camera.UserName, camera.Password);
}
public void StartPush(string number)
public void SetPush(string number, bool state)
{
using (var scope = _applicationServices.CreateScope())
{
@ -579,15 +579,22 @@ namespace IoTNode.DeviceServices.Onvif
var data = device.Data.FirstOrDefault(o => o.Key == "Push");
if (data != null)
{
data.Value = "是";
data.Value = state ? "是" : "否";
this.UpdateData(repo, device, data);
this.StartPushToServer(device);
if (state)
{
this.StartPushToServer(device);
}
else
{
this.StopPushToServer(device.Number);
}
}
}
}
}
public void StopPush(string number)
public void SetRecordStart(string number, bool state)
{
using (var scope = _applicationServices.CreateScope())
{
@ -595,12 +602,12 @@ namespace IoTNode.DeviceServices.Onvif
var device = repo.Table().Include(o => o.Data).FirstOrDefault(o => o.Number == number);
if (device != null)
{
var data = device.Data.FirstOrDefault(o => o.Key == "Push");
var data = device.Data.FirstOrDefault(o => o.Key == "Record");
if (data != null)
{
data.Value = "否";
this.UpdateData(repo, device, data);
this.StopPushToServer(device.Number);
data.Value = state ? "是" : "否";
//this.UpdateData(repo, device, data);
this.SendToServer(Methods.UpdateDvr, data);
}
}
}

Loading…
Cancel
Save