Former-commit-id: a8503b61e4005b3dc023c96b7944f7694dd126a2
TangShanKaiPing
wanggang 6 years ago
parent eaddb73dbd
commit d4b3513b57

@ -301,29 +301,15 @@ namespace IoTCenter.Services
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);
}
url += $"/api/v1/raw?rpc=update&scope=dvr&value=__defaultVhost__&param=enable&data=live/{device.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);
}
url += $"/api/v1/raw?rpc=update&scope=dvr&value=__defaultVhost__&param=disable&data=live/{device.Number}";
}
if (CallSrs(url))
{
this.ServerToClient(method, model.ToJson(), number);
}
}
catch (Exception ex)

@ -0,0 +1,66 @@
using Application.Domain.Entities;
using Infrastructure.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace UserCenter.Controllers
{
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
[ApiController]
public class SrsController : ControllerBase
{
private readonly IConfiguration _cfg;
private readonly IRepository<Device> _deviceRepo;
private readonly IRepository<LiveRecord> _liveRecordRepo;
public SrsController(IConfiguration cfg,
IRepository<Device> deviceRepo,
IRepository<LiveRecord> liveRecordRepo)
{
this._cfg = cfg;
this._deviceRepo = deviceRepo;
this._liveRecordRepo = liveRecordRepo;
}
/// <summary>
/// 录制完毕事件响应
///{"action":"on_dvr","client_id":107,"ip":"192.168.3.124","vhost":"__defaultVhost__","app":"live","stream":"main0a5d5deee43011b483884cbd8fd2b3dd","param":"","cwd":"/root/publish/apps/srs","file":"./objs/nginx/html/live.main0a5d5deee43011b483884cbd8fd2b3dd.1574832559180.mp4"}
/// </summary>
/// <returns></returns>
[AllowAnonymous]
public string OnDvr()
{
using (var reader = new StreamReader(Request.Body))
{
var json = reader.ReadToEndAsync().Result;
Console.WriteLine("ondvr:");
Console.WriteLine(json);
var result = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
if (result["action"] == "on_dvr")
{
var streamId = result["stream"];
var device = this._deviceRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == streamId);
if (device != null)
{
this._liveRecordRepo.Add(new LiveRecord
{
DeviceNumber = device.Number,
DeviceName = device?.DisplayName,
Name = $"回放{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}",
Value = $"/video{result["file"].Substring(result["file"].LastIndexOf('/'))}"
});
this._liveRecordRepo.SaveChanges();
}
}
}
return string.Empty;
}
}
}

@ -1,5 +1,6 @@
@model EditLiveRecordModel
@{
HtmlTitle = Model.Name;
var url = Context.Request.Scheme + "://" + Context.Request.Host.Host + Model.Value;
}
<video id="videoElement" controls autoplay style="width:640px;height:480px;background-color:#000;" src="@Model.Value"></video>
<video controls muted autoplay style="width:640px;height:480px;background-color:#000;" src="@url"></video>

