Search in sources :

Example 6 with LaunchSession

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

the class WebOSTVService method displayMedia.

private void displayMedia(JSONObject params, final MediaPlayer.LaunchListener listener) {
    String uri = "ssap://media.viewer/open";
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            JSONObject obj = (JSONObject) response;
            LaunchSession launchSession = LaunchSession.launchSessionForAppId(obj.optString("id"));
            launchSession.setService(WebOSTVService.this);
            launchSession.setSessionId(obj.optString("sessionId"));
            launchSession.setSessionType(LaunchSessionType.Media);
            Util.postSuccess(listener, new MediaLaunchObject(launchSession, WebOSTVService.this));
        }

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

Example 7 with LaunchSession

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

the class WebOSTVService method launchBrowser.

@Override
public void launchBrowser(String url, final Launcher.AppLaunchListener listener) {
    String uri = "ssap://system.launcher/open";
    JSONObject payload = new JSONObject();
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            JSONObject obj = (JSONObject) response;
            LaunchSession launchSession = new LaunchSession();
            launchSession.setService(WebOSTVService.this);
            // note that response uses id to mean appId
            launchSession.setAppId(obj.optString("id"));
            launchSession.setSessionId(obj.optString("sessionId"));
            launchSession.setSessionType(LaunchSessionType.App);
            launchSession.setRawData(obj);
            Util.postSuccess(listener, launchSession);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    try {
        payload.put("target", url);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    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) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 8 with LaunchSession

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

the class CastService method launchWebApp.

@Override
public void launchWebApp(final String webAppId, final boolean relaunchIfRunning, final WebAppSession.LaunchListener listener) {
    launchingAppId = webAppId;
    final LaunchWebAppListener launchWebAppListener = new LaunchWebAppListener() {

        @Override
        public void onSuccess(WebAppSession webAppSession) {
            Util.postSuccess(listener, webAppSession);
        }

        @Override
        public void onFailure(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ConnectionListener connectionListener = new ConnectionListener() {

        @Override
        public void onConnected() {
            // TODO Workaround, for some reason, if relaunchIfRunning is false, launchApplication returns 2005 error and cannot launch.
            try {
                if (relaunchIfRunning == false) {
                    Cast.CastApi.joinApplication(mApiClient).setResultCallback(new ResultCallback<Cast.ApplicationConnectionResult>() {

                        @Override
                        public void onResult(ApplicationConnectionResult result) {
                            if (result.getStatus().isSuccess() && result.getApplicationMetadata() != null && result.getApplicationMetadata().getName() != null && result.getApplicationMetadata().getApplicationId().equals(webAppId)) {
                                ApplicationMetadata applicationMetadata = result.getApplicationMetadata();
                                currentAppId = applicationMetadata.getApplicationId();
                                LaunchSession launchSession = LaunchSession.launchSessionForAppId(applicationMetadata.getApplicationId());
                                launchSession.setAppName(applicationMetadata.getName());
                                launchSession.setSessionId(result.getSessionId());
                                launchSession.setSessionType(LaunchSessionType.WebApp);
                                launchSession.setService(CastService.this);
                                CastWebAppSession webAppSession = new CastWebAppSession(launchSession, CastService.this);
                                webAppSession.setMetadata(applicationMetadata);
                                sessions.put(applicationMetadata.getApplicationId(), webAppSession);
                                Util.postSuccess(listener, webAppSession);
                            } else {
                                LaunchOptions options = new LaunchOptions();
                                options.setRelaunchIfRunning(true);
                                try {
                                    Cast.CastApi.launchApplication(mApiClient, webAppId, options).setResultCallback(new ApplicationConnectionResultCallback(launchWebAppListener));
                                } catch (Exception e) {
                                    Util.postError(listener, new ServiceCommandError(0, "Unable to launch", null));
                                }
                            }
                        }
                    });
                } else {
                    LaunchOptions options = new LaunchOptions();
                    options.setRelaunchIfRunning(relaunchIfRunning);
                    Cast.CastApi.launchApplication(mApiClient, webAppId, options).setResultCallback(new ApplicationConnectionResultCallback(launchWebAppListener));
                }
            } catch (Exception e) {
                Util.postError(listener, new ServiceCommandError(0, "Unable to launch", null));
            }
        }
    };
    runCommand(connectionListener);
}
Also used : WebAppSession(com.connectsdk.service.sessions.WebAppSession) CastWebAppSession(com.connectsdk.service.sessions.CastWebAppSession) LaunchSession(com.connectsdk.service.sessions.LaunchSession) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) IOException(java.io.IOException) LaunchOptions(com.google.android.gms.cast.LaunchOptions) ApplicationConnectionResult(com.google.android.gms.cast.Cast.ApplicationConnectionResult) ApplicationMetadata(com.google.android.gms.cast.ApplicationMetadata) CastWebAppSession(com.connectsdk.service.sessions.CastWebAppSession)

Example 9 with LaunchSession

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

the class CastService method joinWebApp.

@Override
public void joinWebApp(String webAppId, WebAppSession.LaunchListener listener) {
    LaunchSession launchSession = LaunchSession.launchSessionForAppId(webAppId);
    launchSession.setSessionType(LaunchSessionType.WebApp);
    launchSession.setService(this);
    joinWebApp(launchSession, listener);
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession)

Example 10 with LaunchSession

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

the class DLNAService method decodeLaunchSession.

@Override
public LaunchSession decodeLaunchSession(String type, JSONObject sessionObj) throws JSONException {
    if (type.equals("dlna")) {
        LaunchSession launchSession = LaunchSession.launchSessionFromJSONObject(sessionObj);
        launchSession.setService(this);
        return launchSession;
    }
    return null;
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession)

Aggregations

LaunchSession (com.connectsdk.service.sessions.LaunchSession)17 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)12 JSONObject (org.json.JSONObject)10 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)9 ServiceCommand (com.connectsdk.service.command.ServiceCommand)9 JSONException (org.json.JSONException)6 HashMap (java.util.HashMap)4 AppInfo (com.connectsdk.core.AppInfo)2 WebOSWebAppSession (com.connectsdk.service.sessions.WebOSWebAppSession)2 IOException (java.io.IOException)2 PListBuilder (com.connectsdk.service.airplay.PListBuilder)1 CastWebAppSession (com.connectsdk.service.sessions.CastWebAppSession)1 WebAppSession (com.connectsdk.service.sessions.WebAppSession)1 ApplicationMetadata (com.google.android.gms.cast.ApplicationMetadata)1 ApplicationConnectionResult (com.google.android.gms.cast.Cast.ApplicationConnectionResult)1 LaunchOptions (com.google.android.gms.cast.LaunchOptions)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1