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();
}
}
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();
}
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;
}
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();
}
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);
}
});
}
Aggregations