AndroidAsync icon indicating copy to clipboard operation
AndroidAsync copied to clipboard

Socket.IO callback function support

Open handelcamilo opened this issue 13 years ago • 6 comments

Hi,

I have an app using socket.io(nodejs) and most of my socket.on methods(server side) is using the callback function "fn" to retrieve data to the client. There's a way to use those same callback function "fn" to retrieve data to my AndroidAsync client?

Thank you!

ps: sorry about my english.

handelcamilo avatar Jun 05 '13 14:06 handelcamilo

This lib works in the same way:

httpClient = new AsyncHttpClient(AsyncServer.getCurrentThreadServer());
SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), "http://192.168.1.50:3000/", new SocketIOClient.SocketIOConnectCallback() {
   @Override
   public void onConnectCompleted(Exception ex, SocketIOClient client) {
      if (ex != null) {
         ex.printStackTrace();
         return;
      }
      client.setEventCallback(new SocketIOClient.EventCallback() {
      @Override
      public void onEvent(String event, JSONArray arguments) {
         ProcessSIOEvent(event, arguments);
      }
   });
});

In ProcessSIOEvent is that callback method where you can parse event type and call some other handler:

SkeLLLa avatar Jun 06 '13 10:06 SkeLLLa

I really ought to build out a proper event.Emitter for Java and provide that.

koush avatar Jun 06 '13 15:06 koush

SkeLLLa, I did not understand! In my nodejs code I have:

socket.on('any_event', function(dataReceived, fn) { fn('Something'); }

That raise an exception: fn is undefined.

Koush, that would be awesome!!

handelcamilo avatar Jun 07 '13 21:06 handelcamilo

In progress now. I've added a proper EventEmitter, among other features like endpoints and reconnect support.

https://github.com/koush/AndroidAsync/tree/wip/AndroidAsync/src/com/koushikdutta/async/http/socketio

koush avatar Jul 03 '13 00:07 koush

Woow, that's great!! Thanks a lot!!

handelcamilo avatar Jul 03 '13 11:07 handelcamilo

Done:

client.on("pong", new EventCallback() {
    @Override
    public void onEvent(JSONArray arguments, Acknowledge acknowledge) {
    }
});

https://github.com/koush/AndroidAsync/blob/master/AndroidAsync/src/com/koushikdutta/async/http/socketio/EventEmitter.java

koush avatar Jul 04 '13 20:07 koush