-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDefaultHicVision.cs
More file actions
71 lines (59 loc) · 1.84 KB
/
DefaultHicVision.cs
File metadata and controls
71 lines (59 loc) · 1.84 KB
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
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
namespace BootstrapBlazor.Components;
sealed class DefaultHicVision(IJSRuntime jsRuntime) : IHikVision
{
private JSModule _module = default!;
private bool _initialized;
private bool _logined;
public async Task<bool> Login(string ip, int port, string userName, string password, HikVisionLoginType loginType = HikVisionLoginType.Http)
{
await LoadAsync();
if (!_logined)
{
_logined = await _module.InvokeAsync<bool>("login", ip, port, userName, password, (int)loginType);
}
return _logined;
}
public async Task<bool> Logout(string ip, int port)
{
if (_logined)
{
_logined = await _module.InvokeAsync<bool>("logout");
}
return _logined;
}
public async Task StartRealPlay()
{
if (_logined)
{
await _module.InvokeVoidAsync("startRealPlay");
}
}
public async Task StopRealPlay()
{
if (_logined)
{
await _module.InvokeVoidAsync("stopRealPlay");
}
}
private async Task LoadAsync()
{
if (!_initialized)
{
var module = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/BootstrapBlazor.HikVision/hikvision.js");
_module = new JSModule(module);
_initialized = true;
}
}
public async ValueTask DisposeAsync()
{
if (_module != null)
{
await _module.InvokeVoidAsync("dispose");
await _module.DisposeAsync();
}
GC.SuppressFinalize(this);
}
}