Skip to content
This repository has been archived by the owner on Sep 6, 2020. It is now read-only.

Changed endpoints in SocketIOClient emits to be optional #24

Merged
merged 1 commit into from
Jul 5, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/com/codebutler/android_websockets/SocketIOClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ public void emit(String name, JSONArray args) throws JSONException {
}

public void emit(String name, JSONArray args, final Acknowledge acknowledge) throws JSONException {

emit(name, args, acknowledge, null);
}

public void emit(String name, JSONArray args, final Acknowledge acknowledge, final String endpoint) throws JSONException {

final JSONObject event = new JSONObject();
event.put("name", name);
event.put("args", args);
Expand All @@ -135,7 +141,7 @@ public void emit(String name, JSONArray args, final Acknowledge acknowledge) thr
mSendHandler.post(new Runnable() {
@Override
public void run() {
mClient.send(String.format("5:" + nextId + (acknowledge == null ? "" : "+") +":%s:%s", (mEndpoint == null ? "" : mEndpoint), event.toString()));
mClient.send(String.format("5:" + nextId + (acknowledge == null ? "" : "+") + ":%s:%s", (endpoint == null ? "" : endpoint), event.toString()));
}
});
}
Expand All @@ -146,6 +152,11 @@ public void emit(final JSONObject jsonMessage) throws JSONException {

public void emit(final JSONObject jsonMessage, final Acknowledge acknowledge) throws JSONException {

emit(jsonMessage, acknowledge, null);
}

public void emit(final JSONObject jsonMessage, final Acknowledge acknowledge, final String endpoint) throws JSONException {

final int nextId = getNextMessageId();
if (acknowledge != null) {
mAcknowledges.put(nextId, acknowledge);
Expand All @@ -154,7 +165,7 @@ public void emit(final JSONObject jsonMessage, final Acknowledge acknowledge) th

@Override
public void run() {
mClient.send(String.format("4:" + nextId + (acknowledge == null ? "" : "+") + ":%s:%s", (mEndpoint == null ? "" : mEndpoint), jsonMessage.toString()));
mClient.send(String.format("4:" + nextId + (acknowledge == null ? "" : "+") + ":%s:%s", (endpoint == null ? "" : endpoint), jsonMessage.toString()));
}
});
}
Expand All @@ -165,6 +176,11 @@ public void emit(final String message) {

public void emit(final String message, final Acknowledge acknowledge) {

emit(message, acknowledge, null);
}

public void emit(final String message, final Acknowledge acknowledge, final String endpoint) {

final int nextId = getNextMessageId();
if (acknowledge != null) {
mAcknowledges.put(nextId, acknowledge);
Expand All @@ -173,7 +189,7 @@ public void emit(final String message, final Acknowledge acknowledge) {

@Override
public void run() {
mClient.send(String.format("3:" + nextId + (acknowledge == null ? "" : "+") +":%s:%s", (mEndpoint == null ? "" : mEndpoint), message));
mClient.send(String.format("3:" + nextId + (acknowledge == null ? "" : "+") + ":%s:%s", (endpoint == null ? "" : endpoint), message));
}
});
}
Expand Down