Skip to content

Commit e7fc8ae

Browse files
committed
feat: 增加获得设备通道逻辑
1 parent deaf194 commit e7fc8ae

9 files changed

Lines changed: 152 additions & 26 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 class HikVisionChannel
11+
{
12+
/// <summary>
13+
/// 获得/设置 模拟通道信息集合
14+
/// </summary>
15+
public List<HikVisionAnalogChannelInfo> AnalogChannels { get; set; } = [];
16+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 class HikVisionAnalogChannelInfo()
11+
{
12+
/// <summary>
13+
/// 获得 通道 Id
14+
/// </summary>
15+
public int Id { get; set; }
16+
17+
/// <summary>
18+
/// 获得 通道号
19+
/// </summary>
20+
public int InputPort { get; set; }
21+
22+
/// <summary>
23+
/// 获得 通道名称
24+
/// </summary>
25+
public string? Name { get; set; }
26+
27+
/// <summary>
28+
/// 获得 通道制式
29+
/// </summary>
30+
public string? VideoFormat { get; set; }
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 class HikVisionDigitalChannelInfo()
11+
{
12+
/// <summary>
13+
/// 获得 通道 Id
14+
/// </summary>
15+
public int Id { get; set; }
16+
17+
/// <summary>
18+
/// 获得 通道号
19+
/// </summary>
20+
public int InputPort { get; set; }
21+
22+
/// <summary>
23+
/// 获得 通道名称
24+
/// </summary>
25+
public string? Name { get; set; }
26+
27+
/// <summary>
28+
/// 获得 通道制式
29+
/// </summary>
30+
public string? VideoFormat { get; set; }
31+
}

src/components/BootstrapBlazor.HikVision/LoginType.cs renamed to src/components/BootstrapBlazor.HikVision/Components/HikVisionLoginType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace BootstrapBlazor.Components;
77
/// <summary>
88
/// 登录方式
99
/// </summary>
10-
public enum LoginType
10+
public enum HikVisionLoginType
1111
{
1212
/// <summary>
1313
/// http 方式

src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public partial class HikVisionWebPlugin
3737
public string? Password { get; set; }
3838

3939
/// <summary>
40-
/// 获得/设置 网络摄像机 登录类型 默认值 <see cref="LoginType.Http"/>
40+
/// 获得/设置 网络摄像机 登录类型 默认值 <see cref="HikVisionLoginType.Http"/>
4141
/// </summary>
4242
[Parameter]
43-
public LoginType LoginType { get; set; }
43+
public HikVisionLoginType LoginType { get; set; }
4444

4545
/// <summary>
4646
/// 获得/设置 视频图像窗口宽度 默认值 500px
@@ -66,6 +66,12 @@ public partial class HikVisionWebPlugin
6666
[Parameter]
6767
public Func<Task>? OnLoginedAsync { get; set; }
6868

69+
/// <summary>
70+
/// 获得/设置 停止预览后回调方法
71+
/// </summary>
72+
[Parameter]
73+
public Func<HikVisionChannel, Task>? OnGetChannelsAsync { get; set; }
74+
6975
/// <summary>
7076
/// 获得/设置 注销成功后回调方法
7177
/// </summary>
@@ -129,7 +135,7 @@ protected override void OnParametersSet()
129135
/// <param name="password"></param>
130136
/// <param name="loginType"></param>
131137
/// <returns></returns>
132-
public async Task<bool> Login(string ip, int port, string userName, string password, LoginType loginType = LoginType.Http)
138+
public async Task<bool> Login(string ip, int port, string userName, string password, HikVisionLoginType loginType = HikVisionLoginType.Http)
133139
{
134140
ThrowIfNotInited();
135141
IsLogined = await InvokeAsync<bool?>("login", Id, ip, port, userName, password, (int)loginType) ?? false;
@@ -171,6 +177,16 @@ private async Task TriggerLogouted()
171177
}
172178
}
173179

180+
/// <summary>
181+
/// 获得通道列表方法
182+
/// </summary>
183+
/// <returns></returns>
184+
public async Task GetChannelList()
185+
{
186+
ThrowIfNotInited();
187+
await InvokeVoidAsync("getChannelList", Id);
188+
}
189+
174190
/// <summary>
175191
/// 开始实时预览方法
176192
/// </summary>
@@ -239,4 +255,18 @@ public async Task TriggerInited(bool inited)
239255
await OnInitedAsync(inited);
240256
}
241257
}
258+
259+
/// <summary>
260+
/// 触发 <see cref="OnGetChannelsAsync"/> 回调方法由 JavaScript 调用
261+
/// </summary>
262+
/// <param name="channel"></param>
263+
/// <returns></returns>
264+
[JSInvokable]
265+
public async Task TriggerGetChannelList(HikVisionChannel channel)
266+
{
267+
if (OnGetChannelsAsync != null)
268+
{
269+
await OnGetChannelsAsync(channel);
270+
}
271+
}
242272
}

