WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Dec 5, 2025

Link issues

fixes #788

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 channel list retrieval and callback support to the HikVision web plugin while standardizing login types and callback naming.

New Features:

  • Expose an OnGetChannelsAsync callback on the HikVision web plugin to receive channel information after login.
  • Introduce HikVisionChannel and related channel info models to represent analog, digital, and zero channels from HikVision devices.

Enhancements:

  • Rename LoginType to HikVisionLoginType across the HikVision components and services for clearer scoping.
  • Standardize login state properties and login/logout callback names on the HikVision web plugin for clearer semantics.
  • Refine the HikVision JavaScript integration to cache initialization state, fetch channel lists on login, and simplify real-play setup.

Copilot AI review requested due to automatic review settings December 5, 2025 04:40
@bb-auto bb-auto bot added the enhancement New feature or request label Dec 5, 2025
@bb-auto bb-auto bot added this to the v9.2.0 milestone Dec 5, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 5, 2025

Reviewer's Guide

Extends the HikVision Blazor component to expose channel list information on login, refactors login-related naming and enums for clarity, and wires up JavaScript-side channel discovery and callbacks into new C# models.

Sequence diagram for HikVision login and channel list callback

sequenceDiagram
    actor User
    participant HikVisionWebPlugin as HikVisionWebPlugin_CSharp
    participant JSRuntime
    participant HikVisionWebPluginJs as HikVisionWebPlugin_js
    participant HikvisionJs as hikvision_js
    participant WebVideoCtrl

    User->>HikVisionWebPlugin: Login(ip, port, userName, password, loginType)
    HikVisionWebPlugin->>JSRuntime: InvokeAsync login(Id, ip, port, userName, password, loginType)
    JSRuntime->>HikVisionWebPluginJs: login(id, ip, port, userName, password, loginType)
    HikVisionWebPluginJs->>HikvisionJs: login(id, ip, port, userName, password, loginType)

    HikvisionJs->>WebVideoCtrl: I_Login(ip, loginType, port, userName, password)
    WebVideoCtrl-->>HikvisionJs: success

    HikvisionJs->>HikvisionJs: getChannelList(vision)
    HikvisionJs->>WebVideoCtrl: I_GetAnalogChannelInfo(szDeviceIdentify)
    WebVideoCtrl-->>HikvisionJs: analog channel XML
    HikvisionJs->>HikvisionJs: parse to analogChannels

    HikvisionJs->>WebVideoCtrl: I_GetDigitalChannelInfo(szDeviceIdentify)
    WebVideoCtrl-->>HikvisionJs: digital channel XML
    HikvisionJs->>HikvisionJs: parse to digitalChannels

    HikvisionJs->>WebVideoCtrl: I_GetZeroChannelInfo(szDeviceIdentify)
    WebVideoCtrl-->>HikvisionJs: zero channel XML
    HikvisionJs->>HikvisionJs: parse to zeroChannels

    HikvisionJs->>HikvisionJs: vision.logined = true
    HikvisionJs-->>HikVisionWebPluginJs: logined flag

    HikVisionWebPluginJs->>HikVisionWebPluginJs: read analogChannels, digitalChannels, zeroChannels
    HikVisionWebPluginJs->>HikVisionWebPlugin: invokeMethodAsync TriggerGetChannelList(HikVisionChannel)

    HikVisionWebPlugin->>HikVisionWebPlugin: TriggerGetChannelList(channel)
    HikVisionWebPlugin->>HikVisionWebPlugin: OnGetChannelsAsync(channel)
    HikVisionWebPlugin-->>User: Login result with channels available
Loading

Updated class diagram for HikVision channel models and component

