diff --git a/projects/Infrastructure/Infrastructure.csproj b/projects/Infrastructure/Infrastructure.csproj index 53f1b312..65c71f95 100644 --- a/projects/Infrastructure/Infrastructure.csproj +++ b/projects/Infrastructure/Infrastructure.csproj @@ -15,22 +15,22 @@ - - + + - - + + - - + + - + diff --git a/projects/IoT.Shared/IoT.Shared.csproj b/projects/IoT.Shared/IoT.Shared.csproj index a3025d33..81229b4d 100644 --- a/projects/IoT.Shared/IoT.Shared.csproj +++ b/projects/IoT.Shared/IoT.Shared.csproj @@ -12,10 +12,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/projects/IoTCenter/Views/Home/Device.cshtml b/projects/IoTCenter/Views/Home/Device.cshtml index 770a9cbb..93faf648 100644 --- a/projects/IoTCenter/Views/Home/Device.cshtml +++ b/projects/IoTCenter/Views/Home/Device.cshtml @@ -185,8 +185,7 @@ - - + @@ -196,39 +195,90 @@ - - - - - {{api.Name}} - - - - - - - {{parameter.Description}}: - + + + + {{api.Name}} + + + + + + + {{parameter.Description}}: + + + + + - - - - - - + + + + + + 确定 - - - 确定 - - - + + + + + + + + + + + + {{model.DisplayName}} + + + 开始推流 + 停止推流 + + + + + + + + + + + + + 云台操作 + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/projects/IoTCenter/Views/Home/Node.cshtml b/projects/IoTCenter/Views/Home/Node.cshtml index 757be6cd..d5581c87 100644 --- a/projects/IoTCenter/Views/Home/Node.cshtml +++ b/projects/IoTCenter/Views/Home/Node.cshtml @@ -270,7 +270,7 @@ - {{c.DisplayName||c.Name}} + {{c.DisplayName}} diff --git a/projects/IoTClient/Assets/StreamingAssets/IoT.Resources.csproj b/projects/IoTClient/Assets/StreamingAssets/IoT.Resources.csproj index 78147af7..1877acd8 100644 --- a/projects/IoTClient/Assets/StreamingAssets/IoT.Resources.csproj +++ b/projects/IoTClient/Assets/StreamingAssets/IoT.Resources.csproj @@ -7,7 +7,7 @@ true - + diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/device.js b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/device.js index 805e0744..2f2804ee 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/device.js +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/device.js @@ -69,6 +69,9 @@ function onMessage(method, json, to, from) { if ($('canvas#' + device.Number).length) { UpdateChart(device.Number); } + if ($('#camera').val() === device.Number && item.Name === '推流') { + UpdateCamera(); + } } } } diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/node.js b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/node.js index 0d14cd19..00c31628 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/node.js +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/node.js @@ -106,7 +106,7 @@ methods = { GetChartDevices() { return Enumerable.from(this.model.Devices) .where(function (o) { return o.Name === '温湿度传感器' || o.Name === 'PM2.5感应器' || o.Name === '光强检测器' || o.Name === '智能插座'; }) - .orderBy('o=>o.ProductId') + .orderBy(function (o) { return o.Name;}) .toArray(); } }; @@ -130,6 +130,10 @@ function onMessage(method, json, to, from) { if ($('canvas#' + device.Number).length) { UpdateChart(device.Number); } + if ($('#camera').val() === device.Number && item.Name === '推流') { + console.log('start update camera'); + UpdateCamera(); + } } } } diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/page.js b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/page.js index 8d3827e9..d423046c 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/page.js +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/page.js @@ -515,42 +515,45 @@ function playFlv(videoElement) { $('#ptz').hide(); } closePlayer(livePlayer); - try { - livePlayer = flvjs.createPlayer({ - type: 'flv', - url: url, - isLive: true, - cors: true - }, { - enableWorker: true, - enableStashBuffer: false, - stashInitialSize: 1, - fixAudioTimestampGap: false - }); - livePlayer.attachMediaElement(videoElement); - livePlayer.load(); - livePlayer.volume = volume; - livePlayer.muted = muted; - timer = setInterval(function () { - console.log('.'); - if (livePlayer.statisticsInfo.speed == 0) { - console.log('reload1'); - clearInterval(timer); - playFlv(videoElement); - } - else if (decodedFrames && livePlayer.statisticsInfo.decodedFrames <= decodedFrames) { - console.log('reload2'); - clearInterval(timer); - playFlv(videoElement); - } - else if (livePlayer.buffered.end(0) - livePlayer.currentTime > 1) { - console.log('reset currentTime'); - livePlayer.currentTime = livePlayer.buffered.end(0) - 0.001; - } - decodedFrames = livePlayer.statisticsInfo.decodedFrames; - }, 10 * 1000); - } catch (e) { - console.log(e); + var push = Enumerable.from(device.Data).where(o => o.Name === '推流').firstOrDefault(); + if (push && push.Value === '是') { + try { + livePlayer = flvjs.createPlayer({ + type: 'flv', + url: url, + isLive: true, + cors: true + }, { + enableWorker: true, + enableStashBuffer: false, + stashInitialSize: 1, + fixAudioTimestampGap: false + }); + livePlayer.attachMediaElement(videoElement); + livePlayer.load(); + livePlayer.volume = volume; + livePlayer.muted = muted; + timer = setInterval(function () { + console.log('.'); + if (livePlayer.statisticsInfo.speed == 0) { + console.log('reload1'); + clearInterval(timer); + playFlv(videoElement); + } + else if (decodedFrames && livePlayer.statisticsInfo.decodedFrames <= decodedFrames) { + console.log('reload2'); + clearInterval(timer); + playFlv(videoElement); + } + else if (livePlayer.buffered.end(0) - livePlayer.currentTime > 1) { + console.log('reset currentTime'); + livePlayer.currentTime = livePlayer.buffered.end(0) - 0.001; + } + decodedFrames = livePlayer.statisticsInfo.decodedFrames; + }, 10 * 1000); + } catch (e) { + console.log(e); + } } } } diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/product.js b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/product.js index 93c461a5..d8092966 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/product.js +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/js/product.js @@ -17,7 +17,7 @@ methods = { || this.model.Name.indexOf('插座') >= 0; }, GetDevices() { - return Enumerable.from(this.model.Devices).orderBy('o=>o.DisplayOrder').orderBy('o=>o.Name').toArray(); + return Enumerable.from(this.model.Devices).orderBy(function (o) { return o.DisplayOrder; }).orderBy(function (o) {return o.Name }).toArray(); }, GetDataValue(number, name) { var device = Enumerable.from(this.model.Devices) diff --git a/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs b/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs index f6b0bd61..dc796c07 100644 --- a/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs +++ b/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs @@ -66,7 +66,7 @@ namespace IoTNode.DeviceServices.Onvif { try { - this.Remove(item); + this.StopPushToServer(item); } catch (Exception ex) { @@ -139,7 +139,8 @@ namespace IoTNode.DeviceServices.Onvif this.UpdateDevice(deviceRepo, device); var fileName = $"ffmpeg-{Helper.Instance.GetRunTime()}{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "")}"; var file = Path.Combine(this._env.WebRootPath, fileName); - this.UpdateData(deviceRepo, device, device.CreateData("Push", "是", DeviceDataType.String, "推流")); + var pushValue = device.Data.FirstOrDefault(o => o.Name == "推流")?.Value ?? "是"; + this.UpdateData(deviceRepo, device, device.CreateData("Push", pushValue, DeviceDataType.String, "推流")); this.UpdateData(deviceRepo, device, device.CreateData("Record", "否", DeviceDataType.String, "录像")); this.UpdateData(deviceRepo, device, device.CreateData("ffmpeg.file", file, DeviceDataType.String, "ffmpeg路径", hidden: true)); this.UpdateData(deviceRepo, device, device.CreateData("ffmpeg.args", this._cfg["ffmpeg.args"], DeviceDataType.String, "ffmpeg.args", hidden: true)); @@ -253,7 +254,7 @@ namespace IoTNode.DeviceServices.Onvif } if (remove) { - this.Remove(key); + this.StopPushToServer(key); } } foreach (var camera in cameras) @@ -264,7 +265,7 @@ namespace IoTNode.DeviceServices.Onvif { if (camera.Data.Any(o => o.Key == "NeedAuth" && o.Value == "否") || camera.Data.Any(o => o.Key == "HasAuth" && o.Value == "是")) { - this.Publish(camera); + this.StartPushToServer(camera); } } } @@ -276,7 +277,7 @@ namespace IoTNode.DeviceServices.Onvif } } - private void Publish(Device camera) + private void StartPushToServer(Device camera) { try { @@ -351,7 +352,7 @@ namespace IoTNode.DeviceServices.Onvif } } - public void Remove(string key) + public void StopPushToServer(string key) { (Device camera, Process local, Process remote) item; if (this._list.TryRemove(key, out item)) @@ -573,8 +574,16 @@ namespace IoTNode.DeviceServices.Onvif { var repo = scope.ServiceProvider.GetService>(); var device = repo.Table().Include(o => o.Data).FirstOrDefault(o => o.Number == number); - var data = device.Data.FirstOrDefault(o => o.Key == "Push"); - data.Value = "是"; + if (device != null) + { + var data = device.Data.FirstOrDefault(o => o.Key == "Push"); + if (data != null) + { + data.Value = "是"; + this.UpdateData(repo, device, data); + this.StartPushToServer(device); + } + } } } @@ -584,8 +593,16 @@ namespace IoTNode.DeviceServices.Onvif { var repo = scope.ServiceProvider.GetService>(); var device = repo.Table().Include(o => o.Data).FirstOrDefault(o => o.Number == number); - var data = device.Data.FirstOrDefault(o => o.Key == "Push"); - data.Value = "否"; + if (device != null) + { + var data = device.Data.FirstOrDefault(o => o.Key == "Push"); + if (data != null) + { + data.Value = "否"; + this.UpdateData(repo, device, data); + this.StopPushToServer(device.Number); + } + } } }