@metamask-previews/connectivity-controller 0.0.0-preview-9e00b40b → 0.0.0-preview-85ecacba
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/ConnectivityController.cjs +8 -16
- package/dist/ConnectivityController.cjs.map +1 -1
- package/dist/ConnectivityController.d.cts +8 -26
- package/dist/ConnectivityController.d.cts.map +1 -1
- package/dist/ConnectivityController.d.mts +8 -26
- package/dist/ConnectivityController.d.mts.map +1 -1
- package/dist/ConnectivityController.mjs +9 -17
- package/dist/ConnectivityController.mjs.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +2 -2
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +5 -11
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +5 -11
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -30,7 +30,7 @@ const connectivityControllerMetadata = {
|
|
|
30
30
|
*/
|
|
31
31
|
function getDefaultConnectivityControllerState() {
|
|
32
32
|
return {
|
|
33
|
-
connectivityStatus: types_1.
|
|
33
|
+
connectivityStatus: types_1.CONNECTIVITY_STATUSES.Online,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
exports.getDefaultConnectivityControllerState = getDefaultConnectivityControllerState;
|
|
@@ -38,20 +38,12 @@ exports.getDefaultConnectivityControllerState = getDefaultConnectivityController
|
|
|
38
38
|
* ConnectivityController stores the device's internet connectivity status.
|
|
39
39
|
*
|
|
40
40
|
* This controller is platform-agnostic and designed to be used across different
|
|
41
|
-
* MetaMask clients (extension, mobile). It requires a `
|
|
41
|
+
* MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to
|
|
42
42
|
* be injected, which provides platform-specific connectivity detection.
|
|
43
43
|
*
|
|
44
|
-
* The controller subscribes to the
|
|
44
|
+
* The controller subscribes to the adapter's `onConnectivityChange` callback
|
|
45
45
|
* and updates its state accordingly. All connectivity updates flow through
|
|
46
|
-
* the
|
|
47
|
-
*
|
|
48
|
-
* **Platform implementations:**
|
|
49
|
-
*
|
|
50
|
-
* - **Mobile:** Inject `NetInfoConnectivityService` using `@react-native-community/netinfo`
|
|
51
|
-
* - **Extension:** Inject `PassiveConnectivityService` in the background.
|
|
52
|
-
* Status is updated via the `setDeviceConnectivityStatus` API, which is called from:
|
|
53
|
-
* - MV3: Offscreen document (where browser events work reliably)
|
|
54
|
-
* - MV2: Background page (where browser events work directly)
|
|
46
|
+
* the adapter, ensuring a single source of truth.
|
|
55
47
|
*
|
|
56
48
|
* This controller provides a centralized state for connectivity status,
|
|
57
49
|
* enabling the UI and other controllers to adapt when the user goes offline.
|
|
@@ -62,10 +54,10 @@ class ConnectivityController extends base_controller_1.BaseController {
|
|
|
62
54
|
*
|
|
63
55
|
* @param args - The arguments to this controller.
|
|
64
56
|
* @param args.messenger - The messenger suited for this controller.
|
|
65
|
-
* @param args.
|
|
57
|
+
* @param args.connectivityAdapter - The connectivity adapter to use.
|
|
66
58
|
*/
|
|
67
|
-
constructor({ messenger,
|
|
68
|
-
const initialStatus =
|
|
59
|
+
constructor({ messenger, connectivityAdapter, }) {
|
|
60
|
+
const initialStatus = connectivityAdapter.getStatus();
|
|
69
61
|
super({
|
|
70
62
|
messenger,
|
|
71
63
|
metadata: connectivityControllerMetadata,
|
|
@@ -75,7 +67,7 @@ class ConnectivityController extends base_controller_1.BaseController {
|
|
|
75
67
|
connectivityStatus: initialStatus,
|
|
76
68
|
},
|
|
77
69
|
});
|
|
78
|
-
|
|
70
|
+
connectivityAdapter.onConnectivityChange((status) => {
|
|
79
71
|
this.update((draftState) => {
|
|
80
72
|
draftState.connectivityStatus = status;
|
|
81
73
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectivityController.cjs","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":";;;AAKA,+DAA2D;AAG3D,
|
|
1
|
+
{"version":3,"file":"ConnectivityController.cjs","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":";;;AAKA,+DAA2D;AAG3D,uCAAgD;AAGhD;;;;GAIG;AACU,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAavD;;GAEG;AACH,MAAM,8BAA8B,GAAG;IACrC,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;CACmD,CAAC;AAEvD;;;;;;;GAOG;AACH,SAAgB,qCAAqC;IACnD,OAAO;QACL,kBAAkB,EAAE,6BAAqB,CAAC,MAAM;KACjD,CAAC;AACJ,CAAC;AAJD,sFAIC;AAkED;;;;;;;;;;;;;GAaG;AACH,MAAa,sBAAuB,SAAQ,gCAI3C;IACC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,mBAAmB,GACW;QAC9B,MAAM,aAAa,GAAG,mBAAmB,CAAC,SAAS,EAAE,CAAC;QAEtD,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,8BAA8B;YACxC,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE;gBACL,GAAG,qCAAqC,EAAE;gBAC1C,kBAAkB,EAAE,aAAa;aAClC;SACF,CAAC,CAAC;QAEH,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE;YAClD,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;gBACzB,UAAU,CAAC,kBAAkB,GAAG,MAAM,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAlCD,wDAkCC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport { CONNECTIVITY_STATUSES } from './types';\nimport type { ConnectivityAdapter, ConnectivityStatus } from './types';\n\n/**\n * The name of the {@link ConnectivityController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'ConnectivityController';\n\n/**\n * State for the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerState = {\n /**\n * The current device connectivity status.\n * Named with 'connectivity' prefix to avoid conflicts when state is flattened in Redux.\n */\n connectivityStatus: ConnectivityStatus;\n};\n\n/**\n * The metadata for each property in {@link ConnectivityControllerState}.\n */\nconst connectivityControllerMetadata = {\n connectivityStatus: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<ConnectivityControllerState>;\n\n/**\n * Constructs the default {@link ConnectivityController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link ConnectivityController} state.\n */\nexport function getDefaultConnectivityControllerState(): ConnectivityControllerState {\n return {\n connectivityStatus: CONNECTIVITY_STATUSES.Online,\n };\n}\n\n/**\n * Retrieves the state of the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Actions that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerActions =\n ConnectivityControllerGetStateAction;\n\n/**\n * Actions from other messengers that {@link ConnectivityControllerMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when the state of {@link ConnectivityController} changes.\n */\nexport type ConnectivityControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Events that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerEvents =\n ConnectivityControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ConnectivityControllerMessenger} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ConnectivityController}.\n */\nexport type ConnectivityControllerMessenger = Messenger<\n typeof controllerName,\n ConnectivityControllerActions | AllowedActions,\n ConnectivityControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for constructing the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerOptions = {\n /**\n * The messenger for inter-controller communication.\n */\n messenger: ConnectivityControllerMessenger;\n\n /**\n * Connectivity adapter for platform-specific detection.\n */\n connectivityAdapter: ConnectivityAdapter;\n};\n\n/**\n * ConnectivityController stores the device's internet connectivity status.\n *\n * This controller is platform-agnostic and designed to be used across different\n * MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to\n * be injected, which provides platform-specific connectivity detection.\n *\n * The controller subscribes to the adapter's `onConnectivityChange` callback\n * and updates its state accordingly. All connectivity updates flow through\n * the adapter, ensuring a single source of truth.\n *\n * This controller provides a centralized state for connectivity status,\n * enabling the UI and other controllers to adapt when the user goes offline.\n */\nexport class ConnectivityController extends BaseController<\n typeof controllerName,\n ConnectivityControllerState,\n ConnectivityControllerMessenger\n> {\n /**\n * Constructs a new {@link ConnectivityController}.\n *\n * @param args - The arguments to this controller.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.connectivityAdapter - The connectivity adapter to use.\n */\n constructor({\n messenger,\n connectivityAdapter,\n }: ConnectivityControllerOptions) {\n const initialStatus = connectivityAdapter.getStatus();\n\n super({\n messenger,\n metadata: connectivityControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultConnectivityControllerState(),\n connectivityStatus: initialStatus,\n },\n });\n\n connectivityAdapter.onConnectivityChange((status) => {\n this.update((draftState) => {\n draftState.connectivityStatus = status;\n });\n });\n }\n}\n"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
|
-
import { ConnectivityStatus } from "./types.cjs";
|
|
5
|
-
import type { ConnectivityService } from "./types.cjs";
|
|
4
|
+
import type { ConnectivityAdapter, ConnectivityStatus } from "./types.cjs";
|
|
6
5
|
/**
|
|
7
6
|
* The name of the {@link ConnectivityController}, used to namespace the
|
|
8
7
|
* controller's actions and events and to namespace the controller's state data
|
|
@@ -67,37 +66,20 @@ export type ConnectivityControllerOptions = {
|
|
|
67
66
|
*/
|
|
68
67
|
messenger: ConnectivityControllerMessenger;
|
|
69
68
|
/**
|
|
70
|
-
* Connectivity
|
|
71
|
-
*
|
|
72
|
-
* The controller subscribes to the service's `onConnectivityChange`
|
|
73
|
-
* callback to receive connectivity updates.
|
|
74
|
-
*
|
|
75
|
-
* Platform implementations:
|
|
76
|
-
* - Mobile: Use `NetInfoConnectivityService` with `@react-native-community/netinfo`
|
|
77
|
-
* - Extension (same context): Use `BrowserConnectivityService`
|
|
78
|
-
* - Extension (cross-context): Use `PassiveConnectivityService` and call
|
|
79
|
-
* `setStatus()` from the UI context
|
|
69
|
+
* Connectivity adapter for platform-specific detection.
|
|
80
70
|
*/
|
|
81
|
-
|
|
71
|
+
connectivityAdapter: ConnectivityAdapter;
|
|
82
72
|
};
|
|
83
73
|
/**
|
|
84
74
|
* ConnectivityController stores the device's internet connectivity status.
|
|
85
75
|
*
|
|
86
76
|
* This controller is platform-agnostic and designed to be used across different
|
|
87
|
-
* MetaMask clients (extension, mobile). It requires a `
|
|
77
|
+
* MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to
|
|
88
78
|
* be injected, which provides platform-specific connectivity detection.
|
|
89
79
|
*
|
|
90
|
-
* The controller subscribes to the
|
|
80
|
+
* The controller subscribes to the adapter's `onConnectivityChange` callback
|
|
91
81
|
* and updates its state accordingly. All connectivity updates flow through
|
|
92
|
-
* the
|
|
93
|
-
*
|
|
94
|
-
* **Platform implementations:**
|
|
95
|
-
*
|
|
96
|
-
* - **Mobile:** Inject `NetInfoConnectivityService` using `@react-native-community/netinfo`
|
|
97
|
-
* - **Extension:** Inject `PassiveConnectivityService` in the background.
|
|
98
|
-
* Status is updated via the `setDeviceConnectivityStatus` API, which is called from:
|
|
99
|
-
* - MV3: Offscreen document (where browser events work reliably)
|
|
100
|
-
* - MV2: Background page (where browser events work directly)
|
|
82
|
+
* the adapter, ensuring a single source of truth.
|
|
101
83
|
*
|
|
102
84
|
* This controller provides a centralized state for connectivity status,
|
|
103
85
|
* enabling the UI and other controllers to adapt when the user goes offline.
|
|
@@ -108,9 +90,9 @@ export declare class ConnectivityController extends BaseController<typeof contro
|
|
|
108
90
|
*
|
|
109
91
|
* @param args - The arguments to this controller.
|
|
110
92
|
* @param args.messenger - The messenger suited for this controller.
|
|
111
|
-
* @param args.
|
|
93
|
+
* @param args.connectivityAdapter - The connectivity adapter to use.
|
|
112
94
|
*/
|
|
113
|
-
constructor({ messenger,
|
|
95
|
+
constructor({ messenger, connectivityAdapter, }: ConnectivityControllerOptions);
|
|
114
96
|
}
|
|
115
97
|
export {};
|
|
116
98
|
//# sourceMappingURL=ConnectivityController.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectivityController.d.cts","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;
|
|
1
|
+
{"version":3,"file":"ConnectivityController.d.cts","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AAEvE;;;;GAIG;AACH,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;;OAGG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC;AAcF;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,IAAI,2BAA2B,CAInF;AAED;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACvC,oCAAoC,CAAC;AAEvC;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG,0BAA0B,CAC7E,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACtC,sCAAsC,CAAC;AAEzC;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,cAAc,EACrB,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;OAEG;IACH,SAAS,EAAE,+BAA+B,CAAC;IAE3C;;OAEG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,qBAAa,sBAAuB,SAAQ,cAAc,CACxD,OAAO,cAAc,EACrB,2BAA2B,EAC3B,+BAA+B,CAChC;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE,6BAA6B;CAmBjC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
|
-
import { ConnectivityStatus } from "./types.mjs";
|
|
5
|
-
import type { ConnectivityService } from "./types.mjs";
|
|
4
|
+
import type { ConnectivityAdapter, ConnectivityStatus } from "./types.mjs";
|
|
6
5
|
/**
|
|
7
6
|
* The name of the {@link ConnectivityController}, used to namespace the
|
|
8
7
|
* controller's actions and events and to namespace the controller's state data
|
|
@@ -67,37 +66,20 @@ export type ConnectivityControllerOptions = {
|
|
|
67
66
|
*/
|
|
68
67
|
messenger: ConnectivityControllerMessenger;
|
|
69
68
|
/**
|
|
70
|
-
* Connectivity
|
|
71
|
-
*
|
|
72
|
-
* The controller subscribes to the service's `onConnectivityChange`
|
|
73
|
-
* callback to receive connectivity updates.
|
|
74
|
-
*
|
|
75
|
-
* Platform implementations:
|
|
76
|
-
* - Mobile: Use `NetInfoConnectivityService` with `@react-native-community/netinfo`
|
|
77
|
-
* - Extension (same context): Use `BrowserConnectivityService`
|
|
78
|
-
* - Extension (cross-context): Use `PassiveConnectivityService` and call
|
|
79
|
-
* `setStatus()` from the UI context
|
|
69
|
+
* Connectivity adapter for platform-specific detection.
|
|
80
70
|
*/
|
|
81
|
-
|
|
71
|
+
connectivityAdapter: ConnectivityAdapter;
|
|
82
72
|
};
|
|
83
73
|
/**
|
|
84
74
|
* ConnectivityController stores the device's internet connectivity status.
|
|
85
75
|
*
|
|
86
76
|
* This controller is platform-agnostic and designed to be used across different
|
|
87
|
-
* MetaMask clients (extension, mobile). It requires a `
|
|
77
|
+
* MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to
|
|
88
78
|
* be injected, which provides platform-specific connectivity detection.
|
|
89
79
|
*
|
|
90
|
-
* The controller subscribes to the
|
|
80
|
+
* The controller subscribes to the adapter's `onConnectivityChange` callback
|
|
91
81
|
* and updates its state accordingly. All connectivity updates flow through
|
|
92
|
-
* the
|
|
93
|
-
*
|
|
94
|
-
* **Platform implementations:**
|
|
95
|
-
*
|
|
96
|
-
* - **Mobile:** Inject `NetInfoConnectivityService` using `@react-native-community/netinfo`
|
|
97
|
-
* - **Extension:** Inject `PassiveConnectivityService` in the background.
|
|
98
|
-
* Status is updated via the `setDeviceConnectivityStatus` API, which is called from:
|
|
99
|
-
* - MV3: Offscreen document (where browser events work reliably)
|
|
100
|
-
* - MV2: Background page (where browser events work directly)
|
|
82
|
+
* the adapter, ensuring a single source of truth.
|
|
101
83
|
*
|
|
102
84
|
* This controller provides a centralized state for connectivity status,
|
|
103
85
|
* enabling the UI and other controllers to adapt when the user goes offline.
|
|
@@ -108,9 +90,9 @@ export declare class ConnectivityController extends BaseController<typeof contro
|
|
|
108
90
|
*
|
|
109
91
|
* @param args - The arguments to this controller.
|
|
110
92
|
* @param args.messenger - The messenger suited for this controller.
|
|
111
|
-
* @param args.
|
|
93
|
+
* @param args.connectivityAdapter - The connectivity adapter to use.
|
|
112
94
|
*/
|
|
113
|
-
constructor({ messenger,
|
|
95
|
+
constructor({ messenger, connectivityAdapter, }: ConnectivityControllerOptions);
|
|
114
96
|
}
|
|
115
97
|
export {};
|
|
116
98
|
//# sourceMappingURL=ConnectivityController.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectivityController.d.mts","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;
|
|
1
|
+
{"version":3,"file":"ConnectivityController.d.mts","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AAEvE;;;;GAIG;AACH,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;;OAGG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC;AAcF;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,IAAI,2BAA2B,CAInF;AAED;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACvC,oCAAoC,CAAC;AAEvC;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG,0BAA0B,CAC7E,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACtC,sCAAsC,CAAC;AAEzC;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,cAAc,EACrB,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;OAEG;IACH,SAAS,EAAE,+BAA+B,CAAC;IAE3C;;OAEG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,qBAAa,sBAAuB,SAAQ,cAAc,CACxD,OAAO,cAAc,EACrB,2BAA2B,EAC3B,+BAA+B,CAChC;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE,6BAA6B;CAmBjC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseController } from "@metamask/base-controller";
|
|
2
|
-
import {
|
|
2
|
+
import { CONNECTIVITY_STATUSES } from "./types.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* The name of the {@link ConnectivityController}, used to namespace the
|
|
5
5
|
* controller's actions and events and to namespace the controller's state data
|
|
@@ -27,27 +27,19 @@ const connectivityControllerMetadata = {
|
|
|
27
27
|
*/
|
|
28
28
|
export function getDefaultConnectivityControllerState() {
|
|
29
29
|
return {
|
|
30
|
-
connectivityStatus:
|
|
30
|
+
connectivityStatus: CONNECTIVITY_STATUSES.Online,
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* ConnectivityController stores the device's internet connectivity status.
|
|
35
35
|
*
|
|
36
36
|
* This controller is platform-agnostic and designed to be used across different
|
|
37
|
-
* MetaMask clients (extension, mobile). It requires a `
|
|
37
|
+
* MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to
|
|
38
38
|
* be injected, which provides platform-specific connectivity detection.
|
|
39
39
|
*
|
|
40
|
-
* The controller subscribes to the
|
|
40
|
+
* The controller subscribes to the adapter's `onConnectivityChange` callback
|
|
41
41
|
* and updates its state accordingly. All connectivity updates flow through
|
|
42
|
-
* the
|
|
43
|
-
*
|
|
44
|
-
* **Platform implementations:**
|
|
45
|
-
*
|
|
46
|
-
* - **Mobile:** Inject `NetInfoConnectivityService` using `@react-native-community/netinfo`
|
|
47
|
-
* - **Extension:** Inject `PassiveConnectivityService` in the background.
|
|
48
|
-
* Status is updated via the `setDeviceConnectivityStatus` API, which is called from:
|
|
49
|
-
* - MV3: Offscreen document (where browser events work reliably)
|
|
50
|
-
* - MV2: Background page (where browser events work directly)
|
|
42
|
+
* the adapter, ensuring a single source of truth.
|
|
51
43
|
*
|
|
52
44
|
* This controller provides a centralized state for connectivity status,
|
|
53
45
|
* enabling the UI and other controllers to adapt when the user goes offline.
|
|
@@ -58,10 +50,10 @@ export class ConnectivityController extends BaseController {
|
|
|
58
50
|
*
|
|
59
51
|
* @param args - The arguments to this controller.
|
|
60
52
|
* @param args.messenger - The messenger suited for this controller.
|
|
61
|
-
* @param args.
|
|
53
|
+
* @param args.connectivityAdapter - The connectivity adapter to use.
|
|
62
54
|
*/
|
|
63
|
-
constructor({ messenger,
|
|
64
|
-
const initialStatus =
|
|
55
|
+
constructor({ messenger, connectivityAdapter, }) {
|
|
56
|
+
const initialStatus = connectivityAdapter.getStatus();
|
|
65
57
|
super({
|
|
66
58
|
messenger,
|
|
67
59
|
metadata: connectivityControllerMetadata,
|
|
@@ -71,7 +63,7 @@ export class ConnectivityController extends BaseController {
|
|
|
71
63
|
connectivityStatus: initialStatus,
|
|
72
64
|
},
|
|
73
65
|
});
|
|
74
|
-
|
|
66
|
+
connectivityAdapter.onConnectivityChange((status) => {
|
|
75
67
|
this.update((draftState) => {
|
|
76
68
|
draftState.connectivityStatus = status;
|
|
77
69
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectivityController.mjs","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ConnectivityController.mjs","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAGhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAavD;;GAEG;AACH,MAAM,8BAA8B,GAAG;IACrC,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;CACmD,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,UAAU,qCAAqC;IACnD,OAAO;QACL,kBAAkB,EAAE,qBAAqB,CAAC,MAAM;KACjD,CAAC;AACJ,CAAC;AAkED;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,sBAAuB,SAAQ,cAI3C;IACC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,mBAAmB,GACW;QAC9B,MAAM,aAAa,GAAG,mBAAmB,CAAC,SAAS,EAAE,CAAC;QAEtD,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,8BAA8B;YACxC,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE;gBACL,GAAG,qCAAqC,EAAE;gBAC1C,kBAAkB,EAAE,aAAa;aAClC;SACF,CAAC,CAAC;QAEH,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE;YAClD,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;gBACzB,UAAU,CAAC,kBAAkB,GAAG,MAAM,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport { CONNECTIVITY_STATUSES } from './types';\nimport type { ConnectivityAdapter, ConnectivityStatus } from './types';\n\n/**\n * The name of the {@link ConnectivityController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'ConnectivityController';\n\n/**\n * State for the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerState = {\n /**\n * The current device connectivity status.\n * Named with 'connectivity' prefix to avoid conflicts when state is flattened in Redux.\n */\n connectivityStatus: ConnectivityStatus;\n};\n\n/**\n * The metadata for each property in {@link ConnectivityControllerState}.\n */\nconst connectivityControllerMetadata = {\n connectivityStatus: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<ConnectivityControllerState>;\n\n/**\n * Constructs the default {@link ConnectivityController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link ConnectivityController} state.\n */\nexport function getDefaultConnectivityControllerState(): ConnectivityControllerState {\n return {\n connectivityStatus: CONNECTIVITY_STATUSES.Online,\n };\n}\n\n/**\n * Retrieves the state of the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Actions that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerActions =\n ConnectivityControllerGetStateAction;\n\n/**\n * Actions from other messengers that {@link ConnectivityControllerMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when the state of {@link ConnectivityController} changes.\n */\nexport type ConnectivityControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Events that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerEvents =\n ConnectivityControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ConnectivityControllerMessenger} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ConnectivityController}.\n */\nexport type ConnectivityControllerMessenger = Messenger<\n typeof controllerName,\n ConnectivityControllerActions | AllowedActions,\n ConnectivityControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for constructing the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerOptions = {\n /**\n * The messenger for inter-controller communication.\n */\n messenger: ConnectivityControllerMessenger;\n\n /**\n * Connectivity adapter for platform-specific detection.\n */\n connectivityAdapter: ConnectivityAdapter;\n};\n\n/**\n * ConnectivityController stores the device's internet connectivity status.\n *\n * This controller is platform-agnostic and designed to be used across different\n * MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to\n * be injected, which provides platform-specific connectivity detection.\n *\n * The controller subscribes to the adapter's `onConnectivityChange` callback\n * and updates its state accordingly. All connectivity updates flow through\n * the adapter, ensuring a single source of truth.\n *\n * This controller provides a centralized state for connectivity status,\n * enabling the UI and other controllers to adapt when the user goes offline.\n */\nexport class ConnectivityController extends BaseController<\n typeof controllerName,\n ConnectivityControllerState,\n ConnectivityControllerMessenger\n> {\n /**\n * Constructs a new {@link ConnectivityController}.\n *\n * @param args - The arguments to this controller.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.connectivityAdapter - The connectivity adapter to use.\n */\n constructor({\n messenger,\n connectivityAdapter,\n }: ConnectivityControllerOptions) {\n const initialStatus = connectivityAdapter.getStatus();\n\n super({\n messenger,\n metadata: connectivityControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultConnectivityControllerState(),\n connectivityStatus: initialStatus,\n },\n });\n\n connectivityAdapter.onConnectivityChange((status) => {\n this.update((draftState) => {\n draftState.connectivityStatus = status;\n });\n });\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefaultConnectivityControllerState = exports.ConnectivityController = exports.
|
|
3
|
+
exports.getDefaultConnectivityControllerState = exports.ConnectivityController = exports.CONNECTIVITY_STATUSES = void 0;
|
|
4
4
|
var types_1 = require("./types.cjs");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "CONNECTIVITY_STATUSES", { enumerable: true, get: function () { return types_1.CONNECTIVITY_STATUSES; } });
|
|
6
6
|
var ConnectivityController_1 = require("./ConnectivityController.cjs");
|
|
7
7
|
Object.defineProperty(exports, "ConnectivityController", { enumerable: true, get: function () { return ConnectivityController_1.ConnectivityController; } });
|
|
8
8
|
Object.defineProperty(exports, "getDefaultConnectivityControllerState", { enumerable: true, get: function () { return ConnectivityController_1.getDefaultConnectivityControllerState; } });
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AASA,
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AASA,qCAAgD;AAAvC,8GAAA,qBAAqB,OAAA;AAC9B,uEAGkC;AAFhC,gIAAA,sBAAsB,OAAA;AACtB,+IAAA,qCAAqC,OAAA","sourcesContent":["export type {\n ConnectivityControllerState,\n ConnectivityControllerGetStateAction,\n ConnectivityControllerActions,\n ConnectivityControllerStateChangeEvent,\n ConnectivityControllerEvents,\n ConnectivityControllerMessenger,\n} from './ConnectivityController';\nexport type { ConnectivityAdapter, ConnectivityStatus } from './types';\nexport { CONNECTIVITY_STATUSES } from './types';\nexport {\n ConnectivityController,\n getDefaultConnectivityControllerState,\n} from './ConnectivityController';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { ConnectivityControllerState, ConnectivityControllerGetStateAction, ConnectivityControllerActions, ConnectivityControllerStateChangeEvent, ConnectivityControllerEvents, ConnectivityControllerMessenger, } from "./ConnectivityController.cjs";
|
|
2
|
-
export type {
|
|
3
|
-
export {
|
|
2
|
+
export type { ConnectivityAdapter, ConnectivityStatus } from "./types.cjs";
|
|
3
|
+
export { CONNECTIVITY_STATUSES } from "./types.cjs";
|
|
4
4
|
export { ConnectivityController, getDefaultConnectivityControllerState, } from "./ConnectivityController.cjs";
|
|
5
5
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,YAAY,EAAE,mBAAmB,EAAE,oBAAgB;
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AACvE,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { ConnectivityControllerState, ConnectivityControllerGetStateAction, ConnectivityControllerActions, ConnectivityControllerStateChangeEvent, ConnectivityControllerEvents, ConnectivityControllerMessenger, } from "./ConnectivityController.mjs";
|
|
2
|
-
export type {
|
|
3
|
-
export {
|
|
2
|
+
export type { ConnectivityAdapter, ConnectivityStatus } from "./types.mjs";
|
|
3
|
+
export { CONNECTIVITY_STATUSES } from "./types.mjs";
|
|
4
4
|
export { ConnectivityController, getDefaultConnectivityControllerState, } from "./ConnectivityController.mjs";
|
|
5
5
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,YAAY,EAAE,mBAAmB,EAAE,oBAAgB;
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AACvE,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC"}
|
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,EACtC,qCAAiC","sourcesContent":["export type {\n ConnectivityControllerState,\n ConnectivityControllerGetStateAction,\n ConnectivityControllerActions,\n ConnectivityControllerStateChangeEvent,\n ConnectivityControllerEvents,\n ConnectivityControllerMessenger,\n} from './ConnectivityController';\nexport type { ConnectivityAdapter, ConnectivityStatus } from './types';\nexport { CONNECTIVITY_STATUSES } from './types';\nexport {\n ConnectivityController,\n getDefaultConnectivityControllerState,\n} from './ConnectivityController';\n"]}
|
package/dist/types.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CONNECTIVITY_STATUSES = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Connectivity status constants.
|
|
6
6
|
* Used to represent whether the device has internet connectivity.
|
|
7
7
|
*/
|
|
8
|
-
exports.
|
|
8
|
+
exports.CONNECTIVITY_STATUSES = {
|
|
9
9
|
Online: 'online',
|
|
10
10
|
Offline: 'offline',
|
|
11
11
|
};
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,qBAAqB,GAAG;IACnC,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CACV,CAAC","sourcesContent":["/**\n * Connectivity status constants.\n * Used to represent whether the device has internet connectivity.\n */\nexport const CONNECTIVITY_STATUSES = {\n Online: 'online',\n Offline: 'offline',\n} as const;\n\nexport type ConnectivityStatus =\n (typeof CONNECTIVITY_STATUSES)[keyof typeof CONNECTIVITY_STATUSES];\n\n/**\n * Adapter interface for platform-specific connectivity detection.\n * Each platform (extension, mobile) implements this interface using\n * platform-specific APIs to detect internet connectivity.\n */\nexport type ConnectivityAdapter = {\n /**\n * Returns the current connectivity status.\n *\n * @returns 'online' if the device is online, 'offline' otherwise.\n */\n getStatus(): ConnectivityStatus;\n\n /**\n * Registers a callback to be called when connectivity status changes.\n *\n * @param callback - Function called with 'online' when online, 'offline' when offline.\n */\n onConnectivityChange(callback: (status: ConnectivityStatus) => void): void;\n\n /**\n * Cleans up any resources (event listeners, subscriptions).\n */\n destroy(): void;\n};\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -2,23 +2,17 @@
|
|
|
2
2
|
* Connectivity status constants.
|
|
3
3
|
* Used to represent whether the device has internet connectivity.
|
|
4
4
|
*/
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const CONNECTIVITY_STATUSES: {
|
|
6
6
|
readonly Online: "online";
|
|
7
7
|
readonly Offline: "offline";
|
|
8
8
|
};
|
|
9
|
-
export type ConnectivityStatus = (typeof
|
|
9
|
+
export type ConnectivityStatus = (typeof CONNECTIVITY_STATUSES)[keyof typeof CONNECTIVITY_STATUSES];
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Adapter interface for platform-specific connectivity detection.
|
|
13
12
|
* Each platform (extension, mobile) implements this interface using
|
|
14
|
-
* platform-specific APIs
|
|
15
|
-
* - Extension: `navigator.onLine` and `online`/`offline` events
|
|
16
|
-
* - Mobile: `@react-native-community/netinfo`
|
|
17
|
-
*
|
|
18
|
-
* The service is injected into the ConnectivityController, which
|
|
19
|
-
* subscribes to connectivity changes and updates its state accordingly.
|
|
13
|
+
* platform-specific APIs to detect internet connectivity.
|
|
20
14
|
*/
|
|
21
|
-
export type
|
|
15
|
+
export type ConnectivityAdapter = {
|
|
22
16
|
/**
|
|
23
17
|
* Returns the current connectivity status.
|
|
24
18
|
*
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;CAGxB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,SAAS,IAAI,kBAAkB,CAAC;IAEhC;;;;OAIG;IACH,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,GAAG,IAAI,CAAC;IAE3E;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -2,23 +2,17 @@
|
|
|
2
2
|
* Connectivity status constants.
|
|
3
3
|
* Used to represent whether the device has internet connectivity.
|
|
4
4
|
*/
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const CONNECTIVITY_STATUSES: {
|
|
6
6
|
readonly Online: "online";
|
|
7
7
|
readonly Offline: "offline";
|
|
8
8
|
};
|
|
9
|
-
export type ConnectivityStatus = (typeof
|
|
9
|
+
export type ConnectivityStatus = (typeof CONNECTIVITY_STATUSES)[keyof typeof CONNECTIVITY_STATUSES];
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Adapter interface for platform-specific connectivity detection.
|
|
13
12
|
* Each platform (extension, mobile) implements this interface using
|
|
14
|
-
* platform-specific APIs
|
|
15
|
-
* - Extension: `navigator.onLine` and `online`/`offline` events
|
|
16
|
-
* - Mobile: `@react-native-community/netinfo`
|
|
17
|
-
*
|
|
18
|
-
* The service is injected into the ConnectivityController, which
|
|
19
|
-
* subscribes to connectivity changes and updates its state accordingly.
|
|
13
|
+
* platform-specific APIs to detect internet connectivity.
|
|
20
14
|
*/
|
|
21
|
-
export type
|
|
15
|
+
export type ConnectivityAdapter = {
|
|
22
16
|
/**
|
|
23
17
|
* Returns the current connectivity status.
|
|
24
18
|
*
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;CAGxB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,SAAS,IAAI,kBAAkB,CAAC;IAEhC;;;;OAIG;IACH,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,GAAG,IAAI,CAAC;IAE3E;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"}
|
package/dist/types.mjs
CHANGED
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CACV,CAAC","sourcesContent":["/**\n * Connectivity status constants.\n * Used to represent whether the device has internet connectivity.\n */\nexport const CONNECTIVITY_STATUSES = {\n Online: 'online',\n Offline: 'offline',\n} as const;\n\nexport type ConnectivityStatus =\n (typeof CONNECTIVITY_STATUSES)[keyof typeof CONNECTIVITY_STATUSES];\n\n/**\n * Adapter interface for platform-specific connectivity detection.\n * Each platform (extension, mobile) implements this interface using\n * platform-specific APIs to detect internet connectivity.\n */\nexport type ConnectivityAdapter = {\n /**\n * Returns the current connectivity status.\n *\n * @returns 'online' if the device is online, 'offline' otherwise.\n */\n getStatus(): ConnectivityStatus;\n\n /**\n * Registers a callback to be called when connectivity status changes.\n *\n * @param callback - Function called with 'online' when online, 'offline' when offline.\n */\n onConnectivityChange(callback: (status: ConnectivityStatus) => void): void;\n\n /**\n * Cleans up any resources (event listeners, subscriptions).\n */\n destroy(): void;\n};\n"]}
|
package/package.json
CHANGED