Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>10.0.6</Version>
<Version>10.0.7</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public async Task<bool> SetVolume(int value)
}

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

/// <summary>
/// 抓图方法返回 Url
/// 抓图方法返回 <see cref="IJSStreamReference"/> 实例
/// </summary>
/// <returns></returns>
public async Task<IJSStreamReference?> CapturePicture(CancellationToken token = default)
Expand Down Expand Up @@ -367,4 +367,32 @@ public async Task TriggerReceivePictureStream(IJSStreamReference stream)
_captureTaskCompletionSource.SetResult(stream);
}
}

/// <summary>
/// 开始录像方法
/// </summary>
/// <returns></returns>
public async Task<bool> StartRecord()
{
var ret = false;
if (IsLogin && IsRealPlaying)
{
ret = await InvokeAsync<bool>("startRecord", Id);
}
return ret;
}

/// <summary>
/// 结束录像方法
/// </summary>
/// <returns></returns>
public async Task<bool> StopRecord()
{
var ret = false;
if (IsLogin && IsRealPlaying)
{
ret = await InvokeAsync<bool>("stopRecord", Id);
}
return ret;
}
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
81 changes: 81 additions & 0 deletions src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ export async function capturePicture(id) {
}
}
catch (ex) {
console.log(ex);
return null;
}
}
Expand Down Expand Up @@ -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);
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using clearTimeout with a setInterval handler is incorrect. The handler is created by setInterval on line 496, so it should be cleared using clearInterval, not clearTimeout.

Copilot uses AI. Check for mistakes.
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) {

Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block is empty and doesn't log the exception like other catch blocks in this file. For consistency with the error handling pattern used in lines 428, 466, and 492, this should log the exception.

Suggested change
console.error('Error while stopping record:', ex);

Copilot uses AI. Check for mistakes.
}

return new Promise((resolve, reject) => {
const handler = setInterval(() => {
if (completed) {
clearTimeout(handler);
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using clearTimeout with a setInterval handler is incorrect. The handler is created by setInterval on line 536, so it should be cleared using clearInterval, not clearTimeout.

Suggested change
clearTimeout(handler);
clearInterval(handler);

Copilot uses AI. Check for mistakes.
if (error === null) {
resolve(true);
}
else {
reject(error);
}
}
}, 16);
});
}

export function dispose(id) {
Expand Down
Loading