-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat(HikVision): add CapturePicture method #869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -115,6 +115,16 @@ public partial class HikVisionWebPlugin | |||||||||||||
| /// </summary> | ||||||||||||||
| public bool IsRealPlaying { get; private set; } | ||||||||||||||
|
|
||||||||||||||
| /// <summary> | ||||||||||||||
| /// 获得 是否已经打开声音 | ||||||||||||||
| /// </summary> | ||||||||||||||
| public bool IsOpenSound { get; private set; } | ||||||||||||||
|
|
||||||||||||||
| /// <summary> | ||||||||||||||
| /// 获得 是否开始录像 | ||||||||||||||
| /// </summary> | ||||||||||||||
| public bool IsStartRecord { get; private set; } | ||||||||||||||
|
|
||||||||||||||
| /// <summary> | ||||||||||||||
| /// <inheritdoc/> | ||||||||||||||
| /// </summary> | ||||||||||||||
|
|
@@ -164,6 +174,7 @@ public async Task Logout() | |||||||||||||
| { | ||||||||||||||
| await InvokeVoidAsync("logout", Id); | ||||||||||||||
| } | ||||||||||||||
| IsStartRecord = false; | ||||||||||||||
| IsRealPlaying = false; | ||||||||||||||
| IsLogin = false; | ||||||||||||||
| await TriggerLogout(); | ||||||||||||||
|
|
@@ -221,6 +232,7 @@ public async Task StopRealPlay() | |||||||||||||
| { | ||||||||||||||
| await InvokeVoidAsync("stopRealPlay", Id); | ||||||||||||||
| IsRealPlaying = false; | ||||||||||||||
| IsStartRecord = false; | ||||||||||||||
|
||||||||||||||
| IsStartRecord = false; | |
| IsStartRecord = false; | |
| IsOpenSound = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Local sound state is set to true even when the JS call fails.
ret correctly reflects whether openSound succeeded (code == 100), but IsOpenSound is always set to true, so it can become out of sync with the actual sound state when code != 100. Set IsOpenSound = ret (or only set it when code == 100) so it stays consistent with the real state.
Copilot
AI
Dec 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IsOpenSound property is set to true regardless of whether the operation actually succeeded. It should only be set to true when ret is true (i.e., when code == 100).
| IsOpenSound = true; | |
| IsOpenSound = ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Local sound state is set to false even if closeSound fails.
Because IsOpenSound is set to false unconditionally, callers may believe sound is closed even when closeSound fails. Align the flag with the actual result from code == 100 (e.g., set IsOpenSound = ret; or only update it when the call succeeds) so state remains accurate.
Copilot
AI
Dec 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IsOpenSound property is set to false regardless of whether the operation actually succeeded. It should only be set to false when ret is true (i.e., when code == 100).
Copilot
AI
Dec 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XML documentation comment is outdated. The method no longer returns an IJSStreamReference instance but now returns a boolean value indicating success or failure.
| /// 抓图方法返回 <see cref="IJSStreamReference"/> 实例 | |
| /// </summary> | |
| /// <returns></returns> | |
| /// 抓图方法,返回操作是否成功 | |
| /// </summary> | |
| /// <returns>表示抓图操作是否成功的布尔值。</returns> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -409,24 +409,24 @@ export async function setVolume(id, value) { | |||||
| return code; | ||||||
| } | ||||||
|
|
||||||
| export async function capturePicture(id) { | ||||||
| export function capturePicture(id, szFileName) { | ||||||
| const vision = Data.get(id); | ||||||
| const { realPlaying } = vision; | ||||||
|
|
||||||
| if (realPlaying !== true) { | ||||||
| return ""; | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| try { | ||||||
| const base64 = await WebVideoCtrl.I_CapturePicData(); | ||||||
| if (base64) { | ||||||
| const bytes = base64ToArray(base64); | ||||||
| return DotNet.createJSStreamReference(bytes.buffer); | ||||||
| if (!szFileName) { | ||||||
|
Comment on lines
+412
to
+421
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: The capture filename here is extension-less, unlike the This uses a default of |
||||||
| szFileName = `capture_${new Date().getTime()}`; | ||||||
| } | ||||||
| WebVideoCtrl.I_CapturePic(szFileName); | ||||||
| return true; | ||||||
| } | ||||||
| catch (ex) { | ||||||
| console.log(ex); | ||||||
| return null; | ||||||
| return false; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -443,28 +443,34 @@ const base64ToArray = base64String => { | |||||
| return bytes; | ||||||
| } | ||||||
|
|
||||||
| export async function capturePictureAndDownload(id) { | ||||||
| export async function capturePictureAndDownload(id, szFileName) { | ||||||
| const vision = Data.get(id); | ||||||
| const { realPlaying } = vision; | ||||||
|
|
||||||
| if (realPlaying !== true) { | ||||||
| return; | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| let ret = false; | ||||||
| try { | ||||||
| const base64 = await WebVideoCtrl.I_CapturePicData(); | ||||||
| if (base64) { | ||||||
| if (!szFileName) { | ||||||
| szFileName = `capture_${new Date().getTime()}.jpg` | ||||||
|
||||||
| szFileName = `capture_${new Date().getTime()}.jpg` | |
| szFileName = `capture_${new Date().getTime()}.jpg`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IsOpenSound state is not reset when logout occurs. When a user logs out, the sound state should also be reset to false, similar to how IsStartRecord and IsRealPlaying are reset.