src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { init as initVision, login, logout, startRealPlay, stopRealPlay, dispose as disposeVision } from '../hikvision.js';
1+
import { init as initVision, login as loginVision, logout, startRealPlay, stopRealPlay, dispose as disposeVision } from '../hikvision.js';
2+
import Data from '../../BootstrapBlazor/modules/data.js';
23
import EventHandler from '../../BootstrapBlazor/modules/event-handler.js';
34

45
export async function init(id, invoke) {
@@ -7,11 +8,27 @@ export async function init(id, invoke) {
78
return;
89
}
910

11+
Data.set(id, {
12+
invoke
13+
});
14+
1015
const inited = await initVision(id);
1116
await invoke.invokeMethodAsync('TriggerInited', inited);
1217
}
1318

14-
export { login, logout, startRealPlay, stopRealPlay }
19+
export async function login(id, ip, port, userName, password, loginType) {
20+
const vision = Data.get(id);
21+
await loginVision(id, ip, port, userName, password, loginType);
22+
const { logined, invoke } = vision;
23+
if (logined) {
24+
await invoke.invokeMethodAsync('TriggerGetChannelList', {
25+
analogChannels: vision.analogChannels
26+
});
27+
}
28+
return logined;
29+
}
30+
31+
export { logout, startRealPlay, stopRealPlay }
1532

