Skip to content

Commit

Permalink
Merge pull request #56 from inthepocket/feature/android-use-promises
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Use promises instead of callbacks
  • Loading branch information
eliaslecomte authored May 1, 2020
2 parents 9a7d4c9 + 75df2a7 commit 83e30cd
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 215 deletions.
87 changes: 23 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,66 +220,25 @@ Used on iOS. If YES, the network is WEP Wi-Fi; otherwise it is a WPA or WPA2 per
## Only Android
The following methods work only on Android

### `loadWifiList(successCallback: function, errorCallback: function)`

Method to get a list of nearby WiFI networks.

#### successCallback( wifiList: string )

Type: `function`

Function to be called if the attempt is successful. It contains a stringified JSONArray of wifiObjects as parameter, each object containing:
### `loadWifiList(): Promise<Array<WifiEntry>>`

Returns a list of nearby WiFI networks.
* `SSID`: The network name.
* `BSSID`: The WiFi BSSID.
* `capabilities`: Describes the authentication, key management, and encryption schemes supported by the access point.
* `frequency`: The primary 20 MHz frequency (in MHz) of the channel over which the client is communicating with the access point.
* `level`: The detected signal level in dBm, also known as the RSSI.
* `timestamp`: timestamp in microseconds (since boot) when this result was last seen.

#### errorCallback

Type: `function`

Function to be called if any error occurs during the attempt. It contains a `string` as parameter with the error message.

#### Usage

```javascript
WifiManager.loadWifiList(
wifiList => {
let wifiArray = JSON.parse(wifiList);
wifiArray.map((value, index) =>
console.log(`Wifi ${index + 1} - ${value.SSID}`)
);
},
error => console.log(error)
);
/**
Result:
"Wifi 1 - Name of the network"
"Wifi 2 - Name of the network"
"Wifi 3 - Name of the network"
...
*/
```

### `reScanAndLoadWifiList(successCallback: function, errorCallback: function)`

This method is similar to `loadWifiList` but it forcefully starts the wifi scanning on android and in the callback fetches the list.

#### Usage

Same as `loadWifiList`.

### `isEnabled(isEnabled: function)`
### `reScanAndLoadWifiList(): Promise<Array<string>>`
Similar to `loadWifiList` but it forcefully starts a new WiFi scan and only passes the results when the scan is done.

### `isEnabled(): Promise<boolean>`
Method to check if WiFi is enabled.

```javascript
WifiManager.isEnabled(isEnabled => {
this.setState({wifiIsEnabled: isEnabled});
});
const enabled = await WifiManager.isEnabled();
this.setState({wifiIsEnabled: enabled});
```

### `setEnabled(enabled: boolean)`
Expand All @@ -291,36 +250,36 @@ WifiManager.setEnabled(true); //set WiFi ON
WifiManager.setEnabled(false); //set WiFi OFF
```

### `connectionStatus (connectionStatusResult: function)`

Indicates whether network connectivity exists and it is possible to establish connections.

#### connectionStatusResult( isConnected: boolean )
### `connectionStatus(): Promise<boolean>`

Type: `function`
Returns if the device is currently connected to a WiFi network.

Called when the network status is resolved. It contains a boolean argument
### `disconnect()`
Disconnect currently connected WiFi network.

### `disconnect`
### `getBSSID(): Promise<string>`
Returns the BSSID (basic service set identifier) of the currently connected WiFi network.

### `getBSSID`
### `getCurrentSignalStrength(): Promise<number>`
Returns the RSSI (received signal strength indicator) of the currently connected WiFi network.

### `getCurrentSignalStrength`

### `getFrequency`
### `getFrequency(): Promise<number>`
Returns the frequency of the currently connected WiFi network.

### `getIP`
### `getIP(): Promise<number>`
Returns the IP of the currently connected WiFi network.

### `isRemoveWifiNetwork`
### `isRemoveWifiNetwork(ssid: String): Promise<boolean>`
This method will remove the wifi network configuration.
If you are connected to that network, it will disconnect.

<details>
<summary>forceWifiUsage(useWifi: boolean): Promise</summary>
### `forceWifiUsage(useWifi: boolean): Promise`

Use this to execute api calls to a wifi network that does not have internet access.
Useful for commissioning IoT devices.
This will route all app network requests to the network (instead of the mobile connection).
It is important to disable it again after using as even when the app disconnects from the wifi network it will keep on routing everything to wifi.
</details>

## Conventions

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.reactlibrary.rnwifi;

public enum IsEnabledErrorCodes {
couldNotGetWifiManager,
}
Loading

0 comments on commit 83e30cd

Please sign in to comment.