diff --git a/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj b/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj index f0593360..96d0affd 100644 --- a/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj +++ b/src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj @@ -1,7 +1,7 @@ - 10.0.0-beta05 + 10.0.0-beta06 diff --git a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js index c9e43591..ae3c3b71 100644 --- a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js +++ b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js @@ -1,8 +1,7 @@ -import { addScript } from '../BootstrapBlazor/modules/utility.js'; +import { addScript, registerBootstrapBlazorModule } from '../BootstrapBlazor/modules/utility.js'; import Data from '../BootstrapBlazor/modules/data.js'; export async function init(id) { - await addScript('./_content/BootstrapBlazor.HikVision/jsVideoPlugin-1.0.0.min.js'); await addScript('./_content/BootstrapBlazor.HikVision/webVideoCtrl.js'); if (window.$ === void 0) { @@ -26,6 +25,29 @@ export async function init(id) { 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 hackJSDestroyPlugin = function () { + const originalDestroy = JSVideoPlugin.prototype.JS_DestroyPlugin; + JSVideoPlugin.prototype.JS_DestroyPlugin = function (n) { + const origianlSendRequestProxy = this.oPlugin.oRequest.oRequest.sendRequest; + this.oPlugin.oRequest.oRequest.sendRequest = function (r) { + if (this.oWebSocket && WebSocket.OPEN === this.oWebSocket.readyState) { + return origianlSendRequestProxy.call(this, r); + } + } + return this.oPlugin.JS_DestroyPlugin(true); + } +} + const initWindow = id => { const result = { inited: null, iWndIndex: -1 }; WebVideoCtrl.I_InitPlugin({ @@ -53,7 +75,9 @@ const initWindow = id => { return new Promise((resolve, reject) => { const handler = setInterval(() => { if (result.inited === false || (result.inited && result.iWndIndex !== -1)) { - clearInterval(handler) + clearInterval(handler); + hackJSResize(); + hackJSDestroyPlugin(); resolve(result); } }, 16); @@ -279,7 +303,6 @@ export function dispose(id) { logout(id); } WebVideoCtrl.I_DestroyPlugin(); - } const getTagNameFirstValue = (xmlDoc, tagName, defaultValue = '0') => {