1633
export function dispose(id) {
1734
disposeVision(id);

src/components/BootstrapBlazor.HikVision/Services/DefaultHicVision.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sealed class DefaultHicVision(IJSRuntime jsRuntime) : IHikVision
1010
private bool _initialized;
1111
private bool _logined;
1212

13-
public async Task<bool> Login(string ip, int port, string userName, string password, LoginType loginType = LoginType.Http)
13+
public async Task<bool> Login(string ip, int port, string userName, string password, HikVisionLoginType loginType = HikVisionLoginType.Http)
1414
{
1515
await LoadAsync();
1616

src/components/BootstrapBlazor.HikVision/Services/IHikVision.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public interface IHikVision : IAsyncDisposable
1212
/// <summary>
1313
/// 登录方法
1414
/// </summary>
15-
/// <param name="loginType">登录方式 <see cref="LoginType"/> 实例</param>
15+
/// <param name="loginType">登录方式 <see cref="HikVisionLoginType"/> 实例</param>
1616
/// <param name="ip">设备 Ip 地址</param>
1717
/// <param name="port">设备端口</param>
1818
/// <param name="userName">用户名</param>
1919
/// <param name="password">密码</param>
2020
/// <returns></returns>
21-
Task<bool> Login(string ip, int port, string userName, string password, LoginType loginType = LoginType.Http);
21+
Task<bool> Login(string ip, int port, string userName, string password, HikVisionLoginType loginType = HikVisionLoginType.Http);
2222

2323
/// <summary>
2424
/// 登出方法

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ export async function init(id) {
1919
return false;
2020
}
2121

22-
Data.set(id, {
23-
iWndIndex: result.iWndIndex,
24-
inited: true
25-
});
22+
const vision = Data.get(id);
23+
vision.iWndIndex = result.iWndIndex;
24+
vision.inited = true;
2625

2726
return true;
2827
}
@@ -64,6 +63,7 @@ export async function login(id, ip, port, userName, password, loginType) {
6463
const vision = Data.get(id);
6564
const { inited, logined } = vision;
6665
if (inited !== true || ip.length === 0 || port <= 0 || userName.length === 0 || password.length === 0) {
66+
vision.logined = false;
6767
return false;
6868
}
6969
if (logined === true) {
@@ -78,13 +78,15 @@ export async function login(id, ip, port, userName, password, loginType) {
7878
WebVideoCtrl.I_Login(ip, loginType, port, userName, password, {
7979
timeout: 3000,
8080
success: function (xmlDoc) {
81-
vision.logined = true;
81+
getChannelList(vision).then(() => {
82+
vision.logined = true;
83+
});
8284
},
8385
error: function (oError) {
8486
const ERROR_CODE_LOGIN_REPEATLOGIN = 2001;
8587
if (oError.errorCode === ERROR_CODE_LOGIN_REPEATLOGIN) {
8688
vision.logined = true;
87-
return;
89+
return true;
8890
}
8991

9092
vision.logined = false;
@@ -103,16 +105,18 @@ export async function login(id, ip, port, userName, password, loginType) {
103105
});
104106
}
105107

106-
const getChannelInfo = vision => {
107-
const { szDeviceIdentify } = vision;
108+
const getChannelList = vision => {
109+
const { szDeviceIdentify, logined } = vision;
110+
108111
let analog_completed = false;
109112
WebVideoCtrl.I_GetAnalogChannelInfo(szDeviceIdentify, {
110113
success: function (xmlDoc) {
111114
const channels = [...getTagNameValues(xmlDoc, "VideoInputChannel")];
115+
console.log(xmlDoc);
112116
vision.analogChannels = channels.map(channel => {
113117
return {
114-
id: getTagNameFirstValue(channel, "id"),
115-
inputPort: getTagNameFirstValue(channel, "inputPort"),
118+
id: parseInt(getTagNameFirstValue(channel, "id")),
119+
inputPort: parseInt(getTagNameFirstValue(channel, "inputPort")),
116120
name: getTagNameFirstValue(channel, "name"),
117121
videoFormat: getTagNameFirstValue(channel, "videoFormat")
118122
};
@@ -130,8 +134,7 @@ const getChannelInfo = vision => {
130134
const channels = [...getTagNameValues(xmlDoc, "InputProxyChannelStatus")];
131135
vision.digitalChannels = channels.map(channel => {
132136
return {
133-
id: getTagNameFirstValue(channel, "id"),
134-
name: getTagNameFirstValue(channel, "name"),
137+
id: parseInt(getTagNameFirstValue(channel, "id")),
135138
online: getTagNameFirstValue(channel, "online")
136139
};
137140
});
@@ -187,11 +190,8 @@ export async function startRealPlay(id, iStreamType, iChannelID) {
187190
const vision = Data.get(id);
188191
const { iWndIndex, szDeviceIdentify } = vision;
189192

190-
vision.devicePort = await WebVideoCtrl.I_GetDevicePort(vision.szDeviceIdentify);
191-
await getChannelInfo(vision);
192-
193-
const oWndInfo = WebVideoCtrl.I_GetWindowStatus(iWndIndex);
194-
const iRtspPort = vision.devicePort.iRtspPort;
193+
vision.devicePort = await WebVideoCtrl.I_GetDevicePort(szDeviceIdentify);
194+
const { iRtspPort } = vision.devicePort;
195195
const bZeroChannel = false;
196196
let completed = null;
197197
const startRealPlay = function () {
@@ -212,6 +212,7 @@ export async function startRealPlay(id, iStreamType, iChannelID) {
212212
});
213213
};
214214

215+
const oWndInfo = WebVideoCtrl.I_GetWindowStatus(iWndIndex);
215216
if (oWndInfo !== null) {
216217
WebVideoCtrl.I_Stop({
217218
success: function () {

0 commit comments

Comments
 (0)