Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: Use promises instead of callbacks #56

Merged
merged 16 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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