Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RxJava socket.io library wrapper

NotificationsYou must be signed in to change notification settings

gorgexec/RxSocketIO

Repository files navigation

Simple RxJava2 socket.io library wrapper oversocket.io-client-java library.

Install

Gradle

repositories {    jcenter()}dependencies {  implementation'com.gorgexec.rxsocketio:rxsocketio:1.0.0'}

Usage

//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;    }}

Sample App

TBD

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2026 Movatter.jp