classDiagram
    class HikVisionLoginType {
        <<enumeration>>
        Http
        Https
    }

    class HikVisionAnalogChannelInfo {
        +int Id
        +int InputPort
        +string Name
        +string VideoFormat
    }

    class HikVisionDigitalChannelInfo {
        +int Id
        +int InputPort
        +string Name
        +string VideoFormat
    }

    class HikVisionZeroChannelInfo {
        +int Id
        +int InputPort
        +bool Enabled
    }

    class HikVisionChannel {
        +List~HikVisionAnalogChannelInfo~ AnalogChannels
        +List~HikVisionDigitalChannelInfo~ DigitalChannels
        +List~HikVisionZeroChannelInfo~ ZeroChannels
    }

    class IHikVision {
        <<interface>>
        +Task~bool~ Login(string ip, int port, string userName, string password, HikVisionLoginType loginType)
        +Task Logout()
    }

    class DefaultHicVision {
        -IJSRuntime jsRuntime
        -bool _initialized
        -bool _logined
        +Task~bool~ Login(string ip, int port, string userName, string password, HikVisionLoginType loginType)
        +Task Logout()
    }

    class HikVisionWebPlugin {
        +string Id
        +string Ip
        +int Port
        +string UserName
        +string Password
        +HikVisionLoginType LoginType
        +string Width
        +string Height
        +Func~bool,Task~ OnInitedAsync
        +Func~Task~ OnLoginAsync
        +Func~HikVisionChannel,Task~ OnGetChannelsAsync
        +Func~Task~ OnLogoutAsync
        +Func~Task~ OnStartRealPlayingAsync
        +Func~Task~ OnStopRealPlayingAsync
        +bool Inited
        +bool IsLogin
        +bool IsRealPlaying
        +Task~bool~ Login(string ip, int port, string userName, string password, HikVisionLoginType loginType)
        +Task Logout()
        +Task GetChannelList()
        +Task StartRealPlay(int streamType, int channelId)
        +Task StopRealPlay()
        +Task TriggerInited(bool inited)
        +Task TriggerGetChannelList(HikVisionChannel channel)
    }

    IHikVision <|.. DefaultHicVision

    HikVisionChannel o-- HikVisionAnalogChannelInfo
    HikVisionChannel o-- HikVisionDigitalChannelInfo
    HikVisionChannel o-- HikVisionZeroChannelInfo

    HikVisionWebPlugin ..> HikVisionLoginType
    HikVisionWebPlugin ..> HikVisionChannel
    HikVisionWebPlugin ..> HikVisionAnalogChannelInfo
    HikVisionWebPlugin ..> HikVisionDigitalChannelInfo
    HikVisionWebPlugin ..> HikVisionZeroChannelInfo
    DefaultHicVision ..> HikVisionLoginType
Loading

File-Level Changes

Change Details Files
Expose channel list retrieval via a new OnGetChannelsAsync callback and JS-invokable bridge.
  • Add OnGetChannelsAsync parameter to HikVisionWebPlugin that receives HikVisionChannel data on login.
  • Implement JSInvokable TriggerGetChannelList in HikVisionWebPlugin to call the new callback.
  • Extend HikVisionWebPlugin.razor.js login wrapper to invoke TriggerGetChannelList with analog, digital, and zero channel lists after a successful login.
  • Introduce GetChannelList method on HikVisionWebPlugin to request channel data from JavaScript.
src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs
src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js
Refine login API surface and state naming for the HikVision component and service.
  • Rename LoginType enum to HikVisionLoginType and update all usages in component and service interfaces.
  • Rename OnLoginedAsync/OnLogoutedAsync to OnLoginAsync/OnLogoutAsync and adjust internal trigger methods.
  • Rename IsLogined state to IsLogin and update conditions in Login, Logout, and StartRealPlay.
  • Fix minor XML doc comments and wording in HikVisionWebPlugin.
