Git Product home page Git Product logo

aboozaid / react-native-tethering Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 2.0 2.53 MB

A React Native module for working with Wi-Fi and Hotspot. Compatible with Expo.

Home Page: https://react-native-tethering.onrender.com/

License: MIT License

Kotlin 47.53% JavaScript 5.99% Ruby 4.84% Java 7.10% Swift 0.48% C 0.10% Objective-C 2.95% Objective-C++ 1.10% TypeScript 29.90%
react-native wifi react-native-hotspot react-native-tethering react-native-wifi hotspot tethering

react-native-tethering's Introduction

react-native-tethering's People

Contributors

aboozaid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-tethering's Issues

Feedback about Permissions in general and question about Hotspot

Tested almost every function I could get my hands on at the moment and found out this:

<uses-permission android:name="android.permission.WRITE_SETTINGS"
    tools:ignore="ProtectedPermissions" /> 

does not really make the app have write setting permissions at load.

Instead, what worked for me, was to navigate to the permissions page using the below code that is given in the example folder here: example/src/HotspotScreen.tsx

async () => {
            try {
              await HotspotManager.openWriteSettings();
            } catch (error: any) {
              if (error instanceof TetheringError) {
                ToastAndroid.show(error.message, ToastAndroid.LONG)
              }
              console.log(error);
              
            }
          }

that way we prompt the user to enable the permissions himself and everything works smoothly after that.

As for other permissions like FINE / COURSE_LOCATION, again I faced the same problem with the log showing "Error UID [exampleUID] does not have FINE / COURSE_LOCATION permissions. To bypass this I used this code block :

import { PermissionsAndroid } from 'react-native';

async function requestMultiplePermissions() {
  try {
    const granted = await PermissionsAndroid.requestMultiple([
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
    ]);
    if (
      granted['android.permission.ACCESS_FINE_LOCATION'] ===
        PermissionsAndroid.RESULTS.GRANTED &&
      granted['android.permission.ACCESS_COARSE_LOCATION'] ===
        PermissionsAndroid.RESULTS.GRANTED
    ) {
      console.log('Location permissions granted');
      // Call the desired function here
    } else {
      console.log('Location permissions denied');
    }
  } catch (err) {
    console.warn(err);
  }
}

@aboozaid Overall, if you bypass the permissions "errors" (which ain't exactly errors per se), everything seems to work as intended.
I would like to thank you for publishing this, after such short notice.

I only have one question, which is really important to me and I think many others that will use this module.

Can you add a function in the example where the SSID and Password of the enabled Hotspot are predefined by the programmer, so the user doesn't have to navigate to it's page and put them manually after opening it through your module?
Adding an example of it would be great!

Thank you for your time and I hope this proves to be helpful.

IOS Support

I need someone to help providing an IOS wrapper to the package so please if you're interested feel free to contribute.

When connecting to local network, cannot send HTTPS requests after loading the app with

Hi again!

When using

"@react-native-tethering/wifi": "^1.0.0",

I am having issues when connecting to a local network using connectToLocalNetwork while testing on Android 13:

  1. Connecting the first time works and I am able to make requests to the network's private API no problem
  2. When I kill the app (close completely) and reopen the app, although my device is still connected to the local network, the api returns a "Network Error" status.
  3. It only works again if for a re-connect using connectToLocalNetwork

Then I was thinking I should disconnect to the local network before reconnecting, but:

  • When I try to disconnect in order to reconnect after using disconnectFromLocalNetwork, it returns a NetworkCallback was not registered error.

Would you have an explanation / reasons for the above issues please?

Thanks in advance. Let me know if you need more information!

[Android 13] saveNetworkInDevice error not triggered if already saved

Testing with Android 13, when calling saveNetworkInDevice (when the local network was already successfully saved using that same function) doesn't trigger/throw the error ERR_NETWORK_SAVED specified in the documentation.

How can I make sure to get that error in order to fallback into the regular connectToLocalNetwork if it's already saved?

Thanks in advance again for your help!

Add a method to access the current Network's SSID

Hello there!

Thanks for providing this package!

I was wondering if it'd be possible to include a method which would return the current connected network's SSID? Like:

getCurrentWifiSSID

which would return the SSID or null (if not connected)

for the @react-native-tethering/wifi package

??

After reading online it seems possible if the device grants access to at least the foreground location (?)

Do you think it would possible to add this method and/or do you see any issues with this new request?

Thank you in advance for your help and support :)

connectToNetwork - Connection timeout

The connectToNetwork method returns after the first successful connection, after restarting the app only 'Connection timeout'. Timeout parameter is set to 1000.

Build error

Nice to see there is movement in the React Native Wifi space.
I unfortunately have an error with the Android build:
/WifiTethering.kt: (628, 37): Unresolved reference: STATUS_NETWORK_SUGGESTIONS_ERROR_RESTRICTED_BY_ADMIN

TypeError: 0, _hotspot.isHotspotEnabled is not a function (it is undefined)

i just add permission

"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"permissions": [
"ACCESS_FINE_LOCATION",
"ACCESS_COARSE_LOCATION",
"WRITE_SETTINGS",
"NEARBY_WIFI_DEVICES"
]
},

and than, in my app.js
import { isHotspotEnabled } from '@react-native-tethering/hotspot';

and inside useEffect:
let hotspotStatus = await isHotspotEnabled();
console.log("hotspotStatus", hotspotStatus)

and got
TypeError: 0, _hotspot.isHotspotEnabled is not a function (it is undefined)

Set Specific Hotspot SSID and Password

I want to start a Hotspot with Custom SSID and Password ..how to do it exactly.Since there is no SSID or Password parameter on setHotspotEnabled function.

Error: Arp table reading failed, are you using targetSdk 32 and an Android 13 device? when calling getConnectedDevices()

Error: Arp table reading failed, are you using targetSdk 32 and an Android 13 device?

getConnectedDevices() returns an empty array, I had to look into logs and I discovered that Google introduced some restrictions in Android 10

"Android 10 introduces several privacy-related restrictions that disallow apps to access certain information that could be potentially misused for fingerprinting and data collection. One of among them is the restriction on access to /proc/net filesystem on devices that run Android 10 or higher, apps cannot access /proc/net, which includes information about a device's network state. Apps that need access to this information, such as VPNs, should use the NetworkStatsManager or ConnectivityManager class."

Failure to Switch WiFi Network Using TetheringManager.connectToLocalNetwork()

Hello,

I am encountering a problem similar to the one reported in the react-native-wifi-reborn repository: Issue #303.

My current setup involves using a Google Pixel 6a. However, to eliminate device-specific factors, I plan to test this again on a different device later this week.

The core issue is as follows:

I'm utilizing the TetheringManager.connectToLocalNetwork() function. Although Android indicates a successful connection, my WiFi network does not switch over as expected. It's important to note that the WiFi network in question is not a router; rather, it's a hotspot emitted by a Linux device that lacks internet connectivity (similar to a Raspberry Pi emitting a WiFi signal without internet access).

I've ensured that my AndroidManifest.xml file includes the necessary permissions:

<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

When attempting to connect, I encounter a location permission prompt and subsequently a network connection prompt. Following these, a small popup at the bottom confirms a "Successful connection." Despite this, I remain connected to my original router rather than the intended alternate device.

Your assistance in resolving this matter would be greatly appreciated.

Thank you.

Android getWifiNetworks not providing latest available networks.

Hello There, I am facing a problem, the getWifiNetworks is not providing latest available wifi networks. I have to go to phone wifi settings and if the new devices are available there then only its giving that results. Its a weird thing I am not able to see latest available devices which I want to connect from my app.

Thank you for any advice in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.