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();
}
}
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();
}
Aggregations