Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ private async Task GetFingerCodeAsync()
}</Pre>
<BootstrapInputGroup>
<BootstrapInputGroupLabel DisplayText="Browser-Finger"></BootstrapInputGroupLabel>
<BootstrapInput @bind-Value="@_code" />
<BootstrapInput Value="@_code" Readonly="true" />
</BootstrapInputGroup>

<BootstrapInputGroup class="mt-3">
<BootstrapInputGroupLabel DisplayText="ClientHubId"></BootstrapInputGroupLabel>
<BootstrapInput Value="@_clientHubId" Readonly="true" />
</BootstrapInputGroup>
</DemoBlock>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public partial class BrowserFingers
private IBrowserFingerService? BrowserFingerService { get; set; }

private string? _code;
private string? _clientHubId;

/// <summary>
/// <inheritdoc/>
Expand All @@ -25,10 +26,13 @@ protected override async Task OnInitializedAsync()
await base.OnInitializedAsync();

_code = await GetFingerCodeAsync();
_clientHubId = await GetClientHubIdAsync();
}

private Task<string?> GetFingerCodeAsync() => BrowserFingerService.GetFingerCodeAsync();

private Task<string?> GetClientHubIdAsync() => BrowserFingerService.GetClientHubIdAsync();

private MethodItem[] GetMethods() =>
[
new()
Expand All @@ -37,6 +41,13 @@ private MethodItem[] GetMethods() =>
Description = Localizer["GetFingerCodeAsync"],
Parameters = " — ",
ReturnValue = "Task<string?>"
},
new()
{
Name = "GetClientHubIdAsync",
Description = Localizer["GetClientHubIdAsync"],
Parameters = " — ",
ReturnValue = "Task<string?>"
}
];
}
3 changes: 2 additions & 1 deletion src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -6685,7 +6685,8 @@
"BootstrapBlazor.Server.Components.Samples.BrowserFingers": {
"BrowserFingerTitle": "Browser fingerprint",
"BrowserFingerIntro": "Obtain the client browser fingerprint by calling the <code>IBrowserFingerService</code> service instance method <code>GetFingerCodeAsync</code>. The fingerprint is consistent in privacy mode",
"GetFingerCodeAsync": "Method for obtaining fingerprints"
"GetFingerCodeAsync": "Method for obtaining fingerprints",
"GetClientHubIdAsync": "Method for obtaining client hub Id"
},
"BootstrapBlazor.Server.Components.Samples.SvgEditors": {
"SvgEditorTitle": "SvgEditor",
Expand Down
3 changes: 2 additions & 1 deletion src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -6685,7 +6685,8 @@
"BootstrapBlazor.Server.Components.Samples.BrowserFingers": {
"BrowserFingerTitle": "浏览器指纹",
"BrowserFingerIntro": "通过调用 <code>IBrowserFingerService</code> 服务实例方法 <code>GetFingerCodeAsync</code> 获得客户端浏览器指纹,隐私模式下指纹是一致的",
"GetFingerCodeAsync": "获得指纹方法"
"GetFingerCodeAsync": "获得指纹方法",
"GetClientHubIdAsync": "获得客户端连接 Id 方法"
},
"BootstrapBlazor.Server.Components.Samples.SvgEditors": {
"SvgEditorTitle": "Svg 编辑器",
Expand Down
9 changes: 6 additions & 3 deletions src/BootstrapBlazor/Services/DefaultBrowserFingerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ class DefaultBrowserFingerService(IJSRuntime jSRuntime) : IBrowserFingerService
[NotNull]
private JSModule? _module = null;

/// <summary>
/// 获取剪切板数据方法
/// </summary>
public async Task<string?> GetFingerCodeAsync(CancellationToken token = default)
{
_module ??= await jSRuntime.LoadUtility();
return await _module.InvokeAsync<string?>("getFingerCode", token);
}

public async Task<string?> GetClientHubIdAsync(CancellationToken token = default)
{
_module ??= await jSRuntime.LoadUtility();
return await _module.InvokeAsync<string?>("getClientHubId", token);
}
}
7 changes: 7 additions & 0 deletions src/BootstrapBlazor/Services/IBrowserFingerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ public interface IBrowserFingerService
/// </summary>
/// <returns></returns>
Task<string?> GetFingerCodeAsync(CancellationToken token = default);

/// <summary>
/// 获得当前连接的客户端 ID 由 BootstrapBlazor 组件框架提供
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
Task<string?> GetClientHubIdAsync(CancellationToken token = default);
}
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/wwwroot/modules/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export async function getClientInfo(url) {
if (result) {
data.ip = result.Ip;
}
data.id = localStorage.getItem('bb_hub_connection_id') ?? result.Id;
data.id = localStorage.getItem('bb_hub_connection_id') || result.Id;
return data;
}
4 changes: 4 additions & 0 deletions src/BootstrapBlazor/wwwroot/modules/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,10 @@ export function getNetworkInfo() {
return null;
}

export function getClientHubId() {
return localStorage.getItem('bb_hub_connection_id');
}

export {
autoAdd,
autoRemove,
Expand Down
Loading