Search in sources :

Example 1 with NetcastTVServiceConfig

use of com.connectsdk.service.config.NetcastTVServiceConfig 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 NetcastTVServiceConfig

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

the class NetcastTVService method sendPairingKey.

@Override
public void sendPairingKey(final String pairingKey) {
    state = State.PAIRING;
    if (!(serviceConfig instanceof NetcastTVServiceConfig)) {
        serviceConfig = new NetcastTVServiceConfig(serviceConfig.getServiceUUID());
    }
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            state = State.PAIRED;
            ((NetcastTVServiceConfig) serviceConfig).setPairingKey(pairingKey);
            hConnectSuccess();
        }

        @Override
        public void onError(ServiceCommandError error) {
            state = State.INITIAL;
            if (listener != null)
                listener.onConnectionFailure(NetcastTVService.this, error);
        }
    };
    String requestURL = getUDAPRequestURL(UDAP_PATH_PAIRING);
    Map<String, String> params = new HashMap<String, String>();
    params.put("name", "hello");
    params.put("value", pairingKey);
    params.put("port", String.valueOf(serviceDescription.getPort()));
    String httpMessage = getUDAPMessageBody(UDAP_API_PAIRING, params);
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, requestURL, httpMessage, responseListener);
    command.send();
}
Also used : HashMap(java.util.HashMap) NetcastTVServiceConfig(com.connectsdk.service.config.NetcastTVServiceConfig) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Aggregations

NetcastTVServiceConfig (com.connectsdk.service.config.NetcastTVServiceConfig)2 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)1 ServiceCommand (com.connectsdk.service.command.ServiceCommand)1 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)1 ServiceConfig (com.connectsdk.service.config.ServiceConfig)1 NetcastHttpServer (com.connectsdk.service.netcast.NetcastHttpServer)1 HashMap (java.util.HashMap)1 JSONObject (org.json.JSONObject)1