react-native-wifi-reborn
react-native-wifi-reborn copied to clipboard
Add timeout option for connectToProtectedSSID
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, 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>;
Unfortunately the native bridge doesn't support overloaded methods. Having two methods with overloaded parameters on Android will throw a runtime exception 😢 .
@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)
I will try if that works and doesn't mess with the promise.
@eliaslecomte, if it doesn't work we can add connectToProtectedSSID to index.js and "overload" it in JavaScript to make it backwards compatible.
any update on this?
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.
try react-native-tethering which has this feature see
Hi,
i created this PR https://github.com/JuanSeBestia/react-native-wifi-reborn/pull/355
Thanks for this contribution! @alexma01
Closing the issue as the pull request has already been created. https://github.com/JuanSeBestia/react-native-wifi-reborn/pull/355