kirillzyusko / react-native-wifi-p2p

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

method getAvailablePeers() always return empty device array #88

Closed bacancyshreyansh closed 1 year ago

bacancyshreyansh commented 1 year ago

` useEffect(() => { navigation.setOptions({headerLeft: null, headerRight: null});

initialiseP2P().catch(console.error);

const onCreateGroup = async () => {
  await createGroup().then(() =>
    console.log('Group created successfully!'),
  );
  // .catch((err) => console.log("Something went wrong. Details: ", err));
};

const onStartDiscoveringPeers = async () => {
  await startDiscoveringPeers()
    .then(() => getAvailablePeers())
    .then(({devices}) =>
      console.log('Available Devices: Sync.js ', devices),
    );
};

const onStopDiscoveringPeers = async () => {
  await stopDiscoveringPeers().then(() =>
    console.log('Stop discovering was successful'),
  );
};

const onCancelConnect = async () => {
  await cancelConnect().then(() =>
    console.log('Connection successfully canceled'),
  );
};

const onRemoveGroup = async () => {
  await removeGroup().then(
    () => console.log("Currently you don't belong to a group!"),
    setCreateGroupState(true),
  );
};

if (!props.passSettings) {
  onCreateGroup().catch(err =>
    console.log('Something went wrong. Details: ', err),
  );
} else {
  onStartDiscoveringPeers().catch(err =>
    console.error(
      `onStartDiscoveringPeers - Something has gone WRONG. Maybe your WiFi is disabled? Error details:`,
      err
    ),
  );
}
return () => {
  if (!props.passSettings) {
    onRemoveGroup().catch(
      err =>
        console.error(
          'Remove group - Something went wrong. Details: ',
          err,
        ),
      setCreateGroupState(false),
    );
  } else {
    onStopDiscoveringPeers().catch(err =>
      console.error(
        `onStopDiscoveringPeers - Something is gone wrong. Maybe your WiFi is disabled? Error details: ${err}`,
      ),
    );
    if (isDeviceConnected) {
      onCancelConnect().catch(err =>
        console.error(
          'onCancelConnect - Something gone wrong. Details: ',
          err,
        ),
      );
    }
    setIsDeviceConnected(false);
  }
};

}, []);`

Here is my console.log where I get empty device array .

Screenshot 2023-07-13 at 9 30 29 AM

React-Native Version details

Screenshot 2023-07-13 at 11 20 15 AM

I have 2 phones connected through wifi direct but when I try get available devices, it returns an empty array of devices .

kirillzyusko commented 1 year ago

@bacancyshreyansh You've attached logs only for 100ms... Can you attach from time when you initialize module till the time when it returns an empty array?