- Notifications
You must be signed in to change notification settings - Fork1
gorgexec/RxSocketIO
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Simple RxJava2 socket.io library wrapper oversocket.io-client-java library.
repositories { jcenter()}dependencies { implementation'com.gorgexec.rxsocketio:rxsocketio:1.0.0'}
//collection of server events to handleCollection<String>events =newArraySet<>();events.add("login");events.add("new message");events.add("logout");//socket initializationRxSocketIosocket =RxSocketIo.create("http://localhost",events);//subscribing socket statedisposable.add(socket.observeState() .subscribe(this::onState));//subscribing socket incoming messages from serverdisposable.add(socket.observeMessages() .subscribe(this::onIncomingMessage));socket.connect();
You can set a socket with additional options. It is the originalSocket.IO-client liblary object:
IO.Optionsoptions =newIO.Options();options.timeout =50000;RxSocketIosocket =RxSocketIo.create("http://localhost",events,options);
Full options description is availablehere
Sending message:
socket.emit("new message",message);
Handling incoming messages:
privatevoidonIncomingMessage(SocketEventsocketEvent){StringeventName =socketEvent.name();switch (eventName){case"new message":for(Objectobj:socketEvent.data()) {//do something }break;case"logout":socket.disconnect();break; }}
TBD
About
RxJava socket.io library wrapper
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published