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

Add timeout option for connectToProtectedSSID #116

Closed
eliaslecomte opened this issue Sep 14, 2020 · 11 comments
Closed

Add timeout option for connectToProtectedSSID #116

eliaslecomte opened this issue Sep 14, 2020 · 11 comments
Assignees
Labels

Comments

@eliaslecomte
Copy link
Collaborator

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 eliaslecomte added the feature request New feature or request label Sep 14, 2020
@Rapsssito
Copy link
Collaborator

Rapsssito commented Sep 22, 2020

@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>;

@eliaslecomte
Copy link
Collaborator Author

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

@Rapsssito
Copy link
Collaborator

Rapsssito commented Sep 22, 2020

@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)

@eliaslecomte
Copy link
Collaborator Author

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

@Rapsssito
Copy link
Collaborator

Rapsssito commented Sep 22, 2020

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

@kidasov
Copy link

kidasov commented Oct 4, 2021

any update on this?

@eliaslecomte eliaslecomte self-assigned this Oct 13, 2021
@fiznool
Copy link

fiznool commented Oct 18, 2021

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.

@aboozaid
Copy link

try react-native-tethering which has this feature see

@alexma01
Copy link
Contributor

alexma01 commented Jan 8, 2024

Hi,

i created this PR #355

@gustavoabel
Copy link
Collaborator

Hi,

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

Thanks for this contribution! @alexma01

@gustavoabel
Copy link
Collaborator

Closing the issue as the pull request has already been created. #355

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants