Search in sources :

Example 1 with WebOSWebAppSession

use of com.connectsdk.service.sessions.WebOSWebAppSession in project butter-android by butterproject.

the class WebOSTVService method disconnect.

@Override
public void disconnect() {
    Log.d(Util.T, "attempting to disconnect to " + serviceDescription.getIpAddress());
    Util.runOnUI(new Runnable() {

        @Override
        public void run() {
            if (listener != null)
                listener.onDisconnect(WebOSTVService.this, null);
        }
    });
    if (socket != null) {
        socket.setListener(null);
        socket.disconnect();
        socket = null;
    }
    if (mAppToAppIdMappings != null)
        mAppToAppIdMappings.clear();
    if (mWebAppSessions != null) {
        Enumeration<WebOSWebAppSession> iterator = mWebAppSessions.elements();
        while (iterator.hasMoreElements()) {
            WebOSWebAppSession session = iterator.nextElement();
            session.disconnectFromWebApp();
        }
        mWebAppSessions.clear();
    }
}
Also used : WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession)

Example 2 with WebOSWebAppSession

use of com.connectsdk.service.sessions.WebOSWebAppSession in project butter-android by butterproject.

the class WebOSTVService method closeWebApp.

@Override
public void closeWebApp(LaunchSession launchSession, final ResponseListener<Object> listener) {
    if (launchSession == null || launchSession.getAppId() == null || launchSession.getAppId().length() == 0) {
        Util.postError(listener, new ServiceCommandError(0, "Must provide a valid launch session", null));
        return;
    }
    final WebOSWebAppSession webAppSession = mWebAppSessions.get(launchSession.getAppId());
    if (webAppSession != null) {
        webAppSession.disconnectFromWebApp();
    }
    String uri = "ssap://webapp/closeWebApp";
    JSONObject payload = new JSONObject();
    try {
        if (launchSession.getAppId() != null)
            payload.put("webAppId", launchSession.getAppId());
        if (launchSession.getSessionId() != null)
            payload.put("sessionId", launchSession.getSessionId());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, true, listener);
    request.send();
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) JSONObject(org.json.JSONObject) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 3 with WebOSWebAppSession

use of com.connectsdk.service.sessions.WebOSWebAppSession in project butter-android by butterproject.

the class WebOSTVService method webAppSessionForLaunchSession.

private WebOSWebAppSession webAppSessionForLaunchSession(LaunchSession launchSession) {
    if (mWebAppSessions == null)
        mWebAppSessions = new ConcurrentHashMap<String, WebOSWebAppSession>();
    if (launchSession.getService() == null)
        launchSession.setService(this);
    WebOSWebAppSession webAppSession = mWebAppSessions.get(launchSession.getAppId());
    if (webAppSession == null) {
        webAppSession = new WebOSWebAppSession(launchSession, this);
        mWebAppSessions.put(launchSession.getAppId(), webAppSession);
    }
    return webAppSession;
}
Also used : WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with WebOSWebAppSession

use of com.connectsdk.service.sessions.WebOSWebAppSession in project butter-android by butterproject.

the class WebOSTVService method launchWebApp.

public void launchWebApp(final String webAppId, final JSONObject params, final WebAppSession.LaunchListener listener) {
    if (webAppId == null || webAppId.length() == 0) {
        Util.postError(listener, new ServiceCommandError(-1, "You need to provide a valid webAppId.", null));
        return;
    }
    final WebOSWebAppSession _webAppSession = mWebAppSessions.get(webAppId);
    String uri = "ssap://webapp/launchWebApp";
    JSONObject payload = new JSONObject();
    try {
        payload.put("webAppId", webAppId);
        if (params != null)
            payload.put("urlParams", params);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(final Object response) {
            JSONObject obj = (JSONObject) response;
            LaunchSession launchSession = null;
            WebOSWebAppSession webAppSession = _webAppSession;
            if (webAppSession != null)
                launchSession = webAppSession.launchSession;
            else {
                launchSession = LaunchSession.launchSessionForAppId(webAppId);
                webAppSession = new WebOSWebAppSession(launchSession, WebOSTVService.this);
                mWebAppSessions.put(webAppId, webAppSession);
            }
            launchSession.setService(WebOSTVService.this);
            launchSession.setSessionId(obj.optString("sessionId"));
            launchSession.setSessionType(LaunchSessionType.WebApp);
            launchSession.setRawData(obj);
            Util.postSuccess(listener, webAppSession);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, true, responseListener);
    request.send();
}
Also used : JSONObject(org.json.JSONObject) LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) JSONObject(org.json.JSONObject) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 5 with WebOSWebAppSession

use of com.connectsdk.service.sessions.WebOSWebAppSession in project butter-android by butterproject.

the class WebOSTVService method connectToApp.

/* Connect to a native/installed webOS app */
public void connectToApp(String appId, final WebAppSession.LaunchListener listener) {
    LaunchSession launchSession = LaunchSession.launchSessionForAppId(appId);
    launchSession.setSessionType(LaunchSessionType.App);
    launchSession.setService(this);
    final WebOSWebAppSession webAppSession = webAppSessionForLaunchSession(launchSession);
    connectToWebApp(webAppSession, false, new ResponseListener<Object>() {

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }

        @Override
        public void onSuccess(Object object) {
            Util.postSuccess(listener, webAppSession);
        }
    });
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession)

Aggregations

WebOSWebAppSession (com.connectsdk.service.sessions.WebOSWebAppSession)6 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)4 JSONObject (org.json.JSONObject)4 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)2 ServiceCommand (com.connectsdk.service.command.ServiceCommand)2 LaunchSession (com.connectsdk.service.sessions.LaunchSession)2 JSONException (org.json.JSONException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1