# 海康 ISC
# 初始化插件时容器的长宽必须为数字不能是百分比
/**
* 获取rsa公钥
* @param callback
*/
const findPubKey = (callback = (a) => a) => {
if (webControlObj.current && hasInstalledObj.current) {
webControlObj.current
.JS_RequestInterface({
funcName: funcNameObj.getRSAPubKey,
argument: JSON.stringify({ keyLength: 1024 }),
})
.then((res) => {
// console.log(res);
if (res.responseMsg?.data) {
// console.info(res.responseMsg, '-=-=-=-=-=-=-=-')
setPubKey(res.responseMsg.data);
callback(res.responseMsg.data);
}
});
}
};
// RSA加密
const setEncrypt = (paramValue, paramKey) => {
const encrypt = new JSEncrypt();
encrypt.setPublicKey(paramKey);
return encrypt.encrypt(paramValue);
};
// 推送消息
const cbIntegrationCallBack = (oData) => {
console.info(
JSON.stringify(oData.responseMsg),
"OoO_OoO_OoO_OoO_OoO_OoO_OoO"
);
};
// 初始化数据
const initData = (paramKey) => {
if (webControlObj.current && paramKey && hasInstalledObj.current) {
const { host, appKey, appSecret } = generateVideoParam(videoDevice);
console.info(
`\n%c设备扩展信息中appKey:%c${appKey}`,
"color: #00CFFF; background: #000000; padding: 8px 4px",
"color: #000000; background: #00CFFF; padding: 8px 4px"
);
webControlObj.current
.JS_RequestInterface({
funcName: funcNameObj.init,
argument: JSON.stringify({
...initDataObj,
appkey: appKey || initDataObj.appkey,
ip: host || initDataObj.ip,
secret: setEncrypt(appSecret || initDataObj.secret, paramKey),
}),
})
.then((res) =>
webControlObj.current.JS_Resize(videoStyle.width, videoStyle.height)
);
// 初始化后resize一次,规避firefox下首次显示窗口后插件窗口未与DIV窗口重合问题
}
};
/**
* 初始化插件
*/
const initPlugin = () => {
// console.info('开始初始化插件>>>>>>')
webControlObj.current = new WebControl({
// 指定容器id
szPluginContainer: videoContainerId,
// 指定起止端口号,建议使用该值
iServicePortStart: 15900,
iServicePortEnd: 15909,
// 用于IE10使用ActiveX的clsid
szClassId: "23BF3B0A-2C56-4D97-9C03-0CB103AA8F11",
// 创建WebControl实例成功
cbConnectSuccess() {
console.log("web控件实例创建成功>>>>>");
hasInstalledObj.current = true;
// WebControl实例创建成功后需要启动服务
webControlObj.current
.JS_StartService("window", {
// 值"./VideoPluginConnect.dll"写死
dllPath: "./VideoPluginConnect.dll",
})
.then(
() => {
// 启动插件服务成功
webControlObj.current.JS_SetWindowControlCallback({
// 设置消息回调
cbIntegrationCallBack,
});
// JS_CreateWnd创建视频播放窗口,宽高可设定
webControlObj.current
.JS_CreateWnd(
videoContainerId,
videoStyle.width,
videoStyle.height
)
.then(() => {
// console.info(webControlObj.current, '------------------')
// 创建播放实例成功后初始化
findPubKey((paramKey) => initData(paramKey));
});
},
() => {
// 启动插件服务失败
}
);
},
cbConnectError() {
// 创建WebControl实例失败
webControlObj.current = null;
$(`#${videoContainerId}`).html("插件未启动,正在尝试启动,请稍候...");
WebControl.JS_WakeUp("VideoWebPlugin://"); // 程序未启动时执行error函数,采用wakeup来启动程序
setInitCount((prevState) => {
const newCount = prevState + 1;
// console.info(newCount, '-=-=-=-=-=-=-=-=-=-')
if (newCount < 3) {
setTimeout(() => {
initPlugin();
}, 3000);
} else {
hasInstalledObj.current = false;
$(`#${videoContainerId}`).html("");
}
return newCount;
});
},
cbConnectClose(bNormalClose) {
// 异常断开:bNormalClose = false
// JS_Disconnect正常断开:bNormalClose = true
console.log("连接断开<<<<<");
webControlObj.current = null;
},
});
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138