use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.
the class WebOSWebAppSession method sendP2PMessage.
private void sendP2PMessage(final Object message, final ResponseListener<Object> listener) {
JSONObject _payload = new JSONObject();
try {
_payload.put("type", "p2p");
_payload.put("to", getFullAppId());
_payload.put("payload", message);
} catch (JSONException ex) {
// do nothing
}
if (isConnected()) {
socket.sendMessage(_payload, null);
Util.postSuccess(listener, null);
} else {
ResponseListener<Object> connectListener = new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
sendP2PMessage(message, listener);
}
};
connect(connectListener);
}
}
use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.
the class WebOSWebAppSession method previous.
@Override
public void previous(final ResponseListener<Object> listener) {
int requestIdNumber = getNextId();
final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
JSONObject message = null;
try {
message = new JSONObject() {
{
put("contentType", namespaceKey + "mediaCommand");
put("mediaCommand", new JSONObject() {
{
put("type", "playPrevious");
put("requestId", requestId);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
return;
}
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, listener);
mActiveCommands.put(requestId, command);
sendMessage(message, listener);
}
use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.
the class WebOSWebAppSession method jumpToTrack.
@Override
public void jumpToTrack(final long index, final ResponseListener<Object> listener) {
int requestIdNumber = getNextId();
final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
JSONObject message = null;
try {
message = new JSONObject() {
{
put("contentType", namespaceKey + "mediaCommand");
put("mediaCommand", new JSONObject() {
{
put("type", "jumpToTrack");
put("requestId", requestId);
put("index", (int) index);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
return;
}
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, listener);
mActiveCommands.put(requestId, command);
sendMessage(message, listener);
}
use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.
the class WebOSWebAppSession method playMedia.
@Override
public void playMedia(final String url, final String mimeType, final String title, final String description, final String iconSrc, final boolean shouldLoop, final MediaPlayer.LaunchListener listener) {
int requestIdNumber = getNextId();
final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
JSONObject message = null;
try {
message = new JSONObject() {
{
putOpt("contentType", namespaceKey + "mediaCommand");
putOpt("mediaCommand", new JSONObject() {
{
putOpt("type", "playMedia");
putOpt("mediaURL", url);
putOpt("iconURL", iconSrc);
putOpt("title", title);
putOpt("description", description);
putOpt("mimeType", mimeType);
putOpt("shouldLoop", shouldLoop);
putOpt("requestId", requestId);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
return;
}
ResponseListener<Object> response = new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
Util.postSuccess(listener, new MediaLaunchObject(launchSession, getMediaControl(), getPlaylistControl()));
}
};
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, response);
mActiveCommands.put(requestId, command);
sendMessage(message, new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
}
});
}
use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.
the class WebOSWebAppSession method displayImage.
@Override
public void displayImage(final String url, final String mimeType, final String title, final String description, final String iconSrc, final MediaPlayer.LaunchListener listener) {
int requestIdNumber = getNextId();
final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
JSONObject message = null;
try {
message = new JSONObject() {
{
putOpt("contentType", namespaceKey + "mediaCommand");
putOpt("mediaCommand", new JSONObject() {
{
putOpt("type", "displayImage");
putOpt("mediaURL", url);
putOpt("iconURL", iconSrc);
putOpt("title", title);
putOpt("description", description);
putOpt("mimeType", mimeType);
putOpt("requestId", requestId);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
return;
}
ResponseListener<Object> response = new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
Util.postSuccess(listener, new MediaLaunchObject(launchSession, getMediaControl()));
}
};
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(socket, null, null, response);
mActiveCommands.put(requestId, command);
sendP2PMessage(message, new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
}
});
}
Aggregations