Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.3.1-beta22</Version>
<Version>9.3.1-beta23</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ protected override async Task InvokeInitAsync()
Method = nameof(Callback),
ConnectionId = Guid.NewGuid(),
Interval = options.BeatInterval.TotalMilliseconds,
Url = "ip.axd"
Url = "ip.axd",
BootstrapBlazorOptions.Value.WebClientOptions.EnableIpLocator
});
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/BootstrapBlazor/Services/WebClientService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public async Task<ClientInfo> GetClientInfo()
{
_jsModule ??= await runtime.LoadModuleByName("client");
_interop ??= DotNetObjectReference.Create(this);
await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData));
await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData), new
{
options.CurrentValue.WebClientOptions.EnableIpLocator
});

// 等待 SetData 方法执行完毕
await _taskCompletionSource.Task.WaitAsync(TimeSpan.FromSeconds(3));
Expand Down
20 changes: 11 additions & 9 deletions src/BootstrapBlazor/wwwroot/modules/client.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import "./browser.js"
import { execute } from "./ajax.js"

export async function ping(url, invoke, method) {
const data = await getClientInfo(url);
export async function ping(url, invoke, method, options) {
const data = await getClientInfo(url, options);
await invoke.invokeMethodAsync(method, data)
}

export async function getClientInfo(url) {
export async function getClientInfo(url, options) {
const info = browser()
let data = {
browser: info.browser + ' ' + info.version,
Expand All @@ -17,12 +17,14 @@ export async function getClientInfo(url) {
os: info.system + ' ' + info.systemVersion
}

const result = await execute({
method: 'GET',
url
});
if (result) {
data.ip = result.Ip;
if (options.enableIpLocator === true) {
const result = await execute({
method: 'GET',
url
});
if (result) {
data.ip = result.Ip;
}
}
data.id = localStorage.getItem('bb_hub_connection_id') ?? result.Id;
return data;
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/wwwroot/modules/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Data from "./data.js"
import EventHandler from "./event-handler.js";

export async function init(id, options) {
const { invoke, method, interval = 3000, url, connectionId } = options;
const { invoke, method, interval = 3000, url, connectionId, enableIpLocator } = options;
const elKey = 'bb_hub_el_id';
if (localStorage.getItem(elKey) === null) {
localStorage.setItem(elKey, id);
Expand Down Expand Up @@ -34,7 +34,7 @@ export async function init(id, options) {
}
});

const info = await getClientInfo(url);
const info = await getClientInfo(url, { enableIpLocator: enableIpLocator });
info.id = clientId;

const callback = async () => {
Expand Down