@ -409,12 +409,13 @@ namespace IoTCenter.Controllers
using (var reader = new StreamReader(Request.Body))
{
var json = reader.ReadToEndAsync().Result;
Console.WriteLine("onpublish:");
Console.WriteLine(json);
var result = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
if (result["action"] == "on_publish")
{
var streamId = result["stream"];
var deviceNumber = streamId.StartsWith("main") ? streamId.Substring(4) : streamId.Substring(3);
var device = this._deviceRepo.ReadOnlyTable().Include(o => o.Node).Include(o => o.Data).FirstOrDefault(o => o.Number == deviceNumber);
var device = this._deviceRepo.ReadOnlyTable().Include(o => o.Node).Include(o => o.Data).FirstOrDefault(o => o.Number == streamId);
if (device != null)
{
var data = device.Data.FirstOrDefault(o => o.Name == "录制");
@ -445,17 +446,18 @@ namespace IoTCenter.Controllers
using (var reader = new StreamReader(Request.Body))
{
var json = reader.ReadToEndAsync().Result;
Console.WriteLine("ondvr:");
Console.WriteLine(json);
var result = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
if (result["action"] == "on_dvr")
{
var streamId = result["stream"];
var deviceNumber = streamId.StartsWith("main") ? streamId.Substring(4) : streamId.Substring(3);
var device = this._deviceRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == deviceNumber);
var device = this._deviceRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == streamId);
if (device != null)
{
this._liveRecordRepo.Add(new LiveRecord
{
DeviceNumber = deviceNumber,
DeviceNumber = device.Number,
DeviceName = device?.DisplayName,
Name = $"回放{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}",
Value = $"/video{result["file"].Substring(result["file"].LastIndexOf('/'))}"

@ -29,14 +29,14 @@
<div style="box-sizing: border-box;width: 320px;margin: 5px auto;" :class="'row ptz '+ device.number">
<table style="width: 100%; height:100px;">
<tr>
<td colspan="2" style="text-align:center;"><button class="weui-btn weui-btn_mini weui-btn_default" v-on:click="execApi(model.number,'/Onvif/StartRecord')">启动推流</button></td>
<td colspan="2" style="text-align:center;"><button class="weui-btn weui-btn_mini weui-btn_default" v-on:click="execApi(device.number,'/Onvif/StartPush')">启动推流</button></td>
<td></td>
<td colspan="2" style="text-align:center;"><button class="weui-btn weui-btn_mini weui-btn_default" v-on:click="execApi(model.number,'/Onvif/StopRecord')">停止推流</button></td>
<td colspan="2" style="text-align:center;"><button class="weui-btn weui-btn_mini weui-btn_default" v-on:click="execApi(device.number,'/Onvif/StopPush')">停止推流</button></td>
</tr>
<tr>
<td colspan="2" style="text-align:center;"><button class="weui-btn weui-btn_mini weui-btn_default" v-on:click="execApi(model.number,'/Onvif/StartPush')">开始录像</button></td>
<td colspan="2" style="text-align:center;"><button class="weui-btn weui-btn_mini weui-btn_default" v-on:click="execApi(device.number,'/Onvif/StartRecord')">开始录像</button></td>
<td></td>
<td colspan="2" style="text-align:center;"><button class="weui-btn weui-btn_mini weui-btn_default" v-on:click="execApi(model.number,'/Onvif/StopPush')">停止录像</button></td>
<td colspan="2" style="text-align:center;"><button class="weui-btn weui-btn_mini weui-btn_default" v-on:click="execApi(device.number,'/Onvif/StopRecord')">停止录像</button></td>
</tr>
<template v-if="ptz">
<tr>
@ -130,7 +130,7 @@
clearInterval(vm.timer);
vm.playByFlvJs();
}
else if (vm.decodedFrames && vm.flvPlayer.statisticsInfo.decodedFrames <= decodedFrames) {
else if (vm.decodedFrames && vm.flvPlayer.statisticsInfo.decodedFrames <= vm.decodedFrames) {
console.log('reload2');
clearInterval(vm.timer);
vm.playByFlvJs();

@ -34,6 +34,10 @@ http {
proxy_pass http://localhost:8080/live/;
}
location ^~ /video/ {
proxy_pass http://localhost:8080/video/;
}
location ^~ /UserCenter/ {
proxy_pass http://localhost:8010/UserCenter/;
}

@ -1,55 +0,0 @@
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 0.0.0.0:80;
server_name localhost;
location / {
root ../../publish/src/linux-x64/publish/apps/www;
}
location ^~ /IoTCenter/hub {
proxy_pass http://localhost:5000/IoTCenter/hub/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location ^~ /UserCenter/ {
proxy_pass http://localhost:5000/UserCenter;
}
location ^~ /IoTCenter/ {
proxy_pass http://localhost:5000/IoTCenter;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Loading…
Cancel
Save