diff --git a/src/main/java/io/github/sac/Socket.java b/src/main/java/io/github/sac/Socket.java index d5c4e28..691a3c1 100644 --- a/src/main/java/io/github/sac/Socket.java +++ b/src/main/java/io/github/sac/Socket.java @@ -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() { @@ -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); }