2

I am unable to create a group chat where more than 2 (up to 15) nearby android users are able to join a chat room.

startMeshNetwork() starts advertising the connection and discovering. This is called in onCreate(), as well as in the callback for a successful connection. This is so that the device will continue to join all nearby devices.

public void startMeshNetwork(){
    Nearby.getConnectionsClient(this)
            .startAdvertising(
                    /* endpointName= */ "Name here",
                    /* serviceId= */ "ID here",
                    mConnectionLifecycleCallback,
                    new AdvertisingOptions(com.google.android.gms.nearby.connection.Strategy.P2P_CLUSTER));

    Nearby.getConnectionsClient(this)
            .startDiscovery(
                    /* serviceId= */ "ID here",
                    new EndpointDiscoveryCallback() {
                        @Override
                        public void onEndpointFound(String endpointId, DiscoveredEndpointInfo info) {                       Nearby.getConnectionsClient(getApplicationContext())
                                    .requestConnection(
                                            /* endpointName= */ "Name here",
                                            endpointId,
                                            mConnectionLifecycleCallback);
                            endpoints.add(endpointId);
                        }

                        @Override
                        public void onEndpointLost(String endpointId) {
                            startMeshNetwork();
                        }
                    },
                    new DiscoveryOptions(com.google.android.gms.nearby.connection.Strategy.P2P_CLUSTER));

}

Code segment that sends payloads to all connected devices

Payload payload = Payload.fromBytes(pendingmessage.getBytes());
for(String endpointId:endpoints)
            Nearby.getConnectionsClient(getApplicationContext()).sendPayload(endpointId, payload);

Connections are being formed with this method, however, the payload sending is inconsistent and is only sent to one device.

PrasannS
  • 21
  • 3
  • 1
    I could be wrong about this, but is there a reason why you're using both the STAR and the CLUSTER strategy and not or the other? – knjk04 Feb 12 '19 at 09:59
  • Thank you for pointing that out. Though I don't believe that that is the root of the issue. I will definitely change that. – PrasannS Feb 14 '19 at 02:41

0 Answers0