Skip to content
Merged
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ export function stopRealPlay(id) {
}

export function dispose(id) {
stopRealPlay(id);
logout(id);
WebVideoCtrl.I_DestroyPlugin();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Destroying the global plugin in a per-id dispose may affect other active sessions.

If WebVideoCtrl is a singleton shared across multiple ids, calling I_DestroyPlugin() here will shut it down for all sessions whenever any one id is disposed. That can break other active or subsequent sessions. You may need to only destroy the plugin when the last id is disposed, or move plugin lifecycle management outside this per-id dispose path.

Comment on lines +240 to +242
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The dispose function doesn't wait for asynchronous operations to complete. Both stopRealPlay(id) and logout(id) perform asynchronous operations via WebVideoCtrl.I_Stop and WebVideoCtrl.I_Logout, but dispose doesn't await their completion before calling WebVideoCtrl.I_DestroyPlugin() and Data.remove(id). This can lead to race conditions where the plugin is destroyed or data is removed while cleanup operations are still in progress.

Consider making dispose async and awaiting the operations:

export async function dispose(id) {
    await stopRealPlay(id);
    await logout(id);
    WebVideoCtrl.I_DestroyPlugin();
    
    Data.remove(id);
}

Note: You'll also need to update stopRealPlay to return a Promise for proper awaiting.

Copilot uses AI. Check for mistakes.

Comment on lines +240 to +243
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The dispose function lacks error handling. If Data.get(id) fails (e.g., if the id doesn't exist), both stopRealPlay(id) and logout(id) will throw errors, preventing the cleanup from completing. This could leave resources in an inconsistent state.

Consider adding try-catch blocks or null checks:

export function dispose(id) {
    try {
        stopRealPlay(id);
    } catch (e) {
        console.error('Error stopping real play:', e);
    }
    
    try {
        logout(id);
    } catch (e) {
        console.error('Error logging out:', e);
    }
    
    WebVideoCtrl.I_DestroyPlugin();
    Data.remove(id);
}
Suggested change
stopRealPlay(id);
logout(id);
WebVideoCtrl.I_DestroyPlugin();
try {
stopRealPlay(id);
} catch (e) {
console.error('Error stopping real play:', e);
}
try {
logout(id);
} catch (e) {
console.error('Error logging out:', e);
}
WebVideoCtrl.I_DestroyPlugin();

Copilot uses AI. Check for mistakes.
Data.remove(id);
Comment on lines +242 to 244
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

WebVideoCtrl.I_DestroyPlugin() appears to destroy the entire plugin instance globally, not just for a specific id. If multiple HikVision components can exist simultaneously (which is suggested by the id parameter pattern throughout the codebase), calling this in dispose(id) will destroy the plugin for all instances, not just the one being disposed.

Consider checking if there are any remaining instances before destroying the plugin:

Data.remove(id);
if (Data.size === 0) {
    WebVideoCtrl.I_DestroyPlugin();
}

Or, if the plugin is designed to be per-instance, ensure proper instance management in the WebVideoCtrl API.

Suggested change
WebVideoCtrl.I_DestroyPlugin();
Data.remove(id);
Data.remove(id);
if (Data.size === 0) {
WebVideoCtrl.I_DestroyPlugin();
}

Copilot uses AI. Check for mistakes.
}

Expand Down