-
Notifications
You must be signed in to change notification settings - Fork 270
Ported AndroidAsync Style Socket.IO API to standalone library #26
Conversation
Looks good, though I'm not a huge fan of changing WebSocketClient to WebSocket, and changing the Handler to distinct Callbacks. There's no need to break backwards compatibility there. Was here a reason for doing that? I'd rather the corresponding changes were made in SocketIOClient to support WebSocketClient vs WebSocket. Should be relatively straightforward. |
Your questions:
|
Oh, I thought we looking to move completely away from the old library style. I'll revert some things back to the older style. I'll submit a fix for AndroidAsync as well. Btw, Are you planning to upgrade the README for EventCallbacks? It took me quite a while to figure out that I should be using client.addListener() instead of client.setEventCallback() which seemed to be missing.. I can submit a fix for that too.. but it might take a while as I'll do these only after completing the changes to this library. |
Oh, I completely forgot about the README. I had just updated the tests. I can fix that. |
I'm working on adding the earlier Handler style listener back to SocketIOClient. Would you mind if I renamed the interface to SocketIOCallbacks or SocketIOHandler instead of Handler? |
Go for it |
All right. And one more thing, in AndroidAsync, you can subscribe to events, while in the earlier android-websockets, you'd receive all events. Which one would you prefer to bring into this? If we keep the new version(which I personally prefer), then in the onConnectCompleted(), we'll need to call client.setSocketIOCallbacks(new SocketIOCallbacks());
client.listenForEvents(Arrays.asList("news", "chat")); The final event will still come though |
Sorry, I was confused earlier. I thought you meant android.os.Handler. Right now, none of the events fire back onto the main thread, and I thought you were fixing that. The socket.io callbacks should remain similar to the ones exposed by AndroidAsync. Separate callbacks for Strings, JSON, and Event. And event callbacks are exposed via EventEmitter. What are you trying to solve? |
To clarify, I do not want the old style SocketIOClient.Handler. In retrospect, I found that implementation kludgy. However, I do think that events should be invoked onto the main ui thread. I'll handle that, as I need to do similar for AndroidAsync as well. |
I got confused too.. I thought that you preferred to expose socket messages via the earlier SocketIO.Handler interface.. So I added that in. And I wanted to rename it to SocketIOCallbacks since it was having the same name as an Android system class. Anyway, I'll revert it back.. Won't be too much of a problem. |
Cool, sorry for the confusion. Should have read your comment more thoroughly. I suppose for the purposes of your existing code, you'd want to keep a SocketIOHandler around for easy transition. I think that can just be done outside of the library just as well though. |
Not a problem. I've already removed the interface. As for the callbacks, I'm adding code to invoke them on the main thread now. Or rather, onto the same Handler that is passed to SocketIOClient. |
All right. It should be complete now. Could you review and let me know if I need to make any changes? |
There are changes to WebSocketClient and HybiParser. Member names, package renames, formatting, whitespace, etc. Those shouldn't be in the scope of this change. The websocket/hybiparser should remain as untouched as possible. |
Those are originally created by @codebutler, so I want them to remain in his package prefix. |
Right, I'll fix those. |
HybiParser and WebSocketClient are mostly the same as earlier(apart from the package, which I'll be changing). The parts I did change corresponds to the WebSocketClient#Listener interface to conform to the callback methods in the attach() method in SocketIOConnection. Should I revert those as well? |
WebSocket is still using separate callbacks instead of Listener. I'll leave comments inline |
public class HybiParser { | ||
private static final String TAG = "HybiParser"; | ||
|
||
private WebSocketClient mClient; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rename is unnecessary, let's leave that alone.
If you want to change WebSocket internals around, we should do that in a separate pull request.
Cool, almost there, just need to go back to the original websocket implementation (as much as is reasonably possible) and we can accept. |
FYI I have some patches from someone that cleans up the code a bit and removes the android dependency. codebutler#10 I'd eventually like to get this thing packaged into a proper library (as tinywebsockets or something not-android-specific) and posted on maven central so projects like this could easily depend on it. |
public class WebSocketClient { | ||
private static final String TAG = "WebSocketClient"; | ||
|
||
private URI mURI; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I'm not a fan of the tab/spacing here, let's not change it (or do it in a separate patch). Future merges with codebutler's fork would be a pain.
Try to avoid whitespace changes in general, or put them in a separate pull request so they can be reviewed as they are separate issues. Commits and pull requests should tackle one problem at a time, rather than bunch up a number of different changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry about that. That's my Eclipse formatter. I've got into the habit of hitting Ctrl+Shift+F just before I save and it ends up realigning some stuff. I'll have to fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this may have just been your Eclipse or whatever autoformatting.
@codebutler Awesome, thanks. |
@@ -173,7 +196,7 @@ public void send(byte[] data) { | |||
sendFrame(mParser.frame(data)); | |||
} | |||
|
|||
public boolean isConnected() { | |||
public boolean isOpen() { | |||
return mConnected; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isConnected() method is unchanged from the original. Did you mean to indicate something else?
Yes, isConnected was renamed to isOpen
@koush Done. All switched back to the original WebSocketClient/HybiParser implementation. Changes are limited to the SocketIO classes only. |
Perfect, thanks! |
Ported AndroidAsync Style Socket.IO API to standalone library
I have a few doubts on how to handle certain things -