Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Dec 24, 2025

Link issues

fixes #7403

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add sound control to the HikVision sample by exposing OpenSound and CloseSound actions with UI controls and toast feedback.

New Features:

  • Introduce OpenSound and CloseSound operations in the HikVision sample component to control audio during real-time preview.
  • Add UI buttons to toggle sound on and off for HikVision real-time playback with corresponding status handling.

Enhancements:

  • Display toast notifications indicating success or failure when opening or closing sound in the HikVision sample.

Copilot AI review requested due to automatic review settings December 24, 2025 03:16
@bb-auto bb-auto bot added the enhancement New feature or request label Dec 24, 2025
@bb-auto bb-auto bot added this to the v10.1.0 milestone Dec 24, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 24, 2025

Reviewer's Guide

Adds OpenSound/CloseSound support to the HikVision sample component, including UI buttons, state management, and toast notifications for operation results.

Sequence diagram for HikVisions OpenSound and CloseSound interactions

sequenceDiagram
    actor User
    participant HikVisions
    participant HikVisionWebPlugin
    participant ToastService

    rect rgb(230,230,255)
    User->>HikVisions: Click OpenSound button
    HikVisions->>HikVisionWebPlugin: OpenSound()
    HikVisionWebPlugin-->>HikVisions: result (bool)
    alt OpenSound success
        HikVisions->>HikVisions: _openSoundStatus = true
        HikVisions->>HikVisions: _closeSoundStatus = false
        HikVisions->>ToastService: Success(...)
    else OpenSound failure
        HikVisions->>ToastService: Error(...)
    end
    end

    rect rgb(230,255,230)
    User->>HikVisions: Click CloseSound button
    HikVisions->>HikVisionWebPlugin: CloseSound()
    HikVisionWebPlugin-->>HikVisions: result (bool)
    alt CloseSound success
        HikVisions->>HikVisions: _openSoundStatus = false
        HikVisions->>HikVisions: _closeSoundStatus = true
        HikVisions->>ToastService: Success(...)
    else CloseSound failure
        HikVisions->>ToastService: Error(...)
    end
    end
Loading

Updated class diagram for HikVisions component sound control

classDiagram
    class HikVisions {
        - SwalService SwalService
        - ToastService ToastService
        - HikVisionWebPlugin _hikVision
        - string _ip
        - int _port
        - string _user
        - string _password
        - bool _inited
        - int _streamType
        - bool _loginStatus
        - bool _logoutStatus
        - bool _startRealPlayStatus
        - bool _stopRealPlayStatus
        - bool _openSoundStatus
        - bool _closeSoundStatus
        - List~SelectedItem~ _analogChannels
        - int _channelId
        + OnLogout() Task
        + OnStartRealPlay() Task
        + OnStopRealPlay() Task
        + OnOpenSound() Task
        + OnCloseSound() Task
        + OnInitedAsync(initialized bool) Task
    }

    class HikVisionWebPlugin {
        + Logout() Task
        + StartRealPlay(streamType int, channelId int) Task
        + StopRealPlay() Task
        + OpenSound() Task~bool~
        + CloseSound() Task~bool~
    }

    class SwalService {
        <<service>>
    }

    class ToastService {
        <<service>>
        + Success(title string, content string) Task
        + Error(title string, content string) Task
    }

    class SelectedItem {
    }

    HikVisions --> HikVisionWebPlugin : uses
    HikVisions --> SwalService : injects
    HikVisions --> ToastService : injects
    HikVisions --> SelectedItem : contains
Loading

File-Level Changes

Change Details Files
Add sound control state and lifecycle handling to HikVisions component logic.
  • Inject ToastService for user notifications on sound operations
  • Introduce _openSoundStatus and _closeSoundStatus flags and initialize them along with existing status flags
  • Update OnLogout, OnStartRealPlay, and OnStopRealPlay handlers to reset or adjust sound state appropriately
  • Implement OnOpenSound and OnCloseSound methods that call the HikVision web plugin, update state flags based on results, and show success/error toasts
src/BootstrapBlazor.Server/Components/Samples/HikVisions.razor.cs
Expose sound control actions in the HikVisions sample UI.
  • Add "打开声音" (Open Sound) and "关闭声音" (Close Sound) buttons bound to new handlers
  • Bind button disabled state to _openSoundStatus and _closeSoundStatus to prevent invalid actions during current sound state
