Permalink
Browse files

setting default channel and message

  • Loading branch information...
1 parent 3aff33e commit 7c7337804dee766daa0f1ed2a42303e96a5612a0 unknown committed Sep 28, 2012
@@ -1,12 +1,10 @@
package pubnub;
public interface Callback {
-
public abstract void publishCallback(String channel,Object message,Object responce);
public abstract void subscribeCallback(String channel,Object message);
public abstract void historyCallback(String channel,Object message);
public abstract void errorCallback(String channel, Object message);
-
public abstract void connectCallback(String channel);
public abstract void reconnectCallback(String channel);
public abstract void disconnectCallback(String channel);
@@ -580,7 +580,6 @@ public void unsubscribe(Hashtable args) {
break;
}
}
-
for (int i = 0; i < _connection.size(); i++) {
HttpCallback cb = (HttpCallback) _connection.elementAt(i);
if (cb.getChannel().equals(channel)) {
@@ -632,9 +631,7 @@ private String getURL(Vector url_components) {
* @return JSONArray from JSON response.
*/
private void _request(Vector url_components, final String channel1,Object message) {
-
String request_for = (String) url_components.elementAt(0);
-
if (request_for.equals("subscribe")) {
current_timetoken = (String) url_components.elementAt(4);
}
@@ -655,12 +652,9 @@ private void _request(Vector url_components, final String channel1,Object messag
_headers.put("Accept-Encoding", "gzip");
_headers.put("Connection", "close");
-
HttpCallback callback = new HttpCallback(url.toString(), _headers, request_for) {
-
public void processResponse(HttpConnection conn, Object cookie) throws IOException {
}
-
public void OnComplet(HttpConnection hc, String response, String req_for, String channel) throws IOException {
try {
JSONArray out = null;
@@ -669,7 +663,6 @@ public void OnComplet(HttpConnection hc, String response, String req_for, String
if (!req_for.equals("presence")) {
out = new JSONArray(response);
}
-
} else {
out = null;
}
@@ -766,7 +759,6 @@ void subscribeComplet(JSONArray out, String channel) {
if (!it.connected && it.first) {
subscriptions.removeElement(it);
if (_callback != null) {
-
_callback.disconnectCallback(channel);
}
is_disconnect = true;
@@ -779,7 +771,6 @@ void subscribeComplet(JSONArray out, String channel) {
return;
}
-
// Problem?
if (out == null || out.optInt(1) == 0) {
@@ -814,7 +805,6 @@ void subscribeComplet(JSONArray out, String channel) {
args.put("timetoken", current_timetoken + "");
}
-
_subscribe(args);
is_reconnected = true;
break;
@@ -838,7 +828,6 @@ void subscribeComplet(JSONArray out, String channel) {
}
}
}
-
JSONArray messages = out.optJSONArray(0);
// Update TimeToken
@@ -936,7 +925,6 @@ private void hereNowComplet(String response, String channel) {
callback.setChannel(channel1);
}
-
if (request_for.equals("publish")) {
callback.setMessage(message);
}
@@ -1009,9 +997,7 @@ public String encode(String s, String enc)
int maxBytesPerChar = 10; // rather arbitrary limit, but safe for now
StringBuffer out = new StringBuffer(s.length());
ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);
-
OutputStreamWriter writer = new OutputStreamWriter(buf, enc);
-
for (int i = 0; i < s.length(); i++) {
int c = (int) s.charAt(i);
if (dontNeedEncoding(c)) {
@@ -24,7 +24,7 @@
private Command detailedHistoryCommand;
private Form form;
private StringItem stringItem;
- String Channel = "hello";
+ String Channel = "hello_world";
public PubnubTestMIDlet() {
}
@@ -178,8 +178,7 @@ public Command getPublishCommand() {
*/
public Command getTimeCommand() {
if (timeCommand == null) {
- timeCommand = new Command("Time", Command.ITEM, 2);// GEN-LINE:|27-getter|1|27-postInit
- // GEN-LINE:|7-commandAction|13|7-postCommandAction
+ timeCommand = new Command("Time", Command.ITEM, 2);
}
return timeCommand;
}
@@ -282,10 +281,8 @@ public void destroyApp(boolean unconditional) {
public void publish() {
try {
- // Create JSON Message
JSONObject message = new JSONObject();
- // Create HashMap parameter
- message.put("some_key", "Hello World!");
+ message.put("some_key", "j2me says hello, world!");
Hashtable args = new Hashtable(2);
args.put("channel", Channel); // Channel Name
@@ -402,14 +399,12 @@ public void subscribeCallback(String channel, Object message) {
public void historyCallback(String channel, Object message) {
JSONArray meg = (JSONArray) message;
System.out.println("History recevie on channel:" + channel + " Message:" + meg.toString());
-
stringItem.setLabel("History");
stringItem.setText("History recevie on channel:" + channel + "\n" + meg.toString());
}
public void errorCallback(String channel, Object message) {
System.out.println("Error on channel:" + channel + " Message:" + message.toString());
-
}
public void connectCallback(String channel) {
@@ -438,6 +433,4 @@ public void detailedHistoryCallback(String channel, Object message) {
stringItem.setLabel("DetailedHistory");
stringItem.setText("channel:" + channel + "\n" + message);
}
-
-
}
@@ -1,5 +1,5 @@
MIDlet-1: PubnubTestMIDlet,,test.PubnubTestMIDlet
-MIDlet-Jar-Size: 136284
+MIDlet-Jar-Size: 136299
MIDlet-Jar-URL: Pubnub-J2me.jar
MIDlet-Name: Pubnub-J2me
MIDlet-Permissions: javax.microedition.io.Connector.https, javax.microedition.io.Connector.http
Binary file not shown.
@@ -0,0 +1,9 @@
+MIDlet-1: PubnubTestMIDlet,,test.PubnubTestMIDlet
+MIDlet-Jar-Size: 136299
+MIDlet-Jar-URL: Pubnub-J2me.jar
+MIDlet-Name: Pubnub-J2me
+MIDlet-Permissions: javax.microedition.io.Connector.https, javax.microedition.io.Connector.http
+MIDlet-Vendor: Vendor
+MIDlet-Version: 1.0
+MicroEdition-Configuration: CLDC-1.1
+MicroEdition-Profile: MIDP-2.0
Binary file not shown.
Oops, something went wrong.

0 comments on commit 7c73378

Please sign in to comment.