diff --git a/projects/IoT.Shared/Application/Models/ApiResponse.cs b/projects/IoT.Shared/Application/Models/ApiResponse.cs index 9879717d..e9401045 100644 --- a/projects/IoT.Shared/Application/Models/ApiResponse.cs +++ b/projects/IoT.Shared/Application/Models/ApiResponse.cs @@ -7,10 +7,10 @@ namespace Application.Models public int type { get; set; } public int code { get; set; } public string message { get; set; } - public string data { get; set; } - public int format { get; set; } + public object data { get; set; } + public string format { get; set; } - public static ApiResponse Success(string data, int format = 0) + public static ApiResponse Success(object data, string format = "") { return new ApiResponse { type = 0, code = 0, data = data, format = format }; } diff --git a/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs b/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs index 4b2f779e..9f2d842b 100644 --- a/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs +++ b/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs @@ -346,7 +346,7 @@ namespace IoT.Shared.Services var url = $"http://localhost:{port}{message.FromJson()}"; var httpClient = scope.ServiceProvider.GetService().CreateClient(); var result = httpClient.GetStringAsync(url).Result; - this.ClientToServer(Methods.ExecApiResponse, result, from); + this.ClientToServer(Methods.ExecApiResponse, result, from, to); } else if (method == Methods.ExecSceneRequest) { diff --git a/projects/IoTCenter/wwwroot/js/page.js b/projects/IoTCenter/wwwroot/js/page.js index c8d10984..23846e8e 100644 --- a/projects/IoTCenter/wwwroot/js/page.js +++ b/projects/IoTCenter/wwwroot/js/page.js @@ -35,7 +35,7 @@ var f7params = isApp? { routes: [], name: 'My App', id: 'com.myapp.test', - theme: 'ios', + theme: 'ios' }:null; // //log @@ -112,7 +112,7 @@ function loadData() { function updateItem(list, item) { var update = false; for (var i = 0; i < list.length; i++) { - if (list[i].id == item.id) { + if (list[i].id === item.id) { update = true; break; } @@ -126,7 +126,7 @@ function updateItem(list, item) { } function deleteItem(list, item) { for (var i = 0; i < list.length; i++) { - if (list[i].id == item.id) { + if (list[i].id === item.id) { list.splice(i, 1); break; } @@ -253,9 +253,9 @@ function getCode1(code) { } // function hsvToRgb(h, s, v) { - if (h == "") h = 0; - if (s == "") s = 0; - if (v == "") v = 0; + if (h === "") h = 0; + if (s === "") s = 0; + if (v === "") v = 0; h = parseFloat(h); s = parseFloat(s); v = parseFloat(v); @@ -269,7 +269,7 @@ function hsvToRgb(h, s, v) { v /= 100.0; C = v * s; hh = h / 60.0; - X = C * (1.0 - Math.abs((hh % 2) - 1.0)); + X = C * (1.0 - Math.abs(hh % 2 - 1.0)); r = g = b = 0; if (hh >= 0 && hh < 1) { r = C; @@ -315,7 +315,7 @@ function hsvToRgb(h, s, v) { } // function ajax(url, data, type) { - url = baseUrl + url + url = baseUrl + url; console.log(url); type = type || 'get'; $('.overlay').show(); @@ -349,68 +349,6 @@ function AjaxCallBack(response) { } } // -function hsvToRgb(h, s, v) { - if (h == "") h = 0; - if (s == "") s = 0; - if (v == "") v = 0; - h = parseFloat(h); - s = parseFloat(s); - v = parseFloat(v); - if (h < 0) h = 0; - if (s < 0) s = 0; - if (v < 0) v = 0; - if (h >= 360) h = 359; - if (s > 100) s = 100; - if (v > 100) v = 100; - s /= 100.0; - v /= 100.0; - C = v * s; - hh = h / 60.0; - X = C * (1.0 - Math.abs((hh % 2) - 1.0)); - r = g = b = 0; - if (hh >= 0 && hh < 1) { - r = C; - g = X; - } - else if (hh >= 1 && hh < 2) { - r = X; - g = C; - } - else if (hh >= 2 && hh < 3) { - g = C; - b = X; - } - else if (hh >= 3 && hh < 4) { - g = X; - b = C; - } - else if (hh >= 4 && hh < 5) { - r = X; - b = C; - } - else { - r = C; - b = X; - } - m = v - C; - r += m; - g += m; - b += m; - r *= 255.0; - g *= 255.0; - b *= 255.0; - r = Math.round(r); - g = Math.round(g); - b = Math.round(b); - hex = r * 65536 + g * 256 + b; - hex = hex.toString(16, 6); - len = hex.length; - if (len < 6) - for (i = 0; i < 6 - len; i++) - hex = '0' + hex; - return '#' + hex; -} -// function changeTime(t) { time = t; UpdateChart(); @@ -430,7 +368,7 @@ function UpdateChart(deviceNumber) { }) .catch(function (error) { console.log(error); - toastr.error(error) + toastr.error(error); }); } }); @@ -441,7 +379,7 @@ function UpdateChartInternal(canvas, title, data) { if (instance.chart.canvas.id === canvas.id) { chart = instance; } - }) + }); if (chart) { chart.data = data; chart.update(); @@ -451,7 +389,7 @@ function UpdateChartInternal(canvas, title, data) { var options = { responsive: true, legend: { - position: 'bottom', + position: 'bottom' }, title: { display: false, @@ -461,7 +399,7 @@ function UpdateChartInternal(canvas, title, data) { duration: 0 } }; - var chart = new Chart(ctx, { + chart = new Chart(ctx, { type: 'line', data: data, options: options @@ -546,7 +484,7 @@ function playFlv(videoElement) { livePlayer.muted = muted; timer = setInterval(function () { console.log('.'); - if (livePlayer.statisticsInfo.speed == 0) { + if (livePlayer.statisticsInfo.speed === 0) { console.log('reload1'); clearInterval(timer); playFlv(videoElement); @@ -556,7 +494,7 @@ function playFlv(videoElement) { clearInterval(timer); playFlv(videoElement); } - else if (livePlayer.buffered.end(0) - livePlayer.currentTime > 1) { + else if (livePlayer.buffered.length>0&&livePlayer.buffered.end(0) - livePlayer.currentTime > 1) { console.log('reset currentTime'); livePlayer.currentTime = livePlayer.buffered.end(0) - 0.001; } @@ -573,7 +511,7 @@ function closePlayer(livePlayer) { if (timer) { clearInterval(timer); } - if (livePlayer != null) { + if (livePlayer !== null) { try { livePlayer.pause(); } catch (e) { @@ -590,7 +528,7 @@ function closePlayer(livePlayer) { } } $(document).on('change', '#camera', function (e) { - UpdateCamera() + UpdateCamera(); }); $(document).on('mousedown touchstart', 'img.camera.ajax', function (e) { var number = $('#camera').val(); diff --git a/projects/IoTNode/Controllers/BaseDeviceController.cs b/projects/IoTNode/Controllers/BaseDeviceController.cs index 9046e77d..290c9eff 100644 --- a/projects/IoTNode/Controllers/BaseDeviceController.cs +++ b/projects/IoTNode/Controllers/BaseDeviceController.cs @@ -35,6 +35,25 @@ namespace IoTNode.Controllers } } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")] + public ApiResponse Action(Func action) + { + if (action is null) + { + throw new ArgumentNullException(nameof(action)); + } + + try + { + return ApiResponse.Success(action()); + } + catch (Exception ex) + { + ex.PrintStack(); + return ApiResponse.Error(ex.GetMessage()); + } + } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")] public ApiResponse AsyncAction(Action action) { diff --git a/projects/IoTNode/DeviceServices/Onvif/Controllers/OnvifController.cs b/projects/IoTNode/DeviceServices/Onvif/Controllers/OnvifController.cs index 0faa4d6b..0b049173 100644 --- a/projects/IoTNode/DeviceServices/Onvif/Controllers/OnvifController.cs +++ b/projects/IoTNode/DeviceServices/Onvif/Controllers/OnvifController.cs @@ -19,9 +19,15 @@ namespace IoTNode.Controllers [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("截屏")] public ApiResponse ScreenShot([SwaggerParameter("设备编号")]string number) { - return this.AsyncAction(() => + return this.Action(() => { - this._deviceService.ScreenShot(number); + var data = this._deviceService.ScreenShot(number); + return new ApiResponse + { + code = 0, + format = "image/jpeg", + data = data + }; }); } diff --git a/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs b/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs index 85ca50b2..e1b998f5 100644 --- a/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs +++ b/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs @@ -532,16 +532,24 @@ namespace IoTNode.DeviceServices.Onvif { var camera = this.GetCamera(id); var url = camera.GetDataValue("SnapshotUri"); - if (string.IsNullOrEmpty(url)) - { - return new byte[] { }; - } - var hc = this._httpClientFactory.CreateClient(); - if (camera.GetDataValue("NeedAuth") == "否") + if (!string.IsNullOrEmpty(url)) { - return hc.GetByteArrayAsync(url).Result; + var hc = this._httpClientFactory.CreateClient(); + + if (camera.GetDataValue("NeedAuth") == "否") + { + return hc.GetByteArrayAsync(url).Result; + } + else + { + if (camera.GetDataValue("HasAuth") == "是") + { + return hc.GetByteDigest(new Uri(url), camera.UserName, camera.Password); + } + } } - return hc.GetByteDigest(new Uri(url), camera.UserName, camera.Password); + + return new byte[] { }; } public void SetPush(string number, bool state) diff --git a/projects/WebApp/wwwroot/pages/iot/device.js b/projects/WebApp/wwwroot/pages/iot/device.js index a7541daf..f4b3d0ba 100644 --- a/projects/WebApp/wwwroot/pages/iot/device.js +++ b/projects/WebApp/wwwroot/pages/iot/device.js @@ -11,7 +11,7 @@ mounted: function () { axios.post(this.url) .then(function (response) { - store.commit('setDevice',response.data); + store.commit('setDevice', response.data); }) .catch(function (error) { }) @@ -20,7 +20,7 @@ }); }, destroyed: function () { - store.commit('setDevice',null); + store.commit('setDevice', null); }, methods: { }, @@ -29,7 +29,7 @@ return store.state.device; } } - }) + }); }); }); } \ No newline at end of file diff --git a/projects/WebApp/wwwroot/pages/iot/node.html b/projects/WebApp/wwwroot/pages/iot/node.html index 29a0575e..bae39087 100644 --- a/projects/WebApp/wwwroot/pages/iot/node.html +++ b/projects/WebApp/wwwroot/pages/iot/node.html @@ -171,9 +171,9 @@
- - - + + +
@@ -195,12 +195,12 @@
- - - - - - + + + + + +
@@ -222,8 +222,8 @@
- - + +