src/BootstrapBlazor.Server/Components/Samples/HikVisions.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#7403 Add OpenSound and CloseSound methods to the HikVision sample/component to allow controlling sound during real-time preview, including wiring them to the UI.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit 61871f2 into main Dec 24, 2025
5 of 6 checks passed
@ArgoZhang ArgoZhang deleted the feat-hik branch December 24, 2025 03:16
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider wrapping the _hikVision.OpenSound() and .CloseSound() calls in try/catch blocks so device or network exceptions can be surfaced to the user via a toast instead of failing silently or breaking the component.
  • The success/failure toast messages for opening/closing sound duplicate the same title and similar content; consider centralizing these strings (and possibly using localization) to avoid repetition and make future changes easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider wrapping the `_hikVision.OpenSound()` and `.CloseSound()` calls in try/catch blocks so device or network exceptions can be surfaced to the user via a toast instead of failing silently or breaking the component.
- The success/failure toast messages for opening/closing sound duplicate the same title and similar content; consider centralizing these strings (and possibly using localization) to avoid repetition and make future changes easier.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor.Server/Components/Samples/HikVisions.razor.cs:84-93` </location>
<code_context>
         await _hikVision.StopRealPlay();
     }

+    private async Task OnOpenSound()
+    {
+        var result = await _hikVision.OpenSound();
+        if (result)
+        {
+            _openSoundStatus = true;
+            _closeSoundStatus = false;
+            await ToastService.Success("消息通知", "打开声音成功");
+        }
+        else
+        {
+            await ToastService.Error("消息通知", "打开声音失败");
+        }
+    }
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Consider disabling the buttons during the async sound operations to avoid concurrent calls from rapid user clicks.

Because the `IsDisabled` flags only change after `_hikVision.OpenSound()` / `CloseSound()` complete, rapid clicks can fire overlapping handlers and leave the plugin in an inconsistent state if it isn’t re-entrant. You could instead disable the relevant button(s) before awaiting the call, then restore the flags based on the result to guard against rapid repeated interactions.

Suggested implementation:

```csharp
    private async Task OnOpenSound()
    {
        // Disable both buttons immediately to avoid overlapping operations
        _openSoundStatus = true;
        _closeSoundStatus = true;

        var result = await _hikVision.OpenSound();

        if (result)
        {
            // Sound opened: disable "open", enable "close"
            _openSoundStatus = true;
            _closeSoundStatus = false;
            await ToastService.Success("消息通知", "打开声音成功");
        }
        else
        {
            // Operation failed: restore to the pre-call state
            // (sound presumed closed: enable "open", disable "close")
            _openSoundStatus = false;
            _closeSoundStatus = true;
            await ToastService.Error("消息通知", "打开声音失败");
        }
    }

```

To fully implement the suggestion and avoid concurrent sound operations, you should apply the same pattern to the `OnCloseSound` handler (or any other sound-related handlers):

1. At the beginning of `OnCloseSound`, set `_openSoundStatus = true;` and `_closeSoundStatus = true;` to disable both buttons before awaiting `_hikVision.CloseSound()`.
2. After the await:
   - On success (sound closed), set `_openSoundStatus = false; _closeSoundStatus = true;` so only "open" is enabled.
   - On failure, restore the sound-open state: `_openSoundStatus = true; _closeSoundStatus = false;`.

This ensures that while any sound operation is in progress, the user cannot trigger concurrent calls via rapid clicks.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (30c29bb) to head (6d7ac1d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7404   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          748       748           
  Lines        32793     32793           
  Branches      4551      4551           
=========================================
  Hits         32793     32793           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds sound control functionality to the HikVision web camera component by implementing OpenSound and CloseSound methods. The changes enable users to control audio playback during video streaming.

  • Adds OpenSound and CloseSound methods with proper state management and user feedback via toast notifications
  • Introduces sound control buttons in the UI that are enabled/disabled based on the current playback and sound state
  • Updates the HikVision package dependency from version 10.0.4 to 10.0.5 to support the new sound control features

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/BootstrapBlazor.Server/Components/Samples/HikVisions.razor.cs Adds ToastService injection, sound button state flags, and implements OnOpenSound/OnCloseSound methods with proper state management in existing lifecycle methods
src/BootstrapBlazor.Server/Components/Samples/HikVisions.razor Adds two new buttons for opening and closing sound with appropriate disable logic tied to the sound state flags
src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj Updates BootstrapBlazor.HikVision package reference from version 10.0.4 to 10.0.5

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(HikVision): add OpenSound/CloseSound method

2 participants