Using Salut for Peer-To-Peer
Closed this issue · 2 comments
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?
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
Hello,
I'm going to assume that you're already familiar with the discoverPeers
method and the peerListListener
from 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 SalutDevice
and pass that to the Salut connect
method. You'll need to change up the onConnectionInfoAvailable
method 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);
}