Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Commit

Permalink
Fixed a major bug and added a public discovery boolean.
Browse files Browse the repository at this point in the history
  • Loading branch information
neatorobito committed Nov 1, 2015
1 parent ca6beaf commit f890508
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions src/main/java/com/peak/salut/Salut.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class Salut implements WifiP2pManager.ConnectionInfoListener{
public SalutDevice registeredHost;
public boolean isRunningAsHost = false;
public boolean isConnectedToAnotherDevice = false;
public boolean isDiscovering = false;
private ServerSocket listenerServiceSocket;
private ServerSocket salutServerSocket;

Expand Down Expand Up @@ -494,6 +495,8 @@ public void onFailure(int reason) {

private void createService(final SalutCallback onSuccess, final SalutCallback onFailure) {

manager.clearLocalServices(channel, null);

Log.d(TAG, "Starting " + thisDevice.serviceName + " Transport Protocol " + TTP);

//Inject the listening port along with whatever else data that is going to be sent.
Expand Down Expand Up @@ -573,8 +576,7 @@ public void unregisterClient(boolean disableWiFi)
unregisterClient(null, null, disableWiFi);
}

public void startNetworkService(SalutDeviceCallback onDeviceRegisteredWithHost)
{
public void startNetworkService(SalutDeviceCallback onDeviceRegisteredWithHost) {
startNetworkService(onDeviceRegisteredWithHost, null, null);
}

Expand Down Expand Up @@ -620,11 +622,14 @@ public void onDnsSdServiceAvailable(String instanceName, String serviceNameAndTP
@Override
public void onDnsSdTxtRecordAvailable(String serviceFullDomainName, Map<String, String> record, WifiP2pDevice device) {

for(SalutDevice found : foundDevices)
if(!foundDevices.isEmpty())
{
if(found.deviceName.equals(device.deviceName))
for(SalutDevice found : foundDevices)
{
return;
if(found.deviceName.equals(device.deviceName))
{
return;
}
}
}

Expand Down Expand Up @@ -664,11 +669,14 @@ public void onDnsSdServiceAvailable(String instanceName, String serviceNameAndTP
@Override
public void onDnsSdTxtRecordAvailable(String serviceFullDomainName, Map<String, String> record, WifiP2pDevice device) {

for(SalutDevice found : foundDevices)
if(!foundDevices.isEmpty())
{
if(found.deviceName.equals(device.deviceName))
for(SalutDevice found : foundDevices)
{
return;
if(found.deviceName.equals(device.deviceName))
{
return;
}
}
}

Expand All @@ -682,7 +690,7 @@ public void onDnsSdTxtRecordAvailable(String serviceFullDomainName, Map<String,
onDeviceFound.call();
firstDeviceAlreadyFound = true;
}
else if(firstDeviceAlreadyFound && callContinously)
else if(callContinously)
{
onDeviceFound.call();
}
Expand Down Expand Up @@ -716,9 +724,15 @@ public void onDnsSdServiceAvailable(String instanceName, String serviceNameAndTP
@Override
public void onDnsSdTxtRecordAvailable(String serviceFullDomainName, Map<String, String> record, WifiP2pDevice device) {

for(SalutDevice found : foundDevices) {
if (found.deviceName.equals(device.deviceName)) {
return;

if(!foundDevices.isEmpty())
{
for(SalutDevice found : foundDevices)
{
if(found.deviceName.equals(device.deviceName))
{
return;
}
}
}

Expand All @@ -732,7 +746,7 @@ public void onDnsSdTxtRecordAvailable(String serviceFullDomainName, Map<String,
onDeviceFound.call(foundDevice);
firstDeviceAlreadyFound = true;
}
else if(firstDeviceAlreadyFound && callContinously)
else if(callContinously)
{
onDeviceFound.call(foundDevice);
}
Expand Down Expand Up @@ -768,6 +782,8 @@ public void run() {

private void discoverNetworkServices(final SalutCallback deviceNotSupported)
{
isDiscovering = true;

foundDevices.clear();

if(!receiverRegistered)
Expand Down Expand Up @@ -883,6 +899,8 @@ public void onSuccess() {

public void stopServiceDiscovery(boolean shouldUnregister)
{
isDiscovering = false;

if(isConnectedToAnotherDevice)
disconnectFromDevice();

Expand Down

0 comments on commit f890508

Please sign in to comment.