react-native-wifi-reborn icon indicating copy to clipboard operation
react-native-wifi-reborn copied to clipboard

Add timeout option for connectToProtectedSSID

Open eliaslecomte opened this issue 5 years ago • 7 comments

Feature description

Add configurable timeout option. When the phone couldn't connect to access point in the specified time, cancel the attempt and reject the promise with error timeoutOccurred.

On iOS this timeout behaviour has to be added completely. On Android this is already an option in the native dependency used (https://github.com/ThanosFisherman/WifiUtils) but we don't allow setting it yet.

New method signature

If we don't want to break the lib for users that upgrade, we could add a new method: connectToProtectedSSID(SSID, password, options: Object): Promise Options:

  • isWep: boolean: Used on iOS, ...
  • timeout: int: Maximum time the phone can try to get connected. After this, the connection attempt is cancelled and the promise is rejected. Default is 45 seconds.

eliaslecomte avatar Sep 14 '20 08:09 eliaslecomte

@eliaslecomte, great idea! However, we don't need add a new method. We could change connectToProtectedSSID interface to something like this:

export function connectToProtectedSSID(
        SSID: string,
        password: string | null,
        isWEP: boolean,
        options?: {
             timeout: number | undefined,
        } | undefined
    ): Promise<void>;

Rapsssito avatar Sep 22 '20 10:09 Rapsssito

Unfortunately the native bridge doesn't support overloaded methods. Having two methods with overloaded parameters on Android will throw a runtime exception 😢 .

eliaslecomte avatar Sep 22 '20 11:09 eliaslecomte

@eliaslecomte, can't we add a @Nullable annotation to the options argument in connectToProtectedSSID?

public void connectToProtectedSSID(@NonNull final String SSID, @NonNull final String password, final boolean isWep, @Nullable final ReadableMap options, final Promise promise)

Rapsssito avatar Sep 22 '20 11:09 Rapsssito

I will try if that works and doesn't mess with the promise.

eliaslecomte avatar Sep 22 '20 11:09 eliaslecomte

@eliaslecomte, if it doesn't work we can add connectToProtectedSSID to index.js and "overload" it in JavaScript to make it backwards compatible.

Rapsssito avatar Sep 22 '20 11:09 Rapsssito

any update on this?

kidasov avatar Oct 04 '21 11:10 kidasov

Firstly apologies for wading in, I have just discovered this library, and it's exactly what I need.

My own personal view is that using the named parameters approach to function signatures makes adding new features (such as this) trivial in the future. In this case, a short-term breaking change to a sig such as the following would benefit the library in the longer term:

export function connectToProtectedSSID(options: {
        ssid: string;
        password: string | null;
        isWEP: boolean;
        timeout? number;
    }): Promise<void>;

With this in place, more options can be easily added to this at a later date, providing they are optional.

Of course, there is the downside of inconvenience for existing users, but in most cases a simple refactor should suffice, especially if this is released as a major version bump with clear migration instructions.

Thanks for maintaining this library, whatever decision is taken here, it would be great to have a timeout option.

fiznool avatar Oct 18 '21 20:10 fiznool

try react-native-tethering which has this feature see

aboozaid avatar May 17 '23 06:05 aboozaid

Hi,

i created this PR https://github.com/JuanSeBestia/react-native-wifi-reborn/pull/355

Thanks for this contribution! @alexma01

gustavoabel avatar Feb 05 '24 04:02 gustavoabel

Closing the issue as the pull request has already been created. https://github.com/JuanSeBestia/react-native-wifi-reborn/pull/355

gustavoabel avatar Feb 13 '24 19:02 gustavoabel