Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSONObject parameter to subscription function parameter #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions src/main/java/io/github/sac/Socket.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,25 @@ public void run() {
return this;
}

private Socket subscribe(final String channel, JSONObject object, final Ack ack) {
EventThread.exec(new Runnable() {
public void run() {
JSONObject subscribeObject = new JSONObject();
try {
subscribeObject.put("event", "#subscribe");
acks.put(counter.longValue(), getAckObject(channel, ack));
object.put("channel", channel);
subscribeObject.put("data", object);
subscribeObject.put("cid", counter.getAndIncrement());
} catch (JSONException e) {
e.printStackTrace();
}
ws.sendText(subscribeObject.toString());
}
});
return this;
}

private Socket unsubscribe(final String channel) {
EventThread.exec(new Runnable() {
public void run() {
Expand Down Expand Up @@ -584,6 +603,10 @@ public void subscribe(Ack ack) {
Socket.this.subscribe(channelName, ack);
}

public void subscribe(JSONObject object, Ack ack) {
Socket.this.subscribe(channelName, object, ack);
}

public void onMessage(Listener listener) {
Socket.this.onSubscribe(channelName, listener);
}
Expand Down