neatorobito / Salut

A nice library for working with WiFi P2P service discovery on Android.
MIT License
297 stars 89 forks source link

Using Salut for Peer-To-Peer #11

Closed gouravd closed 8 years ago

gouravd commented 8 years ago

What I understand of Salut, its primarily for Wifi Direct Service discovery and connection/communication henceforth.

Is Salut already abstracting Peer-to-Peer discovery and functionality or is it limited to Service discovery only?

Any plans for Peer-to-Peer discovery and functionality in upcoming versions?

gouravd commented 8 years ago

Since the peer discovery and connecion is really simple (as per the Android docs), getting help for sending data across using Salut would be really helpful

neatorobito commented 8 years ago

Hello,

I'm going to assume that you're already familiar with the discoverPeersmethod and the peerListListenerfrom the Android documentation, which are used for discovering peers and then getting the list of peers respectively. Once you've got a peer as a WiFiP2PDevice, convert it into a SalutDeviceand pass that to the Salut connectmethod. You'll need to change up the onConnectionInfoAvailablemethod completely. It might look something like this. This is mostly pseudocode.

               SalutDevice device = new SalutDevice();
               device.deviceName = WIFIP2PDEVICEOBJECT.deviceName;
               device.macAddress = WIFIP2PDEVICEOBJECT.deviceAddress;
               device.serviceAddress = info.groupOwnerAddress;
               device.servicePort = SOMEPREDETERMINEDPORT;

              //You will likely have to create above object somewhere else, or make it global so that you have access to it in the following method. 
    @Override
    public void onConnectionInfoAvailable(final WifiP2pInfo info) {

               BackgroundDataSendJob sendDataToDevice = new BackgroundDataSendJob(device, SALUTINSTANCE, data, null);
               AsyncJob.doInBackground(sendDataToDevice);
    }