Skip to content

Commit e5e83f8

Browse files
authored
fix(EnableIpLocator): WebClientOptions parameter EnableIpLocator not work (#5400)
* feat: 增加 enableIpLocator 参数控制 * feat: 增加禁止调用 ip.axd 逻辑 * refactor: 增加 EnableIpLocator 参数 * chore: bump version 9.3.1-beta23
1 parent ce828de commit e5e83f8

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.3.1-beta22</Version>
4+
<Version>9.3.1-beta23</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/ConnectionHub/ConnectionHub.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ protected override async Task InvokeInitAsync()
5151
Method = nameof(Callback),
5252
ConnectionId = Guid.NewGuid(),
5353
Interval = options.BeatInterval.TotalMilliseconds,
54-
Url = "ip.axd"
54+
Url = "ip.axd",
55+
BootstrapBlazorOptions.Value.WebClientOptions.EnableIpLocator
5556
});
5657
}
5758
}

src/BootstrapBlazor/Services/WebClientService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public async Task<ClientInfo> GetClientInfo()
4444
{
4545
_jsModule ??= await runtime.LoadModuleByName("client");
4646
_interop ??= DotNetObjectReference.Create(this);
47-
await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData));
47+
await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData), new
48+
{
49+
options.CurrentValue.WebClientOptions.EnableIpLocator
50+
});
4851

4952
// 等待 SetData 方法执行完毕
5053
await _taskCompletionSource.Task.WaitAsync(TimeSpan.FromSeconds(3));

src/BootstrapBlazor/wwwroot/modules/client.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import "./browser.js"
22
import { execute } from "./ajax.js"
33

4-
export async function ping(url, invoke, method) {
5-
const data = await getClientInfo(url);
4+
export async function ping(url, invoke, method, options) {
5+
const data = await getClientInfo(url, options);
66
await invoke.invokeMethodAsync(method, data)
77
}
88

9-
export async function getClientInfo(url) {
9+
export async function getClientInfo(url, options) {
1010
const info = browser()
1111
let data = {
1212
browser: info.browser + ' ' + info.version,
@@ -17,12 +17,14 @@ export async function getClientInfo(url) {
1717
os: info.system + ' ' + info.systemVersion
1818
}
1919

20-
const result = await execute({
21-
method: 'GET',
22-
url
23-
});
24-
if (result) {
25-
data.ip = result.Ip;
20+
if (options.enableIpLocator === true) {
21+
const result = await execute({
22+
method: 'GET',
23+
url
24+
});
25+
if (result) {
26+
data.ip = result.Ip;
27+
}
2628
}
2729
data.id = localStorage.getItem('bb_hub_connection_id') ?? result.Id;
2830
return data;

src/BootstrapBlazor/wwwroot/modules/hub.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Data from "./data.js"
33
import EventHandler from "./event-handler.js";
44

55
export async function init(id, options) {
6-
const { invoke, method, interval = 3000, url, connectionId } = options;
6+
const { invoke, method, interval = 3000, url, connectionId, enableIpLocator } = options;
77
const elKey = 'bb_hub_el_id';
88
if (localStorage.getItem(elKey) === null) {
99
localStorage.setItem(elKey, id);
@@ -34,7 +34,7 @@ export async function init(id, options) {
3434
}
3535
});
3636

37-
const info = await getClientInfo(url);
37+
const info = await getClientInfo(url, { enableIpLocator: enableIpLocator });
3838
info.id = clientId;
3939

4040
const callback = async () => {

0 commit comments

Comments
 (0)