src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs
src/components/BootstrapBlazor.HikVision/Services/IHikVision.cs
src/components/BootstrapBlazor.HikVision/Services/DefaultHicVision.cs
src/components/BootstrapBlazor.HikVision/Components/HikVisionLoginType.cs
Enhance JavaScript HikVision integration to manage channel metadata and initialization state consistently.
  • Change init to reuse existing vision object in Data and mark iWndIndex/inited on it instead of overwriting.
  • In login, explicitly reset logined to false on invalid input and set logined true only after channel list retrieval succeeds.
  • Refactor getChannelInfo to getChannelList and normalize channel fields, parsing ids and ports to integers and adding enabled flag for zero channels.
  • Simplify startRealPlay by assuming channel info is already loaded and only fetching device port and window status.
src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js
Add strongly-typed C# models representing HikVision channel information.
  • Introduce HikVisionAnalogChannelInfo, HikVisionDigitalChannelInfo, and HikVisionZeroChannelInfo classes for analog, digital, and zero channel metadata.
  • Add HikVisionChannel aggregate model holding lists of each channel type for use in callbacks like OnGetChannelsAsync.
src/components/BootstrapBlazor.HikVision/Components/HikVisionAnalogChannelInfo.cs
src/components/BootstrapBlazor.HikVision/Components/HikVisionDigitalChannelInfo.cs
src/components/BootstrapBlazor.HikVision/Components/HikVisionZeroChannelInfo.cs
src/components/BootstrapBlazor.HikVision/Components/HikVisionChannel.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#788 Add an OnGetChannelsAsync parameter/callback to the HikVision web plugin component that provides channel information after login.

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 b37dae2 into master Dec 5, 2025
6 of 7 checks passed
@ArgoZhang ArgoZhang deleted the feat-hik branch December 5, 2025 04:41
Copy link

@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 there - I've reviewed your changes and found some issues that need to be addressed.

  • The new GetChannelList C# method calls a JS function named getChannelList, but hikvision.js no longer exports this symbol (it’s only defined as an internal const), so this interop call will fail at runtime; either export getChannelList or route the call through the existing plugin JS wrapper.
  • The HikVisionDigitalChannelInfo model doesn’t match the JS payload: JS builds objects { id, online } while the C# type expects InputPort, Name, and VideoFormat, which will serialize/deserialize incorrectly; align the JS shape or the C# model (including property names) and update the XML docs accordingly.
  • Several comments and names appear inconsistent with behavior: OnGetChannelsAsync is documented as a stop-preview callback and the XML summaries for HikVisionDigitalChannelInfo/HikVisionZeroChannelInfo still say “模拟通道信息”; it would be clearer to update these descriptions and ensure the login callback naming (OnLoginAsync vs TriggerGetChannelList timing) accurately reflects when channels are available.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `GetChannelList` C# method calls a JS function named `getChannelList`, but `hikvision.js` no longer exports this symbol (it’s only defined as an internal `const`), so this interop call will fail at runtime; either export `getChannelList` or route the call through the existing plugin JS wrapper.
- The `HikVisionDigitalChannelInfo` model doesn’t match the JS payload: JS builds objects `{ id, online }` while the C# type expects `InputPort`, `Name`, and `VideoFormat`, which will serialize/deserialize incorrectly; align the JS shape or the C# model (including property names) and update the XML docs accordingly.
- Several comments and names appear inconsistent with behavior: `OnGetChannelsAsync` is documented as a stop-preview callback and the XML summaries for `HikVisionDigitalChannelInfo`/`HikVisionZeroChannelInfo` still say “模拟通道信息”; it would be clearer to update these descriptions and ensure the login callback naming (`OnLoginAsync` vs `TriggerGetChannelList` timing) accurately reflects when channels are available.

## Individual Comments

### Comment 1
<location> `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs:184-187` </location>
<code_context>
+    /// 获得通道列表方法
+    /// </summary>
+    /// <returns></returns>
+    public async Task GetChannelList()
+    {
+        ThrowIfNotInited();
+        await InvokeVoidAsync("getChannelList", Id);
+    }
+
</code_context>

<issue_to_address>
**issue (bug_risk):** The C# `GetChannelList` method invokes a JS function that is not exported, which will cause a JS interop error at runtime.

