diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a0774b..f7f1e40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [4.3.6](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v4.3.5...v4.3.6) (2021-01-10) + + +### Bug Fixes + +* **Android:** getCurrentWifiSSID return null if '' ([#148](https://github.com/JuanSeBestia/react-native-wifi-reborn/issues/148)) ([336668a](https://github.com/JuanSeBestia/react-native-wifi-reborn/commit/336668a665db05fac141f6f7f0f240cdd43b23c5)) + ## [4.3.5](https://github.com/JuanSeBestia/react-native-wifi-reborn/compare/v4.3.4...v4.3.5) (2021-01-07) diff --git a/README.md b/README.md index 488b5ee..37c7041 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,11 @@ Used on iOS. If true, the network is WEP Wi-Fi; otherwise it is a WPA or WPA2 pe ### `getCurrentWifiSSID(): Promise` +Returns the SSID of the current WiFi network. + +#### Errors: + * `CouldNotDetectSSID`: Not connected or connecting. + ## Only iOS The following methods work only on iOS diff --git a/android/src/main/java/com/reactlibrary/rnwifi/RNWifiModule.java b/android/src/main/java/com/reactlibrary/rnwifi/RNWifiModule.java index 7ed5810..8cf34d3 100644 --- a/android/src/main/java/com/reactlibrary/rnwifi/RNWifiModule.java +++ b/android/src/main/java/com/reactlibrary/rnwifi/RNWifiModule.java @@ -24,6 +24,7 @@ import com.reactlibrary.rnwifi.errors.DisconnectErrorCodes; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableArray; +import com.reactlibrary.rnwifi.errors.GetCurrentWifiSSIDErrorCodes; import com.reactlibrary.rnwifi.errors.IsRemoveWifiNetworkErrorCodes; import com.reactlibrary.rnwifi.errors.LoadWifiListErrorCodes; import com.reactlibrary.rnwifi.receivers.WifiScanResultReceiver; @@ -304,6 +305,12 @@ public void getCurrentWifiSSID(final Promise promise) { ssid = ssid.substring(1, ssid.length() - 1); } + // Android returns `` when it is not connected or still connecting + if (ssid.equals("")) { + promise.reject(GetCurrentWifiSSIDErrorCodes.CouldNotDetectSSID.toString(), "Not connected or connecting."); + return; + } + promise.resolve(ssid); } diff --git a/android/src/main/java/com/reactlibrary/rnwifi/errors/GetCurrentWifiSSIDErrorCodes.kt b/android/src/main/java/com/reactlibrary/rnwifi/errors/GetCurrentWifiSSIDErrorCodes.kt new file mode 100644 index 0000000..6ef6d10 --- /dev/null +++ b/android/src/main/java/com/reactlibrary/rnwifi/errors/GetCurrentWifiSSIDErrorCodes.kt @@ -0,0 +1,8 @@ +package com.reactlibrary.rnwifi.errors + +enum class GetCurrentWifiSSIDErrorCodes { + /** + * Not connected or connecting. + */ + CouldNotDetectSSID, +} diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 68ace09..5cfc115 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -102,6 +102,13 @@ declare module 'react-native-wifi-reborn' { isWEP: boolean ): Promise; + export enum GET_CURRENT_WIFI_SSID_ERRRORS { + CouldNotDetectSSID = 'CouldNotDetectSSID', + } + + /** + * Returns the name of the currently connected WiFi. When not connected, the promise will be or null when not connected. + */ export function getCurrentWifiSSID(): Promise; //#region iOS only diff --git a/package-lock.json b/package-lock.json index 79bd37c..5720239 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-native-wifi-reborn", - "version": "4.3.5", + "version": "4.3.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5321a45..af2594e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-wifi-reborn", - "version": "4.3.5", + "version": "4.3.6", "description": "A react-native implementation for viewing and connecting to Wifi networks on Android and iOS devices.", "types": "lib/types/index.d.ts", "main": "src/index.js",