Skip to content

Commit

Permalink
feat(Bridge): add method to bridge for obtaining metadata about netwo… (
Browse files Browse the repository at this point in the history
#121)

* feat(Bridge): add method to bridge for obtaining metadata about network data connection

* ACCOUNT-23612 rename and add documentation
  • Loading branch information
Winde authored Nov 24, 2023
1 parent 8c91bc9 commit 5e24558
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v.3.30.0 - 2023-12-16

- New `getNetworkConnectionInfo` function

## v.3.29.0 - 2023-10-26

- New `openOnboarding` function
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,28 @@ available
getAttStatus: () => Promise<{status:'granted' | 'denied' | 'unknown'} | null>;
```
### getNetworkConnectionInfo
<kbd>App version >=14.11</kbd>
Obtain metainformation about the current device data network connectivity
```ts
getNetworkConnectionInfo: () => Promise<{
connectionType: 'MOBILE' | 'WIFI ' | 'OTHER' | 'NONE';
mobileConnectionType?: '2G' | '3G' | '4G' | '5G' | 'OTHER' | null;
mobileCarrier?: string | null;
mobileSignalStrength?: 'NONE' | 'POOR' | 'MODERATE' | 'GOOD' | 'GREAT' | null;
}>;
```
- `connectionType`: describes the network technology used currently for data
- `mobileConnectionType`: in case connectionType is 'MOBILE' gives further
details about the network technology used.
- `mobileCarrier`: identifies the carrier used for 'MOBILE' connectionType
- `mobileSignalStrength`: gives a measure of the current signal strength for
'MOBILE' connectionType.
## Error handling
If an uncontrolled error occurs, promise will be rejected with an error object:
Expand Down
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export {
fetch,
checkPermissionStatus,
getAppMetadata,
getNetworkConnectionInfo,
setActionBehavior,
getTopazToken,
onNavigationBarIconClicked,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tef-novum/webview-bridge",
"version": "3.29.0",
"version": "3.30.0",
"description": "JavaScript library to access to native functionality. Requires a webview with a postMessage bridge.",
"main": "./dist/webview-bridge-cjs.js",
"module": "./dist/webview-bridge.mjs",
Expand Down
36 changes: 35 additions & 1 deletion src/__tests__/utils-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
createFakeAndroidPostMessage,
removeFakeAndroidPostMessage,
} from './fake-post-message';
import {getAppMetadata} from '../utils';
import {getAppMetadata, getNetworkConnectionInfo} from '../utils';

const ANY_STRING = 'any-string';
const ANY_OTHER_STRING = 'any-other-string';
Expand Down Expand Up @@ -561,6 +561,40 @@ test('get app metadata of installed application', async () => {
});
});

test('get data connection info', async () => {
const connectionType = 'MOBILE';
const mobileConnectionType = '4G';
const mobileCarrier = 'Telefonica';
const mobileSignalStrength = 'POOR';

createFakeAndroidPostMessage({
checkMessage: (msg) => {
expect(msg.type).toBe('DATA_CONNECTION_INFO');
expect(msg.payload).toMatchObject({});
},
getResponse: (msg) => ({
type: 'DATA_CONNECTION_INFO',
id: msg.id,
payload: {
connectionType,
mobileConnectionType,
mobileCarrier,
mobileSignalStrength,
},
}),
});

await getNetworkConnectionInfo().then((res) => {
expect(res).toMatchObject({
connectionType,
mobileConnectionType,
mobileCarrier,
mobileSignalStrength,
});
removeFakeAndroidPostMessage();
});
});

test('set confirm action behavior', (done) => {
const actions = {
webviewClose: {
Expand Down
18 changes: 18 additions & 0 deletions src/post-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ export type SnackbarResponse = {
action: 'DISMISS' | 'BUTTON' | 'TIMEOUT' | 'CONSECUTIVE';
};

type DataConnectionResponse = {
connectionType: 'MOBILE' | 'WIFI ' | 'OTHER' | 'NONE';
mobileConnectionType?: '2G' | '3G' | '4G' | '5G' | 'OTHER' | null;
mobileCarrier?: string | null;
mobileSignalStrength?:
| 'NONE'
| 'POOR'
| 'MODERATE'
| 'GOOD'
| 'GREAT'
| null;
};

export type ResponsesFromNativeApp = {
SIM_ICC: {
id: string;
Expand Down Expand Up @@ -269,6 +282,11 @@ export type ResponsesFromNativeApp = {
id: string;
payload: void;
};
DATA_CONNECTION_INFO: {
type: 'DATA_CONNECTION_INFO';
id: string;
payload: DataConnectionResponse;
};
};

export type NativeAppResponsePayload<
Expand Down
8 changes: 8 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ export const getAppMetadata = (
},
});

export const getNetworkConnectionInfo = (): Promise<
NativeAppResponsePayload<'DATA_CONNECTION_INFO'>
> =>
postMessageToNativeApp({
type: 'DATA_CONNECTION_INFO',
payload: {},
});

type ActionBehavior =
| {
behavior: 'confirm';
Expand Down

0 comments on commit 5e24558

Please sign in to comment.