-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(HikVision): add HidePlugin function #799
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 3 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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,15 +22,49 @@ export async function init(id) { | |||||||||||
| vision.iWndIndex = result.iWndIndex; | ||||||||||||
| vision.inited = true; | ||||||||||||
|
|
||||||||||||
| const observer = new IntersectionObserver(() => { | ||||||||||||
| if (checkVisibility(el)) { | ||||||||||||
| WebVideoCtrl.I_Resize(el.offsetWidth, el.offsetHeight); | ||||||||||||
| } | ||||||||||||
| }); | ||||||||||||
| observer.observe(el); | ||||||||||||
| vision.observer = observer; | ||||||||||||
|
|
||||||||||||
| return true; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| const hackJSResize = function () { | ||||||||||||
| const originalResize = JSVideoPlugin.prototype.JS_Resize; | ||||||||||||
| JSVideoPlugin.prototype.JS_Resize = function (e, t) { | ||||||||||||
| const { szId } = this.oOptions; | ||||||||||||
| if (document.getElementById(szId)) { | ||||||||||||
| return originalResize.call(this, e, t); | ||||||||||||
| const el = document.getElementById(szId); | ||||||||||||
| if (el) { | ||||||||||||
| const visible = checkVisibility(el); | ||||||||||||
| if (visible) { | ||||||||||||
| return originalResize.call(this, e, t); | ||||||||||||
| } | ||||||||||||
| else { | ||||||||||||
| WebVideoCtrl.I_HidPlugin(); | ||||||||||||
|
||||||||||||
| WebVideoCtrl.I_HidPlugin(); | |
| WebVideoCtrl.I_HidePlugin(); |
Copilot
AI
Dec 7, 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 JS_Resize function should return a value when the element is not visible. Currently, when visible is false and I_HidPlugin() is called, the function doesn't return anything (implicit undefined). This could break calling code that expects a return value. Consider adding an explicit return statement.
| WebVideoCtrl.I_HidPlugin(); | |
| WebVideoCtrl.I_HidPlugin(); | |
| return false; |
Copilot
AI
Dec 7, 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 reject parameter is declared but never used. When returning an empty resolved promise for a non-visible element, this could mask errors. Consider whether this is the intended behavior or if the promise should be rejected instead to signal that the window cannot be shown.
| resolve(); | |
| reject(new Error("Element is not visible, cannot show window.")); |
Copilot
AI
Dec 7, 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.
This empty promise can be simplified using Promise.resolve() instead of constructing a new Promise with an executor function. This is more concise and clearer in intent.
| return new Promise((resolve, reject) => { | |
| resolve(); | |
| }); | |
| return Promise.resolve(); |
Copilot
AI
Dec 7, 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.
Using a magic number 0.01 without explanation makes the code harder to understand. Consider adding a comment explaining why this specific threshold is chosen for opacity checks, or define it as a named constant like MIN_VISIBLE_OPACITY.
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 IntersectionObserver callback doesn't use the
entriesparameter to check intersection state. The observer fires for both entering and leaving viewport, but the current implementation only checks visibility without considering the intersection state. This could cause unnecessary resize calls. Consider checkingentries[0].isIntersectingto only resize when the element is actually intersecting the viewport.