Search in sources :

Example 1 with PairingType

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);
}
Also used : JSONObject(org.json.JSONObject) WebOSTVServiceConfig(com.connectsdk.service.config.WebOSTVServiceConfig) PairingType(com.connectsdk.service.DeviceService.PairingType) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 PairingType (com.connectsdk.service.DeviceService.PairingType)1 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)1 ServiceCommand (com.connectsdk.service.command.ServiceCommand)1 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)1 WebOSTVServiceConfig (com.connectsdk.service.config.WebOSTVServiceConfig)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1