VNAPNIC / flutter_nearby_connections

Flutter plugin support peer-to-peer connectivity and the discovery of nearby devices for Android vs IOS
https://pub.dev/packages/flutter_nearby_connections
BSD 2-Clause "Simplified" License
106 stars 68 forks source link

Browsing and advertising at the same time #21

Closed Sreadon closed 3 years ago

Sreadon commented 3 years ago

Hi,

First of all thanks for this plugin. To let you know what I try to accomplish: imagine a room with 2 phones, when phone is on "scanning room" page, the phone will start advertising a custom ID (passed to deviceName) and at the same time browse for other users. During my testing, I've been able to see other phones, but not if I'm trying to browse AND advertise at the same time. Is that normal? I think yes, but to be sure I prefer to ask.

With this code I can't see any devices neither can be seen

await nearbyService.init(
      serviceType: 'mpconn',
      deviceName: devInfo,
      strategy: Strategy.P2P_CLUSTER,
      callback: (isRunning) async {
        if (isRunning) {
            await nearbyService.stopAdvertisingPeer();
            await nearbyService.stopBrowsingForPeers();
            await Future.delayed(Duration(microseconds: 200));
            await nearbyService.startAdvertisingPeer();
            await nearbyService.startBrowsingForPeers();
        }
      });

But if I'm commenting "startAdvertisingPeer()" on one device and "startBrowsingForPeer" on the other, I can see the device that is advertising perfectly with the one in "browsing mode".

Thank you

VNAPNIC commented 3 years ago

SDK scan only devices started advertisingPeer and the device scan must is BrowsingPeers

Sreadon commented 3 years ago

So a device can't scan (BrowsingPeers) and simultaneously be visible for others (advertisingPeer)?

ether-how commented 3 years ago

Just use both startAdvertisingPeer() and startBrowsingForPeer() without await.

Sreadon commented 3 years ago

Just use both startAdvertisingPeer() and startBrowsingForPeer() without await.

Thank you, that seems to do the job :)