Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimsn98 committed May 9, 2020
1 parent dc41759 commit 2901dae
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,37 @@ I have created this library to communicate the apps with their own backends. All
interface SocketService {

@SendEvent("echo")
fun sendEcho(@Field("name") name: String,
@Field("surname") surname: String)
fun sendEcho(
@Field("name") name: String,
@Field("surname") surname: String
)

@ReceiveEvent("echo")
fun receiveEcho(): Observable<Response>
suspend fun receiveEcho(): Flow<Response>
}
```

- Use Achilles to create an implementation:
```kotlin
val achilles = Achilles.Builder()
.baseUrl("wss://echo.websocket.org")
.client(OkHttpClient().newBuilder().build())
.encodePayload(true)
.logTraffic(true)
.build()

val service = achilles.create(SocketService::class.java)
val achilles = Achilles.Builder()
.baseUrl("wss://echo.websocket.org")
.client(OkHttpClient().newBuilder().build())
.encodePayload(true)
.logTraffic(true)
.build()

val service = achilles.create(SocketService::class.java)
```

- Send and observe socket event data
```kotlin
disposable.add(service.receiveEcho()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
// TODO
}, {
// Handle error
}))

service.sendEcho("Mark", "Bond")
CoroutineScope(IO).launch {
service.receiveEcho().onEach {
Log.d("MainActivity", "Response: $it")
}

service.sendEcho("Name", "Surname")
}
```


Expand Down

0 comments on commit 2901dae

Please sign in to comment.