Socket.IO callback function support
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.
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:
I really ought to build out a proper event.Emitter for Java and provide that.
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!!
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
Woow, that's great!! Thanks a lot!!
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