Scarlet
Scarlet copied to clipboard
Unable to send message after open the socket ?
I try to send a message after open the socket but nothing happened?
Could anyone help on this ?
Open the socket : ``` RetrofitHub.chatServices?.observeWebSocketEvent() ?.observeOn(AndroidSchedulers.mainThread()) ?.subscribeOn(Schedulers.io()) ?.subscribe({ Log.d("BKS-1", it.toString())
}, {
Log.d("BKS-2", it.toString())
})
Send the message :
RetrofitHub.chatServices?.sendChatMessage(
SendMessageRequest(
SystemClock.currentThreadTimeMillis().toInt(),
"Kalanidhi M")
)l̥
interface ChatServices { @Receive fun observeWebSocketEvent(): Flowable<WebSocket.Event>
@Send
fun sendChatMessage(sendMessageRequest: SendMessageRequest)
@Receive
fun observeSendMessage(): Flowable<SendMessageResponse>
}
val chatServices by lazy { scarletInstance?.create<ChatServices>() }
val b = OkHttpClient().newBuilder()
.addInterceptor(getLoggingInterceptor())
val c = b.build()
scarletInstance =
Scarlet.Builder()
.webSocketFactory(c.newWebSocketFactory(WebConstants.CHAT_URL))
.addMessageAdapterFactory(MoshiMessageAdapter.Factory())
.addStreamAdapterFactory(RxJava2StreamAdapterFactory())
.build()
Try having a look at the presenter from the demo, https://github.com/Tinder/Scarlet/blob/master/demo/src/main/java/com/tinder/app/echo/presenter/EchoBotPresenter.kt .
and the echo bot fragment .
https://github.com/Tinder/Scarlet/blob/3ddd11441e4fc0eeb7b4c8dc38b1ac8c4f6ba5c3/demo/src/main/java/com/tinder/app/echo/view/EchoBotFragment.kt .
One is setting up the stream and the other is just calling it.