use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSTVService method sendMessage.
@SuppressWarnings("unused")
private void sendMessage(Object message, LaunchSession launchSession, ResponseListener<Object> listener) {
if (launchSession == null || launchSession.getAppId() == null) {
Util.postError(listener, new ServiceCommandError(0, "Must provide a valid LaunchSession object", null));
return;
}
if (message == null) {
Util.postError(listener, new ServiceCommandError(0, "Cannot send a null message", null));
return;
}
if (socket == null) {
connect();
}
String appId = launchSession.getAppId();
String fullAppId = appId;
if (launchSession.getSessionType() == LaunchSessionType.WebApp)
fullAppId = mAppToAppIdMappings.get(appId);
if (fullAppId == null || fullAppId.length() == 0) {
Util.postError(listener, new ServiceCommandError(-1, "You must provide a valid LaunchSession to send messages to", null));
return;
}
JSONObject payload = new JSONObject();
try {
payload.put("type", "p2p");
payload.put("to", fullAppId);
payload.put("payload", message);
} catch (JSONException e) {
e.printStackTrace();
}
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, null, payload, true, listener);
sendCommand(request);
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSTVService method launchAppWithInfo.
@Override
public void launchAppWithInfo(final AppInfo appInfo, Object params, final Launcher.AppLaunchListener listener) {
String uri = "ssap://system.launcher/launch";
JSONObject payload = new JSONObject();
final String appId = appInfo.getId();
String contentId = null;
if (params != null) {
try {
contentId = (String) ((JSONObject) params).get("contentId");
} catch (JSONException e) {
e.printStackTrace();
}
}
try {
payload.put("id", appId);
if (contentId != null)
payload.put("contentId", contentId);
if (params != null)
payload.put("params", params);
} catch (JSONException e) {
e.printStackTrace();
}
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(appId);
launchSession.setSessionId(obj.optString("sessionId"));
launchSession.setSessionType(LaunchSessionType.App);
Util.postSuccess(listener, launchSession);
}
@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.command.ServiceCommand in project butter-android by butterproject.
the class WebOSTVService method getChannelCurrentProgramInfo.
private ServiceCommand<ResponseListener<Object>> getChannelCurrentProgramInfo(boolean isSubscription, final ProgramInfoListener listener) {
String uri = "ssap://tv/getChannelCurrentProgramInfo";
ServiceCommand<ResponseListener<Object>> request;
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
JSONObject jsonObj = (JSONObject) response;
ProgramInfo programInfo = parseRawProgramInfo(jsonObj);
Util.postSuccess(listener, programInfo);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
if (isSubscription)
request = new URLServiceSubscription<ResponseListener<Object>>(this, uri, null, true, responseListener);
else
request = new ServiceCommand<ResponseListener<Object>>(this, uri, null, true, responseListener);
request.send();
return request;
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSTVService method getProgramList.
private ServiceCommand<ResponseListener<Object>> getProgramList(boolean isSubscription, final ProgramListListener listener) {
ServiceCommand<ResponseListener<Object>> request;
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
try {
JSONObject jsonObj = (JSONObject) response;
JSONObject jsonChannel = (JSONObject) jsonObj.get("channel");
ChannelInfo channel = parseRawChannelData(jsonChannel);
JSONArray programList = (JSONArray) jsonObj.get("programList");
Util.postSuccess(listener, new ProgramList(channel, programList));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
if (isSubscription)
request = new URLServiceSubscription<ResponseListener<Object>>(this, PROGRAM, null, true, responseListener);
else
request = new ServiceCommand<ResponseListener<Object>>(this, PROGRAM, null, true, responseListener);
request.send();
return request;
}
use of com.connectsdk.service.command.ServiceCommand 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();
}
Aggregations