use of com.connectsdk.service.config.ServiceDescription in project butter-android by butterproject.
the class DeviceService method getService.
@SuppressWarnings("unchecked")
public static DeviceService getService(JSONObject json) {
Class<DeviceService> newServiceClass;
try {
String className = json.optString(KEY_CLASS);
if (className.equalsIgnoreCase("DLNAService"))
return null;
if (className.equalsIgnoreCase("Chromecast"))
return null;
newServiceClass = (Class<DeviceService>) Class.forName(DeviceService.class.getPackage().getName() + "." + className);
Constructor<DeviceService> constructor = newServiceClass.getConstructor(ServiceDescription.class, ServiceConfig.class);
JSONObject jsonConfig = json.optJSONObject(KEY_CONFIG);
ServiceConfig serviceConfig = null;
if (jsonConfig != null)
serviceConfig = ServiceConfig.getConfig(jsonConfig);
JSONObject jsonDescription = json.optJSONObject(KEY_DESC);
ServiceDescription serviceDescription = null;
if (jsonDescription != null)
serviceDescription = ServiceDescription.getDescription(jsonDescription);
if (serviceConfig == null || serviceDescription == null)
return null;
return constructor.newInstance(serviceDescription, serviceConfig);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
use of com.connectsdk.service.config.ServiceDescription in project butter-android by butterproject.
the class SSDPDiscoveryProvider method notifyListenersOfLostService.
private void notifyListenersOfLostService(ServiceDescription service) {
List<String> serviceIds = serviceIdsForFilter(service.getServiceFilter());
for (String serviceId : serviceIds) {
ServiceDescription _newService = service.clone();
_newService.setServiceID(serviceId);
final ServiceDescription newService = _newService;
Util.runOnUI(new Runnable() {
@Override
public void run() {
for (DiscoveryProviderListener listener : serviceListeners) {
listener.onServiceRemoved(SSDPDiscoveryProvider.this, newService);
}
}
});
}
}
use of com.connectsdk.service.config.ServiceDescription in project butter-android by butterproject.
the class SSDPDiscoveryProvider method notifyListenersOfNewService.
private void notifyListenersOfNewService(ServiceDescription service) {
List<String> serviceIds = serviceIdsForFilter(service.getServiceFilter());
for (String serviceId : serviceIds) {
ServiceDescription _newService = service.clone();
_newService.setServiceID(serviceId);
final ServiceDescription newService = _newService;
Util.runOnUI(new Runnable() {
@Override
public void run() {
for (DiscoveryProviderListener listener : serviceListeners) {
listener.onServiceAdded(SSDPDiscoveryProvider.this, newService);
}
}
});
}
}
use of com.connectsdk.service.config.ServiceDescription in project butter-android by butterproject.
the class FireTVDiscoveryProvider method stop.
/**
* Safely stop discovery and remove all found FireTV services because they don't work when
* discovery is stopped. Ignore if it's already stopped.
*/
@Override
public void stop() {
if (isRunning) {
discoveryController.stop();
isRunning = false;
}
for (ServiceDescription serviceDescription : foundServices.values()) {
notifyListenersThatServiceLost(serviceDescription);
}
foundServices.clear();
}
use of com.connectsdk.service.config.ServiceDescription in project butter-android by butterproject.
the class SSDPDiscoveryProvider method handleSSDPPacket.
private void handleSSDPPacket(SSDPPacket ssdpPacket) {
if (ssdpPacket == null || ssdpPacket.getData().size() == 0 || ssdpPacket.getType() == null)
return;
String serviceFilter = ssdpPacket.getData().get(ssdpPacket.getType().equals(SSDPClient.NOTIFY) ? "NT" : "ST");
if (serviceFilter == null || SSDPClient.MSEARCH.equals(ssdpPacket.getType()) || !isSearchingForFilter(serviceFilter))
return;
String usnKey = ssdpPacket.getData().get("USN");
if (usnKey == null || usnKey.length() == 0)
return;
Matcher m = uuidReg.matcher(usnKey);
if (!m.find())
return;
String uuid = m.group();
if (SSDPClient.BYEBYE.equals(ssdpPacket.getData().get("NTS"))) {
final ServiceDescription service = foundServices.get(uuid);
if (service != null) {
foundServices.remove(uuid);
notifyListenersOfLostService(service);
}
} else {
String location = ssdpPacket.getData().get("LOCATION");
if (location == null || location.length() == 0)
return;
ServiceDescription foundService = foundServices.get(uuid);
ServiceDescription discoverdService = discoveredServices.get(uuid);
boolean isNew = foundService == null && discoverdService == null;
if (isNew) {
foundService = new ServiceDescription();
foundService.setUUID(uuid);
foundService.setServiceFilter(serviceFilter);
foundService.setIpAddress(ssdpPacket.getDatagramPacket().getAddress().getHostAddress());
foundService.setPort(3001);
discoveredServices.put(uuid, foundService);
getLocationData(location, uuid, serviceFilter);
}
if (foundService != null)
foundService.setLastDetection(new Date().getTime());
}
}
Aggregations