Skip to content

Commit fa5e369

Browse files
committed
feat: 增加海康威视摄像头功能
1 parent b57f1c3 commit fa5e369

8 files changed

Lines changed: 301 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

3+
<PropertyGroup>
4+
<Version>10.0.0-beta01</Version>
5+
</PropertyGroup>
6+
37
<PropertyGroup>
48
<PackageTags>Bootstrap Blazor WebAssembly wasm UI Components Graph</PackageTags>
59
<Description>Bootstrap UI components extensions of Graph</Description>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
using BootstrapBlazor.Components;
6+
using Microsoft.Extensions.DependencyInjection.Extensions;
7+
8+
namespace Microsoft.Extensions.DependencyInjection;
9+
10+
/// <summary>
11+
/// BootstrapBlazor 服务扩展类
12+
/// </summary>
13+
public static class ServiceCollectionExtensions
14+
{
15+
/// <summary>
16+
/// 增加海康威视网络摄像机 Web 服务
17+
/// </summary>
18+
/// <param name="services"></param>
19+
/// <returns></returns>
20+
public static IServiceCollection AddBootstrapBlazorHikVision(this IServiceCollection services)
21+
{
22+
services.TryAddScoped<IHikVision, DefaultHicVision>();
23+
return services;
24+
}
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
/// <summary>
8+
/// 登录方式
9+
/// </summary>
10+
public enum LoginType
11+
{
12+
/// <summary>
13+
/// http 方式
14+
/// </summary>
15+
Http = 1,
16+
17+
/// <summary>
18+
/// https 方式
19+
/// </summary>
20+
Https = 2
21+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
sealed class DefaultHicVision(IJSRuntime jsRuntime) : IHikVision
8+
{
9+
private JSModule _module = default!;
10+
private bool _initialized;
11+
private bool _logined;
12+
13+
public async Task<bool> Login(string ip, int port, string userName, string password, LoginType loginType = LoginType.Http)
14+
{
15+
await LoadAsync();
16+
17+
if (!_logined)
18+
{
19+
_logined = await _module.InvokeAsync<bool>("login", ip, port, userName, password, (int)loginType);
20+
}
21+
22+
return _logined;
23+
}
24+
25+
public async Task<bool> Logout(string ip, int port)
26+
{
27+
if (_logined)
28+
{
29+
_logined = await _module.InvokeAsync<bool>("logout");
30+
}
31+
32+
return _logined;
33+
}
34+
35+
public async Task StartRealPlay()
36+
{
37+
if (_logined)
38+
{
39+
await _module.InvokeVoidAsync("startRealPlay");
40+
}
41+
}
42+
43+
public async Task StopRealPlay()
44+
{
45+
if (_logined)
46+
{
47+
await _module.InvokeVoidAsync("stopRealPlay");
48+
}
49+
}
50+
51+
private async Task LoadAsync()
52+
{
53+
if (!_initialized)
54+
{
55+
var module = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/BootstrapBlazor.HikVision/hikvision.js");
56+
_module = new JSModule(module);
57+
58+
_initialized = true;
59+
}
60+
}
61+
62+
public async ValueTask DisposeAsync()
63+
{
64+
if (_module != null)
65+
{
66+
await _module.InvokeVoidAsync("dispose");
67+
await _module.DisposeAsync();
68+
}
69+
GC.SuppressFinalize(this);
70+
}
71+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
/// <summary>
8+
/// 海康威视网络摄像机接口
9+
/// </summary>
10+
public interface IHikVision : IAsyncDisposable
11+
{
12+
/// <summary>
13+
/// 登录方法
14+
/// </summary>
15+
/// <param name="loginType">登录方式 <see cref="LoginType"/> 实例</param>
16+
/// <param name="ip">设备 Ip 地址</param>
17+
/// <param name="port">设备端口</param>
18+
/// <param name="userName">用户名</param>
19+
/// <param name="password">密码</param>
20+
/// <returns></returns>
21+
Task<bool> Login(string ip, int port, string userName, string password, LoginType loginType = LoginType.Http);
22+
23+
/// <summary>
24+
/// 登出方法
25+
/// </summary>
26+
/// <param name="ip">设备 Ip 地址</param>
27+
/// <param name="port">设备端口</param>
28+
/// <returns></returns>
29+
Task<bool> Logout(string ip, int port);
30+
31+
/// <summary>
32+
/// 开始实时预览画面方法
33+
/// </summary>
34+
/// <returns></returns>
35+
Task StartRealPlay();
36+
37+
/// <summary>
38+
/// 停止实时预览画面方法
39+
/// </summary>
40+
/// <returns></returns>
41+
Task StopRealPlay();
42+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { addScript } from '../BootstrapBlazor/modules/utility.js';
2+
3+
export async function login(ip, port, userName, password, loginType) {
4+
await addScript('./_content/BootstrapBlazor.HikVision/jsVideoPlugin-1.0.0.min.js');
5+
await addScript('./_content/BootstrapBlazor.HikVision/webVideoCtrl.js');
6+
7+
await init_video_plugin();
8+
9+
//var szDeviceIdentify = `${ip}_ ${port}`;
10+
11+
WebVideoCtrl.I_Login(ip, loginType, port, userName, password, {
12+
timeout: 3000,
13+
success: function (xmlDoc) {
14+
showOPInfo(szDeviceIdentify + " 登录成功!");
15+
$("#ip").prepend("<option value='" + szDeviceIdentify + "'>" + szDeviceIdentify + "</option>");
16+
setTimeout(function () {
17+
$("#ip").val(szDeviceIdentify);
18+
setTimeout(function () {
19+
getChannelInfo();
20+
}, 1000);
21+
getDevicePort();
22+
}, 10);
23+
console.log(xmlDoc);
24+
},
25+
error: function (oError) {
26+
console.log(oError);
27+
//if (ERROR_CODE_LOGIN_REPEATLOGIN === status) {
28+
// showOPInfo(szDeviceIdentify + " 已登录过!");
29+
//} else {
30+
// if (oError.errorCode === 401) {
31+
// showOPInfo(szDeviceIdentify + " 登录失败,已自动切换认证方式!");
32+
// } else {
33+
// showOPInfo(szDeviceIdentify + " 登录失败!", oError.errorCode, oError.errorMsg);
34+
// }
35+
//}
36+
}
37+
});
38+
39+
return true;
40+
}
41+
42+
const init_video_plugin = async () => {
43+
let inited = false;
44+
WebVideoCtrl.I_InitPlugin({
45+
bWndFull: true,
46+
iWndowType: 1,
47+
cbSelWnd: function (xmlDoc) {
48+
//g_iWndIndex = parseInt($(xmlDoc).find("SelectWnd").eq(0).text(), 10);
49+
//var szInfo = "当前选择的窗口编号:" + g_iWndIndex;
50+
//showCBInfo(szInfo);
51+
},
52+
cbDoubleClickWnd: function (iWndIndex, bFullScreen) {
53+
// var szInfo = "当前放大的窗口编号:" + iWndIndex;
54+
// if (!bFullScreen) {
55+
// szInfo = "当前还原的窗口编号:" + iWndIndex;
56+
// }
57+
// showCBInfo(szInfo);
58+
},
59+
cbEvent: function (iEventType, iParam1, iParam2) {
60+
// if (2 == iEventType) {// 回放正常结束
61+
// showCBInfo("窗口" + iParam1 + "回放结束!");
62+
// } else if (-1 == iEventType) {
63+
// showCBInfo("设备" + iParam1 + "网络错误!");
64+
// } else if (3001 == iEventType) {
65+
// clickStopRecord(g_szRecordType, iParam1);
66+
// }
67+
},
68+
cbInitPluginComplete: function () {
69+
WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin").then(() => {
70+
WebVideoCtrl.I_CheckPluginVersion().then((bFlag) => {
71+
if (bFlag) {
72+
alert("检测到新的插件版本,双击开发包目录里的HCWebSDKPluginsUserSetup.exe升级!");
73+
}
74+
75+
inited = true;
76+
});
77+
}, () => {
78+
alert("插件初始化失败,请确认是否已安装插件;如果未安装,请双击开发包目录里的HCWebSDKPluginsUserSetup.exe安装!");
79+
});
80+
}
81+
});
82+
83+
return new Promise((resolve, reject) => {
84+
const handler = setInterval(() => {
85+
if (inited) {
86+
clearInterval(handler)
87+
resolve()
88+
}
89+
}, 20)
90+
})
91+
}
92+
93+
export function logout(id) {
94+
var szDeviceIdentify = `${ip}_ ${port}`;
95+
96+
WebVideoCtrl.I_Logout(szDeviceIdentify).then(() => {
97+
//$("#ip option:contains(" + szDeviceIdentify + ")").remove();
98+
//showOPInfo(szDeviceIdentify + " " + "退出成功!");
99+
}, () => {
100+
//showOPInfo(szDeviceIdentify + " " + "退出失败!");
101+
});
102+
}
103+
104+
export function startRealPlay() {
105+
106+
}
107+
108+
export function stopRealPlay() {
109+
110+
}
111+
112+
export function dispose() {
113+
114+
}

src/components/BootstrapBlazor.HikVision/wwwroot/jsVideoPlugin-1.0.0.min.js

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)