Skip to content

Commit bdbd944

Browse files
authored
feat(HikVision): hack JSVideoPlugin script prevent throw exception (#795)
* fix: 修复底层报错问题 * chore: bump version 10.0.0 * refactor: 精简代码 * chore: bump version 10.0.0-beta06
1 parent ee340ab commit bdbd944

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/components/BootstrapBlazor.HikVision/BootstrapBlazor.HikVision.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.0.0-beta05</Version>
4+
<Version>10.0.0-beta06</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { addScript } from '../BootstrapBlazor/modules/utility.js';
1+
import { addScript, registerBootstrapBlazorModule } from '../BootstrapBlazor/modules/utility.js';
22
import Data from '../BootstrapBlazor/modules/data.js';
33

44
export async function init(id) {
5-
await addScript('./_content/BootstrapBlazor.HikVision/jsVideoPlugin-1.0.0.min.js');
65
await addScript('./_content/BootstrapBlazor.HikVision/webVideoCtrl.js');
76

87
if (window.$ === void 0) {
@@ -26,6 +25,29 @@ export async function init(id) {
2625
return true;
2726
}
2827

28+
const hackJSResize = function () {
29+
const originalResize = JSVideoPlugin.prototype.JS_Resize;
30+
JSVideoPlugin.prototype.JS_Resize = function (e, t) {
31+
const { szId } = this.oOptions;
32+
if (document.getElementById(szId)) {
33+
return originalResize.call(this, e, t);
34+
}
35+
}
36+
}
37+
38+
const hackJSDestroyPlugin = function () {
39+
const originalDestroy = JSVideoPlugin.prototype.JS_DestroyPlugin;
40+
JSVideoPlugin.prototype.JS_DestroyPlugin = function (n) {
41+
const origianlSendRequestProxy = this.oPlugin.oRequest.oRequest.sendRequest;
42+
this.oPlugin.oRequest.oRequest.sendRequest = function (r) {
43+
if (this.oWebSocket && WebSocket.OPEN === this.oWebSocket.readyState) {
44+
return origianlSendRequestProxy.call(this, r);
45+
}
46+
}
47+
return this.oPlugin.JS_DestroyPlugin(true);
48+
}
49+
}
50+
2951
const initWindow = id => {
3052
const result = { inited: null, iWndIndex: -1 };
3153
WebVideoCtrl.I_InitPlugin({
@@ -53,7 +75,9 @@ const initWindow = id => {
5375
return new Promise((resolve, reject) => {
5476
const handler = setInterval(() => {
5577
if (result.inited === false || (result.inited && result.iWndIndex !== -1)) {
56-
clearInterval(handler)
78+
clearInterval(handler);
79+
hackJSResize();
80+
hackJSDestroyPlugin();
5781
resolve(result);
5882
}
5983
}, 16);
@@ -279,7 +303,6 @@ export function dispose(id) {
279303
logout(id);
280304
}
281305
WebVideoCtrl.I_DestroyPlugin();
282-
283306
}
284307

285308
const getTagNameFirstValue = (xmlDoc, tagName, defaultValue = '0') => {

0 commit comments

Comments
 (0)