diff --git a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs index 40d87b33..abe3dd9c 100644 --- a/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs +++ b/src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs @@ -58,7 +58,31 @@ public partial class HikVisionWebPlugin /// 获得/设置 插件初始化完成后回调方法 /// [Parameter] - public Func OnInitedAsync { get; set; } + public Func? OnInitedAsync { get; set; } + + /// + /// 获得/设置 登录成功后回调方法 + /// + [Parameter] + public Func? OnLoginedAsync { get; set; } + + /// + /// 获得/设置 注销成功后回调方法 + /// + [Parameter] + public Func? OnLogoutedAsync { get; set; } + + /// + /// 获得/设置 开始预览后回调方法 + /// + [Parameter] + public Func? OnStartRealPlayedAsync { get; set; } + + /// + /// 获得/设置 停止预览后回调方法 + /// + [Parameter] + public Func? OnStopRealPlayedAsync { get; set; } private string? ClassString => CssBuilder.Default("bb-hik") .AddClassFromAttributes(AdditionalAttributes) @@ -109,9 +133,21 @@ public async Task Login(string ip, int port, string userName, string passw { ThrowIfNotInited(); IsLogined = await InvokeAsync("login", Id, ip, port, userName, password, (int)loginType) ?? false; + if (IsLogined) + { + await TriggerLogined(); + } return IsLogined; } + private async Task TriggerLogined() + { + if (OnLoginedAsync != null) + { + await OnLoginedAsync(); + } + } + /// /// 登出方法 /// @@ -122,7 +158,17 @@ public async Task Logout() { await InvokeVoidAsync("logout", Id); } + IsRealPlaying = false; IsLogined = false; + await TriggerLogouted(); + } + + private async Task TriggerLogouted() + { + if (OnLogoutedAsync != null) + { + await OnLogoutedAsync(); + } } /// @@ -134,6 +180,18 @@ public async Task StartRealPlay(int streamType, int channelId) if (IsLogined && !IsRealPlaying) { IsRealPlaying = await InvokeAsync("startRealPlay", Id, streamType, channelId) ?? false; + if (IsRealPlaying) + { + await TriggerStartRealPlay(); + } + } + } + + private async Task TriggerStartRealPlay() + { + if (OnStartRealPlayedAsync != null) + { + await OnStartRealPlayedAsync(); } } @@ -143,13 +201,19 @@ public async Task StartRealPlay(int streamType, int channelId) /// public async Task StopRealPlay() { - if (IsLogined && IsRealPlaying) + if (IsRealPlaying) { - var result = await InvokeAsync("stopRealPlay", Id) ?? false; - if (result) - { - IsRealPlaying = false; - } + await InvokeVoidAsync("stopRealPlay", Id); + IsRealPlaying = false; + await TriggerStopRealPlay(); + } + } + + private async Task TriggerStopRealPlay() + { + if (OnStopRealPlayedAsync != null) + { + await OnStopRealPlayedAsync(); } } diff --git a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js index d95263af..14f4ede9 100644 --- a/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js +++ b/src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js @@ -212,7 +212,6 @@ export async function startRealPlay(id, iStreamType, iChannelID) { }); }; - console.log(oWndInfo); if (oWndInfo !== null) { WebVideoCtrl.I_Stop({ success: function () {