This calls `InvokeVoidAsync("getChannelList", Id)`, but `HikVisionWebPlugin.razor.js` doesn’t export `getChannelList`, and in `hikvision.js` it is only defined as an internal `const` (not exported). This will cause the interop call to fail at runtime. Please either export `getChannelList` on the JS side and re-export it via the `.razor.js` module, or remove/repurpose this C# method and rely on the existing login callback that fetches channel information.
</issue_to_address>

### Comment 2
<location> `src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js:78` </location>
<code_context>
 }

-export { login, logout, startRealPlay, stopRealPlay }
+export async function login(id, ip, port, userName, password, loginType) {
+    const vision = Data.get(id);
+    await loginVision(id, ip, port, userName, password, loginType);
</code_context>

<issue_to_address>
**issue (bug_risk):** The `login` function doesn’t resolve based on the async callbacks, causing race conditions for callers awaiting it.

Because `login` is marked `async` but doesn’t return a Promise tied to `WebVideoCtrl.I_Login`’s callbacks, `await login(...)` completes before the login actually finishes and before `vision.logined`/channels are updated. Wrap the login flow in a Promise, resolve/reject it in the `success`/`error` callbacks, and return that Promise so callers can reliably await the completed login state.
</issue_to_address>

### Comment 3
<location> `src/components/BootstrapBlazor.HikVision/Components/HikVisionDigitalChannelInfo.cs:10-19` </location>
<code_context>
+/// <summary>
+/// 模拟通道信息
+/// </summary>
+public class HikVisionDigitalChannelInfo()
+{
+    /// <summary>
+    /// 获得 通道 Id
+    /// </summary>
+    public int Id { get; set; }
+
+    /// <summary>
+    /// 获得 通道号
+    /// </summary>
+    public int InputPort { get; set; }
+
+    /// <summary>
+    /// 获得 通道名称
+    /// </summary>
+    public string? Name { get; set; }
+
+    /// <summary>
+    /// 获得 通道制式
+    /// </summary>
+    public string? VideoFormat { get; set; }
+}
</code_context>

<issue_to_address>
**suggestion (bug_risk):** The `HikVisionDigitalChannelInfo` model doesn’t align with the JS channel data shape.

On the JS side `digitalChannels` are shaped as `{ id, online }`, but this class exposes `Id`, `InputPort`, `Name`, and `VideoFormat`. When JS data is marshalled, only `Id` will bind and `online` will be dropped. Please either add an `Online` property (and remove any unused ones) or update the JS mapping to populate the properties defined here so the interop model matches the actual payload.
</issue_to_address>

### Comment 4
<location> `src/components/BootstrapBlazor.HikVision/Components/HikVisionDigitalChannelInfo.cs:7-8` </location>
<code_context>
+
+namespace BootstrapBlazor.Components;
+
+/// <summary>
+/// 模拟通道信息
+/// </summary>
+public class HikVisionAnalogChannelInfo()
</code_context>

<issue_to_address>
**nitpick (typo):** The XML summary for `HikVisionDigitalChannelInfo` refers to it as an analog channel.

The summary text currently says `模拟通道信息` (analog channel info), which conflicts with this type representing digital channel information and with `HikVisionAnalogChannelInfo`. Please update the summary to describe it as a digital channel type to avoid confusion in the API docs.
</issue_to_address>

### Comment 5
<location> `src/components/BootstrapBlazor.HikVision/Components/HikVisionZeroChannelInfo.cs:7-8` </location>
<code_context>
+
+namespace BootstrapBlazor.Components;
+
+/// <summary>
+/// 模拟通道信息
+/// </summary>
+public class HikVisionAnalogChannelInfo()
</code_context>

<issue_to_address>
**nitpick (typo):** The XML summary for `HikVisionZeroChannelInfo` is misleading.

Please update the summary text to explicitly describe this as zero-channel information so it’s clearly distinguished from the analog and digital channel types.
</issue_to_address>

### Comment 6
<location> `src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js:2` </location>
<code_context>
-import { init as initVision, login, logout, startRealPlay, stopRealPlay, dispose as disposeVision } from '../hikvision.js';
+import { init as initVision, login as loginVision, logout, startRealPlay, stopRealPlay, dispose as disposeVision } from '../hikvision.js';
+import Data from '../../BootstrapBlazor/modules/data.js';
 import EventHandler from '../../BootstrapBlazor/modules/event-handler.js';

</code_context>

<issue_to_address>
**issue (complexity):** Consider avoiding use of the shared `Data` store in this interop wrapper and instead pass an `invoke` callback through to `hikvision.js` so channel handling and state live in one place.

You can keep the new feature while reducing the indirection and shared state by removing `Data` usage from this file and pushing the “channels ready” callback into `hikvision.js`.

### 1. Keep `invoke` local to this module instead of using `Data`

```js
// hikvisionInterop.js (this file)

import {
  init as initVision,
  login as loginVision,
  logout,
  startRealPlay,
  stopRealPlay,
  dispose as disposeVision
} from '../hikvision.js';

const invokers = new Map(); // id -> invoke

export async function init(id, invoke) {
  const el = document.getElementById(id);
  if (el === null) {
    return;
  }

  invokers.set(id, invoke);

  const inited = await initVision(id);
  await invoke.invokeMethodAsync('TriggerInited', inited);
}

export async function login(id, ip, port, userName, password, loginType) {
  const invoke = invokers.get(id);
  const logined = await loginVision(id, ip, port, userName, password, loginType, invoke);
  return logined;
}

export { logout, startRealPlay, stopRealPlay };

export function dispose(id) {
  invokers.delete(id);
  disposeVision(id);
}
```

### 2. Move the channel callback into `hikvision.js`

In `hikvision.js`, keep using `Data` for camera/session state only, and invoke .NET when channels are ready:

```js
// hikvision.js

import Data from '../../BootstrapBlazor/modules/data.js';

export async function login(id, ip, port, userName, password, loginType, invoke) {
  const vision = Data.get(id) ?? {};
  // ... existing login logic that sets vision.logined, vision.analogChannels, etc.
  // Data.set(id, vision) as you already do

  if (vision.logined && invoke) {
    await invoke.invokeMethodAsync('TriggerGetChannelList', {
      analogChannels: vision.analogChannels,
      digitalChannels: vision.digitalChannels,
      zeroChannels: vision.zeroChannels
    });
  }

  return vision.logined;
}
```

This keeps:

- All camera state in `hikvision.js` (via `Data`)  
- All interop plumbing (`invoke`) local to the wrapper module  
- `login` sequencing readable in one place (no need to “peek” into `Data` from two modules)
</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.

Comment on lines +184 to +187
public async Task GetChannelList()
{
ThrowIfNotInited();
await InvokeVoidAsync("getChannelList", Id);
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): The C# GetChannelList method invokes a JS function that is not exported, which will cause a JS interop error at runtime.

This calls InvokeVoidAsync("getChannelList", Id), but HikVisionWebPlugin.razor.js doesn’t export getChannelList, and in hikvision.js it is only defined as an internal const (not exported). This will cause the interop call to fail at runtime. Please either export getChannelList on the JS side and re-export it via the .razor.js module, or remove/repurpose this C# method and rely on the existing login callback that fetches channel information.

Comment on lines +10 to +19
public class HikVisionDigitalChannelInfo()
{
/// <summary>
/// 获得 通道 Id
/// </summary>
public int Id { get; set; }

/// <summary>
/// 获得 通道号
/// </summary>
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): The HikVisionDigitalChannelInfo model doesn’t align with the JS channel data shape.

On the JS side digitalChannels are shaped as { id, online }, but this class exposes Id, InputPort, Name, and VideoFormat. When JS data is marshalled, only Id will bind and online will be dropped. Please either add an Online property (and remove any unused ones) or update the JS mapping to populate the properties defined here so the interop model matches the actual payload.

Comment on lines +7 to +8
/// <summary>
/// 模拟通道信息
Copy link

Choose a reason for hiding this comment

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

nitpick (typo): The XML summary for HikVisionDigitalChannelInfo refers to it as an analog channel.

The summary text currently says 模拟通道信息 (analog channel info), which conflicts with this type representing digital channel information and with HikVisionAnalogChannelInfo. Please update the summary to describe it as a digital channel type to avoid confusion in the API docs.

Comment on lines +7 to +8
/// <summary>
/// 模拟通道信息
Copy link

Choose a reason for hiding this comment

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

nitpick (typo): The XML summary for HikVisionZeroChannelInfo is misleading.

Please update the summary text to explicitly describe this as zero-channel information so it’s clearly distinguished from the analog and digital channel types.

Copy link

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 pull request adds a new OnGetChannelsAsync callback parameter to the HikVision component, enabling consumers to receive channel information after successful login. The PR also performs several refactoring improvements including renaming the LoginType enum to HikVisionLoginType for better namespacing, renaming callback parameters from past tense to present tense (e.g., OnLoginedAsync to OnLoginAsync), and restructuring the channel retrieval logic to be called during login rather than during real-time playback.

Key changes:

  • Added OnGetChannelsAsync callback with new channel model classes to expose channel information
  • Refactored channel list retrieval to occur during login instead of during video playback
  • Renamed enum and parameters for better naming consistency and clarity

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
hikvision.js Refactored to retrieve channel lists during login; fixed data structure initialization; added parsing improvements for channel properties
HikVisionWebPlugin.razor.js Added wrapper logic to invoke C# callback with channel data after successful login
IHikVision.cs Updated interface to use renamed HikVisionLoginType enum
DefaultHicVision.cs Updated implementation to use renamed HikVisionLoginType enum
HikVisionWebPlugin.razor.cs Added OnGetChannelsAsync parameter; renamed callbacks to present tense; added TriggerGetChannelList method; renamed IsLogined to IsLogin
HikVisionLoginType.cs Renamed enum from LoginType to HikVisionLoginType for better namespacing
HikVisionZeroChannelInfo.cs New model class for zero channel information with Id, InputPort, and Enabled properties
HikVisionDigitalChannelInfo.cs New model class for digital channel information (has property mismatch issue with JavaScript)
HikVisionChannel.cs New container class to hold all channel types (analog, digital, zero)
HikVisionAnalogChannelInfo.cs New model class for analog channel information
BootstrapBlazor.HikVision.csproj Version bumped from beta02 to beta03
Comments suppressed due to low confidence (1)

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

  • Unused variable logined.
    const { szDeviceIdentify, logined } = vision;

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

Comment on lines 87 to +89
if (oError.errorCode === ERROR_CODE_LOGIN_REPEATLOGIN) {
vision.logined = true;
return;
return true;
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

When handling repeat login (ERROR_CODE_LOGIN_REPEATLOGIN), the code sets vision.logined = true and returns true, but getChannelList is not called in this case. This means the channel information won't be populated when a repeat login occurs, leading to inconsistent behavior compared to the success path where getChannelList is called. Consider calling getChannelList(vision) before setting vision.logined = true in the repeat login case.

Copilot uses AI. Check for mistakes.
const getChannelInfo = vision => {
const { szDeviceIdentify } = vision;
const getChannelList = vision => {
const { szDeviceIdentify, logined } = vision;
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The logined variable is destructured from vision but never used in the getChannelList function. Consider removing it to clean up the code.

Suggested change
const { szDeviceIdentify, logined } = vision;
const { szDeviceIdentify } = vision;

Copilot uses AI. Check for mistakes.
public List<HikVisionDigitalChannelInfo> DigitalChannels { get; set; } = [];

/// <summary>
/// 获得/设置 数字通道信息集合
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The comment on line 23 says "数字通道信息集合" (digital channel info collection) which is identical to the comment on line 18 for DigitalChannels. The comment for ZeroChannels should be "零通道信息集合" (zero channel info collection) instead.

Suggested change
/// 获得/设置 数字通道信息集合
/// 获得/设置 零通道信息集合

Copilot uses AI. Check for mistakes.

/// <summary>
/// 获得 Websdk 插件是否初始化成功
/// 获得 Web sdk 插件是否初始化成功
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The comment uses "Web sdk" (with a space and lowercase "sdk") while line 10 uses "WebSdk" (no space, camelCase). For consistency, this should also be "WebSdk" to match the naming convention used elsewhere in the file.

Suggested change
/// 获得 Web sdk 插件是否初始化成功
/// 获得 WebSdk 插件是否初始化成功

Copilot uses AI. Check for mistakes.
/// 获得 是否已登录
/// </summary>
public bool IsLogined { get; private set; }
public bool IsLogin { get; private set; }
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

[nitpick] The property name IsLogin is grammatically awkward. Consider using IsLoggedIn instead, which is the standard past participle form used in similar contexts (e.g., User.IsLoggedIn() is a common pattern). Alternatively, IsAuthenticated would also be appropriate.

Suggested change
public bool IsLogin { get; private set; }
public bool IsLoggedIn { get; private set; }

Copilot uses AI. Check for mistakes.
public Func<Task>? OnLoginAsync { get; set; }

/// <summary>
/// 获得/设置 停止预览后回调方法
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The documentation comment incorrectly states "停止预览后回调方法" (callback method after stopping preview), but this parameter is OnGetChannelsAsync which is called after getting the channel list. The comment should be something like "获取通道列表后回调方法" (callback method after getting channel list) instead.

Suggested change
/// 获得/设置 停止预览后回调方法
/// 获得/设置 获取通道列表后回调方法

Copilot uses AI. Check for mistakes.
namespace BootstrapBlazor.Components;

/// <summary>
/// 模拟通道信息
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The documentation comment incorrectly states "模拟通道信息" (analog channel info), but this class represents digital channel information. It should be "数字通道信息" (digital channel info) instead.

Suggested change
/// 模拟通道信息
/// 数字通道信息

Copilot uses AI. Check for mistakes.
namespace BootstrapBlazor.Components;

/// <summary>
/// 模拟通道信息
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The documentation comment incorrectly states "模拟通道信息" (analog channel info), but this class represents zero channel information. It should be "零通道信息" (zero channel info) instead.

Suggested change
/// 模拟通道信息
/// 零通道信息

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +30
/// 获得 通道号
/// </summary>
public int InputPort { get; set; }

/// <summary>
/// 获得 通道名称
/// </summary>
public string? Name { get; set; }

/// <summary>
/// 获得 通道制式
/// </summary>
public string? VideoFormat { get; set; }
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The JavaScript code in hikvision.js (lines 134-138) sets an online property for digital channels, not InputPort, Name, or VideoFormat. This mismatch will cause deserialization issues when JavaScript passes data to C#. The HikVisionDigitalChannelInfo class should have an Online property (string or bool) instead of InputPort, Name, and VideoFormat, or the JavaScript code needs to be updated to extract these fields from the XML.

Suggested change
/// 获得 通道号
/// </summary>
public int InputPort { get; set; }
/// <summary>
/// 获得 通道名称
/// </summary>
public string? Name { get; set; }
/// <summary>
/// 获得 通道制式
/// </summary>
public string? VideoFormat { get; set; }
/// 获得 通道在线状态
/// </summary>
public string? Online { get; set; }

Copilot uses AI. Check for mistakes.
Comment on lines 3 to 4
import EventHandler from '../../BootstrapBlazor/modules/event-handler.js';

Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

Unused import EventHandler.

Suggested change
import EventHandler from '../../BootstrapBlazor/modules/event-handler.js';

Copilot uses AI. Check for mistakes.
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 OnGetChannelsAsync parameter

2 participants