@peers-app/peers-ui 0.21.2 → 0.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/screens/network-viewer/connection-troubleshooter.js +1 -1
- package/dist/screens/network-viewer/device-details-modal.js +11 -15
- package/dist/screens/network-viewer/group-details-modal.js +60 -17
- package/dist/screens/network-viewer/network-viewer-ipc.d.ts +9 -39
- package/dist/screens/network-viewer/network-viewer-ipc.js +71 -3
- package/dist/screens/network-viewer/network-viewer-ipc.test.d.ts +1 -0
- package/dist/screens/network-viewer/network-viewer-ipc.test.js +59 -0
- package/dist/screens/network-viewer/network-viewer.js +46 -60
- package/dist/screens/network-viewer/remote-logs-panel.js +11 -12
- package/dist/tabs-layout/network-status-indicator.d.ts +19 -0
- package/dist/tabs-layout/network-status-indicator.js +105 -0
- package/dist/tabs-layout/network-status-indicator.test.d.ts +1 -0
- package/dist/tabs-layout/network-status-indicator.test.js +81 -0
- package/dist/tabs-layout/tabs-layout.js +25 -24
- package/dist/tabs-layout/use-network-status.d.ts +8 -0
- package/dist/tabs-layout/use-network-status.js +57 -0
- package/dist/tabs-layout/use-network-status.test.d.ts +1 -0
- package/dist/tabs-layout/use-network-status.test.js +42 -0
- package/package.json +3 -3
- package/src/screens/network-viewer/connection-troubleshooter.tsx +2 -2
- package/src/screens/network-viewer/device-details-modal.tsx +19 -61
- package/src/screens/network-viewer/group-details-modal.tsx +211 -130
- package/src/screens/network-viewer/network-viewer-ipc.test.ts +70 -0
- package/src/screens/network-viewer/network-viewer-ipc.ts +102 -35
- package/src/screens/network-viewer/network-viewer.tsx +76 -148
- package/src/screens/network-viewer/remote-logs-panel.tsx +14 -16
- package/src/tabs-layout/network-status-indicator.test.tsx +94 -0
- package/src/tabs-layout/network-status-indicator.tsx +209 -0
- package/src/tabs-layout/tabs-layout.tsx +4 -1
- package/src/tabs-layout/use-network-status.test.tsx +55 -0
- package/src/tabs-layout/use-network-status.ts +68 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { INetworkStatusSummary } from "@peers-app/peers-sdk";
|
|
2
|
+
import { fireEvent, render } from "@testing-library/react";
|
|
3
|
+
import { NetworkStatusIndicator } from "./network-status-indicator";
|
|
4
|
+
import type { INetworkStatusViewState } from "./use-network-status";
|
|
5
|
+
|
|
6
|
+
const goToTabPath = jest.fn();
|
|
7
|
+
let mockViewState: INetworkStatusViewState = { availability: "loading" };
|
|
8
|
+
|
|
9
|
+
jest.mock("./tabs-state", () => ({
|
|
10
|
+
goToTabPath: (...args: unknown[]) => goToTabPath(...args),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
jest.mock("./use-network-status", () => ({
|
|
14
|
+
useNetworkStatus: () => mockViewState,
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
function status(overrides: Partial<INetworkStatusSummary>): INetworkStatusSummary {
|
|
18
|
+
return {
|
|
19
|
+
state: "synced",
|
|
20
|
+
connectionCount: 2,
|
|
21
|
+
syncingContextCount: 0,
|
|
22
|
+
errorCount: 0,
|
|
23
|
+
errors: [],
|
|
24
|
+
...overrides,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe("NetworkStatusIndicator", () => {
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
mockViewState = { availability: "loading" };
|
|
31
|
+
jest.clearAllMocks();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it.each([
|
|
35
|
+
[{ availability: "loading" }, /Network status loading/],
|
|
36
|
+
[{ availability: "unavailable" }, /Network status unavailable/],
|
|
37
|
+
[
|
|
38
|
+
{ availability: "ready", status: status({ state: "offline", connectionCount: 0 }) },
|
|
39
|
+
/Network offline/,
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
{
|
|
43
|
+
availability: "ready",
|
|
44
|
+
status: status({ state: "syncing", syncingContextCount: 1 }),
|
|
45
|
+
},
|
|
46
|
+
/Network syncing/,
|
|
47
|
+
],
|
|
48
|
+
[{ availability: "ready", status: status({ state: "synced" }) }, /Network synced/],
|
|
49
|
+
[
|
|
50
|
+
{
|
|
51
|
+
availability: "ready",
|
|
52
|
+
status: status({
|
|
53
|
+
state: "error",
|
|
54
|
+
errorCount: 1,
|
|
55
|
+
errors: [{ dataContextId: "context", message: "failed", occurredAt: 1 }],
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
/Network error/,
|
|
59
|
+
],
|
|
60
|
+
] satisfies Array<
|
|
61
|
+
[INetworkStatusViewState, RegExp]
|
|
62
|
+
>)("renders an accessible state for %#", (viewState, accessibleName) => {
|
|
63
|
+
mockViewState = viewState;
|
|
64
|
+
const view = render(<NetworkStatusIndicator />);
|
|
65
|
+
expect(view.getByRole("button", { name: accessibleName })).toBeTruthy();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("updates on rerender and opens details before navigating to Network Viewer", () => {
|
|
69
|
+
const view = render(<NetworkStatusIndicator />);
|
|
70
|
+
expect(view.getByRole("button", { name: /loading/ })).toBeTruthy();
|
|
71
|
+
|
|
72
|
+
mockViewState = {
|
|
73
|
+
availability: "ready",
|
|
74
|
+
status: status({
|
|
75
|
+
state: "error",
|
|
76
|
+
connectionCount: 3,
|
|
77
|
+
errorCount: 1,
|
|
78
|
+
errors: [{ dataContextId: "context", message: "sync failed", occurredAt: 1 }],
|
|
79
|
+
}),
|
|
80
|
+
};
|
|
81
|
+
view.rerender(<NetworkStatusIndicator />);
|
|
82
|
+
fireEvent.click(view.getByRole("button", { name: /Network error/ }));
|
|
83
|
+
|
|
84
|
+
expect(view.getByRole("dialog", { name: "Network status details" })).toHaveTextContent(
|
|
85
|
+
"sync failed",
|
|
86
|
+
);
|
|
87
|
+
fireEvent.keyDown(document, { key: "Escape" });
|
|
88
|
+
expect(view.queryByRole("dialog", { name: "Network status details" })).toBeNull();
|
|
89
|
+
|
|
90
|
+
fireEvent.click(view.getByRole("button", { name: /Network error/ }));
|
|
91
|
+
fireEvent.click(view.getByRole("button", { name: "Open Network Viewer" }));
|
|
92
|
+
expect(goToTabPath).toHaveBeenCalledWith("network-viewer");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { INetworkStatusSummary } from "@peers-app/peers-sdk";
|
|
2
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { goToTabPath } from "./tabs-state";
|
|
4
|
+
import { type INetworkStatusViewState, useNetworkStatus } from "./use-network-status";
|
|
5
|
+
|
|
6
|
+
interface INetworkStatusPresentation {
|
|
7
|
+
label: string;
|
|
8
|
+
shortLabel: string;
|
|
9
|
+
iconClass: string;
|
|
10
|
+
colorClass: string;
|
|
11
|
+
spinning?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Convert host availability and network state into accessible indicator text and styling. */
|
|
15
|
+
export function getNetworkStatusPresentation(
|
|
16
|
+
viewState: INetworkStatusViewState,
|
|
17
|
+
): INetworkStatusPresentation {
|
|
18
|
+
if (viewState.availability === "loading") {
|
|
19
|
+
return {
|
|
20
|
+
label: "Network status loading",
|
|
21
|
+
shortLabel: "Loading",
|
|
22
|
+
iconClass: "bi-arrow-repeat",
|
|
23
|
+
colorClass: "text-secondary",
|
|
24
|
+
spinning: true,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (viewState.availability === "unavailable" || !viewState.status) {
|
|
28
|
+
return {
|
|
29
|
+
label: "Network status unavailable",
|
|
30
|
+
shortLabel: "Unavailable",
|
|
31
|
+
iconClass: "bi-question-circle",
|
|
32
|
+
colorClass: "text-secondary",
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const { connectionCount, errorCount, state, syncingContextCount } = viewState.status;
|
|
36
|
+
if (state === "error") {
|
|
37
|
+
return {
|
|
38
|
+
label: `Network error; ${errorCount} sync ${errorCount === 1 ? "error" : "errors"}; ${connectionCount} active ${connectionCount === 1 ? "connection" : "connections"}`,
|
|
39
|
+
shortLabel: "Error",
|
|
40
|
+
iconClass: "bi-exclamation-triangle-fill",
|
|
41
|
+
colorClass: "text-danger",
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (state === "syncing") {
|
|
45
|
+
return {
|
|
46
|
+
label: `Network syncing ${syncingContextCount} ${syncingContextCount === 1 ? "context" : "contexts"}; ${connectionCount} active ${connectionCount === 1 ? "connection" : "connections"}`,
|
|
47
|
+
shortLabel: "Syncing",
|
|
48
|
+
iconClass: "bi-arrow-repeat",
|
|
49
|
+
colorClass: "text-primary",
|
|
50
|
+
spinning: true,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (state === "offline") {
|
|
54
|
+
return {
|
|
55
|
+
label: "Network offline; no active connections",
|
|
56
|
+
shortLabel: "Offline",
|
|
57
|
+
iconClass: "bi-cloud-slash-fill",
|
|
58
|
+
colorClass: "text-secondary",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
label: `Network synced; ${connectionCount} active ${connectionCount === 1 ? "connection" : "connections"}`,
|
|
63
|
+
shortLabel: "Synced",
|
|
64
|
+
iconClass: "bi-check-circle-fill",
|
|
65
|
+
colorClass: "text-success",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function NetworkStatusDetails({
|
|
70
|
+
detailsId,
|
|
71
|
+
status,
|
|
72
|
+
unavailable,
|
|
73
|
+
onOpenViewer,
|
|
74
|
+
}: {
|
|
75
|
+
detailsId: string;
|
|
76
|
+
status?: INetworkStatusSummary;
|
|
77
|
+
unavailable: boolean;
|
|
78
|
+
onOpenViewer: () => void;
|
|
79
|
+
}) {
|
|
80
|
+
return (
|
|
81
|
+
<div
|
|
82
|
+
id={detailsId}
|
|
83
|
+
role="dialog"
|
|
84
|
+
aria-label="Network status details"
|
|
85
|
+
className="card shadow position-absolute end-0 mt-1"
|
|
86
|
+
style={{ top: "100%", width: "280px", zIndex: 1100 }}
|
|
87
|
+
>
|
|
88
|
+
<div className="card-body p-3">
|
|
89
|
+
<h6 className="card-title mb-2">Network status</h6>
|
|
90
|
+
{unavailable || !status ? (
|
|
91
|
+
<p className="small text-muted mb-3">
|
|
92
|
+
Network diagnostics are temporarily unavailable. The local host may still be starting or
|
|
93
|
+
reconnecting.
|
|
94
|
+
</p>
|
|
95
|
+
) : (
|
|
96
|
+
<>
|
|
97
|
+
<dl className="row small mb-2">
|
|
98
|
+
<dt className="col-7">Connections</dt>
|
|
99
|
+
<dd className="col-5 text-end">{status.connectionCount}</dd>
|
|
100
|
+
<dt className="col-7">Syncing contexts</dt>
|
|
101
|
+
<dd className="col-5 text-end">{status.syncingContextCount}</dd>
|
|
102
|
+
<dt className="col-7">Sync errors</dt>
|
|
103
|
+
<dd className="col-5 text-end">{status.errorCount}</dd>
|
|
104
|
+
</dl>
|
|
105
|
+
{status.lastSuccessfulSyncAt && (
|
|
106
|
+
<p className="small text-muted mb-2">
|
|
107
|
+
Last successful sync: {new Date(status.lastSuccessfulSyncAt).toLocaleString()}
|
|
108
|
+
</p>
|
|
109
|
+
)}
|
|
110
|
+
{status.errors.length > 0 && (
|
|
111
|
+
<div className="alert alert-danger py-2 px-2 small mb-2">
|
|
112
|
+
{status.errors[0].message}
|
|
113
|
+
{status.errors.length > 1 && ` (+${status.errors.length - 1} more)`}
|
|
114
|
+
</div>
|
|
115
|
+
)}
|
|
116
|
+
</>
|
|
117
|
+
)}
|
|
118
|
+
<button type="button" className="btn btn-sm btn-primary w-100" onClick={onOpenViewer}>
|
|
119
|
+
Open Network Viewer
|
|
120
|
+
</button>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Accessible reactive network status button and details popover. */
|
|
127
|
+
export function NetworkStatusIndicator({ compact = false }: { compact?: boolean }) {
|
|
128
|
+
const viewState = useNetworkStatus();
|
|
129
|
+
const presentation = getNetworkStatusPresentation(viewState);
|
|
130
|
+
const [open, setOpen] = useState(false);
|
|
131
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
132
|
+
const detailsId = useId();
|
|
133
|
+
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (!open) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const closeOutside = (event: MouseEvent) => {
|
|
139
|
+
if (!containerRef.current?.contains(event.target as Node)) {
|
|
140
|
+
setOpen(false);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const closeOnEscape = (event: KeyboardEvent) => {
|
|
144
|
+
if (event.key === "Escape") {
|
|
145
|
+
setOpen(false);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
document.addEventListener("mousedown", closeOutside);
|
|
149
|
+
document.addEventListener("keydown", closeOnEscape);
|
|
150
|
+
return () => {
|
|
151
|
+
document.removeEventListener("mousedown", closeOutside);
|
|
152
|
+
document.removeEventListener("keydown", closeOnEscape);
|
|
153
|
+
};
|
|
154
|
+
}, [open]);
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<div ref={containerRef} className="position-relative d-flex align-items-center">
|
|
158
|
+
<button
|
|
159
|
+
type="button"
|
|
160
|
+
className={`btn btn-sm d-flex align-items-center gap-1 px-2 ${presentation.colorClass}`}
|
|
161
|
+
style={{
|
|
162
|
+
border: "none",
|
|
163
|
+
background: "transparent",
|
|
164
|
+
minWidth: compact ? "30px" : undefined,
|
|
165
|
+
}}
|
|
166
|
+
aria-label={presentation.label}
|
|
167
|
+
aria-expanded={open}
|
|
168
|
+
aria-controls={detailsId}
|
|
169
|
+
title={presentation.label}
|
|
170
|
+
onClick={() => setOpen((current) => !current)}
|
|
171
|
+
>
|
|
172
|
+
<i
|
|
173
|
+
className={`bi ${presentation.iconClass} ${presentation.spinning ? "spin" : ""}`}
|
|
174
|
+
aria-hidden="true"
|
|
175
|
+
/>
|
|
176
|
+
{!compact && (
|
|
177
|
+
<span className="small">
|
|
178
|
+
{viewState.status?.connectionCount ?? 0}
|
|
179
|
+
<span className="visually-hidden"> connections</span>
|
|
180
|
+
</span>
|
|
181
|
+
)}
|
|
182
|
+
</button>
|
|
183
|
+
{open && (
|
|
184
|
+
<NetworkStatusDetails
|
|
185
|
+
detailsId={detailsId}
|
|
186
|
+
status={viewState.status}
|
|
187
|
+
unavailable={viewState.availability !== "ready"}
|
|
188
|
+
onOpenViewer={() => {
|
|
189
|
+
setOpen(false);
|
|
190
|
+
goToTabPath("network-viewer");
|
|
191
|
+
}}
|
|
192
|
+
/>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Fixed tabs-strip area for built-in shell indicators. */
|
|
199
|
+
export function TabsStripIndicators({ compact = false }: { compact?: boolean }) {
|
|
200
|
+
return (
|
|
201
|
+
<div
|
|
202
|
+
className="d-flex align-items-center flex-shrink-0"
|
|
203
|
+
role="group"
|
|
204
|
+
aria-label="Application status"
|
|
205
|
+
>
|
|
206
|
+
<NetworkStatusIndicator compact={compact} />
|
|
207
|
+
</div>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
@@ -14,6 +14,7 @@ import { colorMode } from "../screens/settings/color-mode-dropdown";
|
|
|
14
14
|
import { systemPackage } from "../system-apps";
|
|
15
15
|
import { allPackages } from "../ui-router/routes-loader";
|
|
16
16
|
import { UIRouter } from "../ui-router/ui-loader";
|
|
17
|
+
import { TabsStripIndicators } from "./network-status-indicator";
|
|
17
18
|
import {
|
|
18
19
|
activeTabId,
|
|
19
20
|
activeTabs,
|
|
@@ -246,6 +247,7 @@ export function TabsLayoutInternal({ fillContainer = false }: { fillContainer?:
|
|
|
246
247
|
/>
|
|
247
248
|
))}
|
|
248
249
|
</div>
|
|
250
|
+
<TabsStripIndicators />
|
|
249
251
|
</div>
|
|
250
252
|
)}
|
|
251
253
|
</div>
|
|
@@ -314,7 +316,8 @@ function MobileTabsHeader({
|
|
|
314
316
|
</div>
|
|
315
317
|
|
|
316
318
|
{/* Right Side - Hamburger Menu */}
|
|
317
|
-
<div className="d-flex align-items-center">
|
|
319
|
+
<div className="d-flex align-items-center gap-1">
|
|
320
|
+
<TabsStripIndicators compact />
|
|
318
321
|
<div className="dropdown">
|
|
319
322
|
<button
|
|
320
323
|
type="button"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type INetworkDiagnosticsConsumer,
|
|
3
|
+
type INetworkStatusSummary,
|
|
4
|
+
inProcessTransportPair,
|
|
5
|
+
observable,
|
|
6
|
+
registerHostContractTransport,
|
|
7
|
+
} from "@peers-app/peers-sdk";
|
|
8
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
9
|
+
import { getNetworkDiagnosticsConsumer } from "../screens/network-viewer/network-viewer-ipc";
|
|
10
|
+
import { useNetworkStatus } from "./use-network-status";
|
|
11
|
+
|
|
12
|
+
jest.mock("../screens/network-viewer/network-viewer-ipc", () => ({
|
|
13
|
+
getNetworkDiagnosticsConsumer: jest.fn(),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
const mockGetDiagnostics = getNetworkDiagnosticsConsumer as jest.MockedFunction<
|
|
17
|
+
typeof getNetworkDiagnosticsConsumer
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
function makeStatus(overrides: Partial<INetworkStatusSummary> = {}): INetworkStatusSummary {
|
|
21
|
+
return {
|
|
22
|
+
state: "offline",
|
|
23
|
+
connectionCount: 0,
|
|
24
|
+
syncingContextCount: 0,
|
|
25
|
+
errorCount: 0,
|
|
26
|
+
errors: [],
|
|
27
|
+
...overrides,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("useNetworkStatus", () => {
|
|
32
|
+
it("streams status updates and reports host disconnection", async () => {
|
|
33
|
+
const status = observable(makeStatus());
|
|
34
|
+
mockGetDiagnostics.mockResolvedValue({
|
|
35
|
+
observables: { status },
|
|
36
|
+
} as INetworkDiagnosticsConsumer);
|
|
37
|
+
const [transport] = inProcessTransportPair();
|
|
38
|
+
const disposeTransport = registerHostContractTransport(transport);
|
|
39
|
+
const hook = renderHook(() => useNetworkStatus());
|
|
40
|
+
|
|
41
|
+
await waitFor(() => expect(hook.result.current.availability).toBe("ready"));
|
|
42
|
+
expect(hook.result.current.status?.state).toBe("offline");
|
|
43
|
+
|
|
44
|
+
act(() => {
|
|
45
|
+
status(makeStatus({ state: "syncing", connectionCount: 2, syncingContextCount: 1 }));
|
|
46
|
+
});
|
|
47
|
+
await waitFor(() => expect(hook.result.current.status?.state).toBe("syncing"));
|
|
48
|
+
|
|
49
|
+
act(() => {
|
|
50
|
+
disposeTransport();
|
|
51
|
+
});
|
|
52
|
+
await waitFor(() => expect(hook.result.current.availability).toBe("unavailable"));
|
|
53
|
+
hook.unmount();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type INetworkStatusSummary,
|
|
3
|
+
type Subscription,
|
|
4
|
+
subscribeHostContractTransport,
|
|
5
|
+
} from "@peers-app/peers-sdk";
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import { getNetworkDiagnosticsConsumer } from "../screens/network-viewer/network-viewer-ipc";
|
|
8
|
+
|
|
9
|
+
/** Host availability plus the latest reactive network status snapshot. */
|
|
10
|
+
export interface INetworkStatusViewState {
|
|
11
|
+
availability: "loading" | "ready" | "unavailable";
|
|
12
|
+
status?: INetworkStatusSummary;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Subscribe to the current host's System Network Diagnostics status observable. */
|
|
16
|
+
export function useNetworkStatus(): INetworkStatusViewState {
|
|
17
|
+
const [viewState, setViewState] = useState<INetworkStatusViewState>({
|
|
18
|
+
availability: "loading",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
let active = true;
|
|
23
|
+
let generation = 0;
|
|
24
|
+
let statusSubscription: Subscription | undefined;
|
|
25
|
+
let hadTransport = false;
|
|
26
|
+
const unsubscribeTransport = subscribeHostContractTransport((transport) => {
|
|
27
|
+
generation += 1;
|
|
28
|
+
const currentGeneration = generation;
|
|
29
|
+
statusSubscription?.dispose();
|
|
30
|
+
statusSubscription = undefined;
|
|
31
|
+
if (!transport) {
|
|
32
|
+
setViewState({ availability: hadTransport ? "unavailable" : "loading" });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
hadTransport = true;
|
|
36
|
+
setViewState({ availability: "loading" });
|
|
37
|
+
void getNetworkDiagnosticsConsumer()
|
|
38
|
+
.then((diagnostics) => {
|
|
39
|
+
if (!active || generation !== currentGeneration) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
setViewState({
|
|
43
|
+
availability: "ready",
|
|
44
|
+
status: diagnostics.observables.status(),
|
|
45
|
+
});
|
|
46
|
+
statusSubscription = diagnostics.observables.status.subscribe((status) => {
|
|
47
|
+
if (active && generation === currentGeneration) {
|
|
48
|
+
setViewState({ availability: "ready", status });
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
})
|
|
52
|
+
.catch(() => {
|
|
53
|
+
if (active && generation === currentGeneration) {
|
|
54
|
+
setViewState({ availability: "unavailable" });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
active = false;
|
|
61
|
+
generation += 1;
|
|
62
|
+
statusSubscription?.dispose();
|
|
63
|
+
unsubscribeTransport();
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
return viewState;
|
|
68
|
+
}
|