I'm develop an android app that communicates with the server using a protocol WebSocket. I use AsyncAndroid lib. WebSocket has listener, that receive data from server.
Something like this
private WebSocket.StringCallback mStringCallback = new WebSocket.StringCallback() {
@Override
public void onStringAvailable(String s) {
}
};
I need write api this, and i want use rxjava. But i cannot imagine, that should be Observable, and that Observer. i tried to do Observable string received from server into WebSocket listener, but i think it is bad idea. Are there any ideas how correctly build api. Thank u.
You could wrap
WebSocket
into a new interface like this:Then in a
RxWebSocket
implementation you can usePublishSubject
with an internalWebSocket.StringCallback
to publish the Strings.