Search in sources :

Example 1 with ServiceConfig

use of com.connectsdk.service.config.ServiceConfig in project butter-android by butterproject.

the class NetcastTVService method connect.

@Override
public void connect() {
    if (state != State.INITIAL) {
        Log.w(Util.T, "already connecting; not trying to connect again: " + state);
        // don't try to connect again while connected
        return;
    }
    if (!(serviceConfig instanceof NetcastTVServiceConfig)) {
        ServiceConfig.ServiceConfigListener serviceConfigListener = serviceConfig.getListener();
        serviceConfig = new NetcastTVServiceConfig(serviceConfig.getServiceUUID());
        serviceConfig.setListener(serviceConfigListener);
    }
    if (DiscoveryManager.getInstance().getPairingLevel() == PairingLevel.ON) {
        if (((NetcastTVServiceConfig) serviceConfig).getPairingKey() != null && ((NetcastTVServiceConfig) serviceConfig).getPairingKey().length() != 0) {
            sendPairingKey(((NetcastTVServiceConfig) serviceConfig).getPairingKey());
        } else {
            showPairingKeyOnTV();
        }
        Util.runInBackground(new Runnable() {

            @Override
            public void run() {
                httpServer = new NetcastHttpServer(NetcastTVService.this, getServiceDescription().getPort(), mTextChangedListener);
                httpServer.setSubscriptions(subscriptions);
                httpServer.start();
            }
        });
    } else {
        hConnectSuccess();
    }
}
Also used : NetcastHttpServer(com.connectsdk.service.netcast.NetcastHttpServer) NetcastTVServiceConfig(com.connectsdk.service.config.NetcastTVServiceConfig) ServiceConfig(com.connectsdk.service.config.ServiceConfig) NetcastTVServiceConfig(com.connectsdk.service.config.NetcastTVServiceConfig)

Example 2 with ServiceConfig

use of com.connectsdk.service.config.ServiceConfig in project butter-android by butterproject.

the class DiscoveryManager method addServiceDescriptionToDevice.

@SuppressWarnings("unchecked")
public void addServiceDescriptionToDevice(ServiceDescription desc, ConnectableDevice device) {
    Log.d(Util.T, "Adding service " + desc.getServiceID() + " to device with address " + device.getIpAddress() + " and id " + device.getId());
    Class<? extends DeviceService> deviceServiceClass = deviceClasses.get(desc.getServiceID());
    if (deviceServiceClass == null)
        return;
    if (deviceServiceClass == DLNAService.class) {
        if (desc.getLocationXML() == null)
            return;
    } else if (deviceServiceClass == NetcastTVService.class) {
        if (!isNetcast(desc))
            return;
    }
    ServiceConfig serviceConfig = null;
    if (connectableDeviceStore != null)
        serviceConfig = connectableDeviceStore.getServiceConfig(desc);
    if (serviceConfig == null)
        serviceConfig = new ServiceConfig(desc);
    serviceConfig.setListener(DiscoveryManager.this);
    boolean hasType = false;
    boolean hasService = false;
    for (DeviceService service : device.getServices()) {
        if (service.getServiceDescription().getServiceID().equals(desc.getServiceID())) {
            hasType = true;
            if (service.getServiceDescription().getUUID().equals(desc.getUUID())) {
                hasService = true;
            }
            break;
        }
    }
    if (hasType) {
        if (hasService) {
            device.setServiceDescription(desc);
            DeviceService alreadyAddedService = device.getServiceByName(desc.getServiceID());
            if (alreadyAddedService != null)
                alreadyAddedService.setServiceDescription(desc);
            return;
        }
        device.removeServiceByName(desc.getServiceID());
    }
    DeviceService deviceService = DeviceService.getService(deviceServiceClass, desc, serviceConfig);
    if (deviceService != null) {
        deviceService.setServiceDescription(desc);
        device.addService(deviceService);
    }
}
Also used : NetcastTVService(com.connectsdk.service.NetcastTVService) ServiceConfig(com.connectsdk.service.config.ServiceConfig) DeviceService(com.connectsdk.service.DeviceService)

Example 3 with ServiceConfig

use of com.connectsdk.service.config.ServiceConfig 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;
}
Also used : ServiceDescription(com.connectsdk.service.config.ServiceDescription) InvocationTargetException(java.lang.reflect.InvocationTargetException) JSONObject(org.json.JSONObject) ServiceConfig(com.connectsdk.service.config.ServiceConfig)

Aggregations

ServiceConfig (com.connectsdk.service.config.ServiceConfig)3 DeviceService (com.connectsdk.service.DeviceService)1 NetcastTVService (com.connectsdk.service.NetcastTVService)1 NetcastTVServiceConfig (com.connectsdk.service.config.NetcastTVServiceConfig)1 ServiceDescription (com.connectsdk.service.config.ServiceDescription)1 NetcastHttpServer (com.connectsdk.service.netcast.NetcastHttpServer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 JSONObject (org.json.JSONObject)1