use of com.connectsdk.service.DeviceService.PairingType in project butter-android by butterproject.
the class WebOSTVServiceSocketClient method sendRegister.
protected void sendRegister() {
ResponseListener<Object> listener = new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
state = State.INITIAL;
if (mListener != null)
mListener.onRegistrationFailed(error);
}
@Override
public void onSuccess(Object object) {
if (object instanceof JSONObject) {
PairingType pairingType = PairingType.NONE;
JSONObject jsonObj = (JSONObject) object;
String type = jsonObj.optString("pairingType");
if (type.equalsIgnoreCase("PROMPT")) {
pairingType = PairingType.FIRST_SCREEN;
} else if (type.equalsIgnoreCase("PIN")) {
pairingType = PairingType.PIN_CODE;
}
if (mListener != null)
mListener.onBeforeRegister(pairingType);
}
}
};
int dataId = this.nextRequestId++;
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, null, null, listener);
command.setRequestId(dataId);
JSONObject headers = new JSONObject();
JSONObject payload = new JSONObject();
try {
headers.put("type", "register");
headers.put("id", dataId);
if (!(mService.getServiceConfig() instanceof WebOSTVServiceConfig)) {
mService.setServiceConfig(new WebOSTVServiceConfig(mService.getServiceConfig().getServiceUUID()));
}
if (((WebOSTVServiceConfig) mService.getServiceConfig()).getClientKey() != null) {
payload.put("client-key", ((WebOSTVServiceConfig) mService.getServiceConfig()).getClientKey());
}
if (PairingType.PIN_CODE.equals(mService.getPairingType())) {
payload.put("pairingType", "PIN");
}
if (manifest != null) {
payload.put("manifest", manifest);
}
} catch (JSONException e) {
e.printStackTrace();
}
requests.put(dataId, command);
sendMessage(headers, payload);
}
Aggregations