Skip to content

Commit

Permalink
setting default channel and message
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Sep 28, 2012
1 parent 3aff33e commit 7c73378
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 223 deletions.
2 changes: 0 additions & 2 deletions j2me/3.3/j2me/build/preprocessed/pubnub/Callback.java
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
14 changes: 0 additions & 14 deletions j2me/3.3/j2me/build/preprocessed/pubnub/Pubnub.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -779,7 +771,6 @@ void subscribeComplet(JSONArray out, String channel) {
return;
}


// Problem?
if (out == null || out.optInt(1) == 0) {

Expand Down Expand Up @@ -814,7 +805,6 @@ void subscribeComplet(JSONArray out, String channel) {
args.put("timetoken", current_timetoken + "");

}

_subscribe(args);
is_reconnected = true;
break;
Expand All @@ -838,7 +828,6 @@ void subscribeComplet(JSONArray out, String channel) {
}
}
}

JSONArray messages = out.optJSONArray(0);

// Update TimeToken
Expand Down Expand Up @@ -936,7 +925,6 @@ private void hereNowComplet(String response, String channel) {
callback.setChannel(channel1);

}

if (request_for.equals("publish")) {
callback.setMessage(message);
}
Expand Down Expand Up @@ -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)) {
Expand Down
13 changes: 3 additions & 10 deletions j2me/3.3/j2me/build/preprocessed/test/PubnubTestMIDlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PubnubTestMIDlet extends MIDlet implements CommandListener, Callbac
private Command detailedHistoryCommand;
private Form form;
private StringItem stringItem;
String Channel = "hello";
String Channel = "hello_world";

public PubnubTestMIDlet() {
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -438,6 +433,4 @@ public void detailedHistoryCallback(String channel, Object message) {
stringItem.setLabel("DetailedHistory");
stringItem.setText("channel:" + channel + "\n" + message);
}


}
2 changes: 1 addition & 1 deletion j2me/3.3/j2me/dist/Pubnub-J2me.jad
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file modified j2me/3.3/j2me/dist/Pubnub-J2me.jar
Binary file not shown.
9 changes: 9 additions & 0 deletions j2me/3.3/j2me/dist/nbrun7817501402660198190/Pubnub-J2me.jad
Original file line number Diff line number Diff line change
@@ -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.
Loading

0 comments on commit 7c73378

Please sign in to comment.