kirillzyusko / react-native-wifi-p2p

Library that provide access for working with wi-fi direct (p2p) module in android.
164 stars 32 forks source link

disconnect implementation doesn't match the name 'disconnect' #20

Closed NoamDev closed 4 years ago

NoamDev commented 4 years ago

currently the implementation is:

@ReactMethod
    public void disconnect(final Callback callback) {
        manager.cancelConnect(channel, new WifiP2pManager.ActionListener() {
            @Override
            public void onSuccess() {
                callback.invoke();
            }

            @Override
            public void onFailure(int reasonCode) {
                callback.invoke(Integer.valueOf(reasonCode));
            }
        });
    }

However, according to its docs cancelConnect - 'Cancel any ongoing p2p group negotiation'.

disconnect should be like in this stackoverflow answer:

public static void disconnect() {
    if (mManager != null && mChannel != null) {
        mManager.requestGroupInfo(mChannel, new GroupInfoListener() {
            @Override
            public void onGroupInfoAvailable(WifiP2pGroup group) {
                if (group != null && mManager != null && mChannel != null) {
                    mManager.removeGroup(mChannel, new ActionListener() {

                        @Override
                        public void onSuccess() {
                            Log.d(TAG, "removeGroup onSuccess -");
                        }

                        @Override
                        public void onFailure(int reason) {
                            Log.d(TAG, "removeGroup onFailure -" + reason);
                        }
                    });
                }
            }
        });
    }
}
NoamDev commented 4 years ago

I don't what is wrong, the name 'disconnect' or the implementation. @kirillzyusko, What was your purpose?

kirillzyusko commented 4 years ago

Hi, @NoamDev When I worked on implementation of this library, I merely wanted to recreate all basics methods (yes, sometimes methods names are different 😄)

About disconnect implementation from StackOverflow - you can re-create this code snippet using JS code:

await getGroupPassphraseInfo();
await removeGroup();

It was a goal of this library: rather than trying to cover all possible cases, merely write basics methods and if needed - use a combination of them in JS.

Did I answer on your question?

NoamDev commented 4 years ago

Yeah, I guess that what enabled to create a great library with only two collaborators:) In that case, I suggest you to rename the method, it is really misleading..

NoamDev commented 4 years ago

Yes, I know, it's a breaking change so you'd have to publish a new version...

kirillzyusko commented 4 years ago

Yes, I agree with you I definetly have to do it Thank you for pointing it out :)

kirillzyusko commented 4 years ago

@NoamDev Done!😎 I published new version as 2.0.0. So, you can update to the newest and use cancelConnect.