Skip to content

Commit 81271e6

Browse files
authored
feat(HikVision): add IsOpenSound parameter (#867)
* feat(HikVision): add StartRecord/StopRecord function * chore: bump version 10.0.7
1 parent 2a1cea6 commit 81271e6

4 files changed

Lines changed: 114 additions & 5 deletions

File tree

src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.0.6</Version>
4+
<Version>10.0.7</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public async Task<bool> SetVolume(int value)
317317
}
318318

319319
/// <summary>
320-
/// 抓图方法返回 Url
320+
/// 抓图方法并且下载方法
321321
/// </summary>
322322
/// <returns></returns>
323323
public async Task CapturePictureAndDownload()
@@ -331,7 +331,7 @@ public async Task CapturePictureAndDownload()
331331
private TaskCompletionSource<IJSStreamReference?>? _captureTaskCompletionSource = null;
332332

333333
/// <summary>
334-
/// 抓图方法返回 Url
334+
/// 抓图方法返回 <see cref="IJSStreamReference"/> 实例
335335
/// </summary>
336336
/// <returns></returns>
337337
public async Task<IJSStreamReference?> CapturePicture(CancellationToken token = default)
@@ -367,4 +367,32 @@ public async Task TriggerReceivePictureStream(IJSStreamReference stream)
367367
_captureTaskCompletionSource.SetResult(stream);
368368
}
369369
}
370+
371+
/// <summary>
372+
/// 开始录像方法
373+
/// </summary>
374+
/// <returns></returns>
375+
public async Task<bool> StartRecord()
376+
{
377+
var ret = false;
378+
if (IsLogin && IsRealPlaying)
379+
{
380+
ret = await InvokeAsync<bool>("startRecord", Id);
381+
}
382+
return ret;
383+
}
384+
385+
/// <summary>
386+
/// 结束录像方法
387+
/// </summary>
388+
/// <returns></returns>
389+
public async Task<bool> StopRecord()
390+
{
391+
var ret = false;
392+
if (IsLogin && IsRealPlaying)
393+
{
394+
ret = await InvokeAsync<bool>("stopRecord", Id);
395+
}
396+
return ret;
397+
}
370398
}

src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { init as initVision, login as loginVision, logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, capturePicture, capturePictureAndDownload, dispose as disposeVision } from '../hikvision.js';
1+
import { init as initVision, login as loginVision, logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, capturePicture, capturePictureAndDownload, startRecord, stopRecord, dispose as disposeVision } from '../hikvision.js';
22
import Data from '../../BootstrapBlazor/modules/data.js';
33

44
export async function init(id, invoke) {
@@ -29,7 +29,7 @@ export async function login(id, ip, port, userName, password, loginType) {
2929
return logined;
3030
}
3131

32-
export { logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, capturePicture, capturePictureAndDownload }
32+
export { logout, startRealPlay, stopRealPlay, openSound, closeSound, setVolume, capturePicture, capturePictureAndDownload, startRecord, stopRecord }
3333

3434
export function dispose(id) {
3535
disposeVision(id);

src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ export async function capturePicture(id) {
425425
}
426426
}
427427
catch (ex) {
428+
console.log(ex);
428429
return null;
429430
}
430431
}
@@ -462,8 +463,88 @@ export async function capturePictureAndDownload(id) {
462463
}
463464
}
464465
catch (ex) {
466+
console.log(ex);
467+
}
468+
}
469+
470+
export async function startRecord(id) {
471+
const vision = Data.get(id);
472+
const { realPlaying } = vision;
465473

474+
if (realPlaying !== true) {
475+
return false;
476+
}
477+
478+
let completed = false;
479+
let error = null;
480+
try {
481+
WebVideoCtrl.I_StartRecord(`record_${new Date().getTime()}`, {
482+
success: function () {
483+
completed = true;
484+
},
485+
error: function (oError) {
486+
completed = true;
487+
error = oError;
488+
}
489+
});
490+
}
491+
catch (ex) {
492+
console.log(ex);
466493
}
494+
495+
return new Promise((resolve, reject) => {
496+
const handler = setInterval(() => {
497+
if (completed) {
498+
clearTimeout(handler);
499+
if (error === null) {
500+
resolve(true);
501+
}
502+
else {
503+
reject(error);
504+
}
505+
}
506+
}, 16);
507+
});
508+
}
509+
510+
export async function stopRecord(id) {
511+
const vision = Data.get(id);
512+
const { realPlaying } = vision;
513+
514+
if (realPlaying !== true) {
515+
return false;
516+
}
517+
518+
let completed = false;
519+
let error = null;
520+
try {
521+
WebVideoCtrl.I_StopRecord({
522+
success: function () {
523+
completed = true;
524+
},
525+
error: function (oError) {
526+
completed = true;
527+
error = oError;
528+
}
529+
});
530+
}
531+
catch (ex) {
532+
533+
}
534+
535+
return new Promise((resolve, reject) => {
536+
const handler = setInterval(() => {
537+
if (completed) {
538+
clearTimeout(handler);
539+
if (error === null) {
540+
resolve(true);
541+
}
542+
else {
543+
reject(error);
544+
}
545+
}
546+
}, 16);
547+
});
467548
}
468549

469550
export function dispose(id) {

0 commit comments

Comments
 (0)