diff --git a/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj b/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj index d1ed5412..6f193e44 100644 --- a/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj +++ b/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj @@ -1,7 +1,7 @@ - 10.0.6 + 10.0.7 diff --git a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs index 88712dae..3e376715 100644 --- a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs +++ b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs @@ -317,7 +317,7 @@ public async Task SetVolume(int value) } /// - /// 抓图方法返回 Url + /// 抓图方法并且下载方法 /// /// public async Task CapturePictureAndDownload() @@ -331,7 +331,7 @@ public async Task CapturePictureAndDownload() private TaskCompletionSource? _captureTaskCompletionSource = null; /// - /// 抓图方法返回 Url + /// 抓图方法返回 实例 /// /// public async Task CapturePicture(CancellationToken token = default) @@ -367,4 +367,32 @@ public async Task TriggerReceivePictureStream(IJSStreamReference stream) _captureTaskCompletionSource.SetResult(stream); } } + + /// + /// 开始录像方法 + /// + /// + public async Task StartRecord() + { + var ret = false; + if (IsLogin && IsRealPlaying) + { + ret = await InvokeAsync("startRecord", Id); + } + return ret; + } + + /// + /// 结束录像方法 + /// + /// + public async Task StopRecord() + { + var ret = false; + if (IsLogin && IsRealPlaying) + { + ret = await InvokeAsync("stopRecord", Id); + } + return ret; + } } diff --git a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js index 07009e82..d5fb6449 100644 --- a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js +++ b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js @@ -1,4 +1,4 @@ -import { init as initVision, login as loginVision, logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, capturePicture, capturePictureAndDownload, dispose as disposeVision } from '../hikvision.js'; +import { init as initVision, login as loginVision, logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, capturePicture, capturePictureAndDownload, startRecord, stopRecord, dispose as disposeVision } from '../hikvision.js'; import Data from '../../BootstrapBlazor/modules/data.js'; export async function init(id, invoke) { @@ -29,7 +29,7 @@ export async function login(id, ip, port, userName, password, loginType) { return logined; } -export { logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, capturePicture, capturePictureAndDownload } +export { logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, capturePicture, capturePictureAndDownload, startRecord, stopRecord } export function dispose(id) { disposeVision(id); diff --git a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js index 7e8f8be2..2f803dad 100644 --- a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js +++ b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js @@ -425,6 +425,7 @@ export async function capturePicture(id) { } } catch (ex) { + console.log(ex); return null; } } @@ -462,8 +463,88 @@ export async function capturePictureAndDownload(id) { } } catch (ex) { + console.log(ex); + } +} + +export async function startRecord(id) { + const vision = Data.get(id); + const { realPlaying } = vision; + if (realPlaying !== true) { + return false; + } + + let completed = false; + let error = null; + try { + WebVideoCtrl.I_StartRecord(`record_${new Date().getTime()}`, { + success: function () { + completed = true; + }, + error: function (oError) { + completed = true; + error = oError; + } + }); + } + catch (ex) { + console.log(ex); } + + return new Promise((resolve, reject) => { + const handler = setInterval(() => { + if (completed) { + clearTimeout(handler); + if (error === null) { + resolve(true); + } + else { + reject(error); + } + } + }, 16); + }); +} + +export async function stopRecord(id) { + const vision = Data.get(id); + const { realPlaying } = vision; + + if (realPlaying !== true) { + return false; + } + + let completed = false; + let error = null; + try { + WebVideoCtrl.I_StopRecord({ + success: function () { + completed = true; + }, + error: function (oError) { + completed = true; + error = oError; + } + }); + } + catch (ex) { + + } + + return new Promise((resolve, reject) => { + const handler = setInterval(() => { + if (completed) { + clearTimeout(handler); + if (error === null) { + resolve(true); + } + else { + reject(error); + } + } + }, 16); + }); } export function dispose(id) {