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

FIX connectionInfo updated when connection closes #78

Closed viniciuscb closed 1 year ago

viniciuscb commented 1 year ago

FIXES #74

kirillzyusko commented 1 year ago

Could you please explain why you've removed if statement?

I copied code from here:

    ...
    } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {

        if (manager == null) {
            return;
        }

        NetworkInfo networkInfo = (NetworkInfo) intent
                .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);

        if (networkInfo.isConnected()) {

            // We are connected with the other device, request connection
            // info to find group owner IP

            manager.requestConnectionInfo(channel, connectionListener);
        }
        ...

Source: https://developer.android.com/training/connect-devices-wirelessly/wifi-direct#connect

viniciuscb commented 1 year ago

Yes, this is preventing the user's code to receive an update on connectionInfo when the connection is closed by the other peer.

After this patch, I started receiving updates when connection is closed. See this log:

{"groupFormed": false, "groupOwnerAddress": null, "isGroupOwner": false}

with this patch the user can realiably look into connectionInfo.groupFormed to see if the connection with other peers is open or closed.

kirillzyusko commented 1 year ago

Okay, looks good 👍 Could you please fix java-lint/formatting issues?

Just run node scripts/java-lint.js and it should automatically resolve all issues

viniciuscb commented 1 year ago

linted