Search in sources :

Example 1 with WebOSTVServiceSocketClient

use of com.connectsdk.service.webos.WebOSTVServiceSocketClient in project butter-android by butterproject.

the class WebOSTVService method connect.

@Override
public void connect() {
    if (this.socket == null) {
        this.socket = new WebOSTVServiceSocketClient(this, WebOSTVServiceSocketClient.getURI(this));
        this.socket.setListener(mSocketListener);
    }
    if (!this.isConnected())
        this.socket.connect();
}
Also used : WebOSTVServiceSocketClient(com.connectsdk.service.webos.WebOSTVServiceSocketClient)

Example 2 with WebOSTVServiceSocketClient

use of com.connectsdk.service.webos.WebOSTVServiceSocketClient in project butter-android by butterproject.

the class WebOSWebAppSession method connect.

private void connect(final Boolean joinOnly, final ResponseListener<Object> connectionListener) {
    if (socket != null && socket.getState() == WebOSTVServiceSocketClient.State.CONNECTING) {
        if (connectionListener != null) {
            connectionListener.onError(new ServiceCommandError(0, "You have a connection request pending,  please wait until it has finished", null));
        }
        return;
    }
    if (isConnected()) {
        if (connectionListener != null)
            connectionListener.onSuccess(null);
        return;
    }
    mConnectionListener = new ResponseListener<ServiceCommand<ResponseListener<Object>>>() {

        @Override
        public void onError(ServiceCommandError error) {
            if (socket != null)
                disconnectFromWebApp();
            if (connectionListener != null) {
                if (error == null) {
                    error = new ServiceCommandError(0, "Unknown error connecting to web app", null);
                }
                connectionListener.onError(error);
            }
        }

        @Override
        public void onSuccess(ServiceCommand<ResponseListener<Object>> object) {
            ResponseListener<Object> finalConnectionListener = new ResponseListener<Object>() {

                @Override
                public void onError(ServiceCommandError error) {
                    disconnectFromWebApp();
                    if (connectionListener != null)
                        connectionListener.onError(error);
                }

                @Override
                public void onSuccess(Object object) {
                    connected = true;
                    if (connectionListener != null)
                        connectionListener.onSuccess(object);
                }
            };
            service.connectToWebApp(WebOSWebAppSession.this, joinOnly, finalConnectionListener);
        }
    };
    if (socket != null) {
        if (socket.isConnected())
            mConnectionListener.onSuccess(null);
        else
            socket.connect();
    } else {
        socket = new WebOSTVServiceSocketClient(service, WebOSTVServiceSocketClient.getURI(service));
        socket.setListener(mSocketListener);
        socket.connect();
    }
}
Also used : WebOSTVServiceSocketClient(com.connectsdk.service.webos.WebOSTVServiceSocketClient) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) JSONObject(org.json.JSONObject) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Aggregations

WebOSTVServiceSocketClient (com.connectsdk.service.webos.WebOSTVServiceSocketClient)2 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)1 ServiceCommand (com.connectsdk.service.command.ServiceCommand)1 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)1 JSONObject (org.json.JSONObject)1