Hello all, I am working on Android by kotlin to develop a client receiving websocket message. The server team provides sample in python showing that the server side will assign a new url like ws://domain.name/connect/79004032-a52c-4c1a-b305-be12de925318, and the client should call websockets.connect (websockets is a python library) to this url. I didn't find the equivalent function of "connect" in scarlet, when the "connect" action is executed by scarlet and how to define the url of this function? and I am wondering how can I define the url in the functions of my interface by annotation, like what we can do in retrofit, @Url on the paramters of the function.
Take the example of url ws://domain.name/connect/79004032-a52c-4c1a-b305-be12de925318, I want to do something in this way:
@Provides
@Singleton
fun provideScarlet(okHttpClient: OkHttpClient) : Scarlet {
val scarletInstance = Scarlet.Builder()
.webSocketFactory(okHttpClient.newWebSocketFactory("ws://domain.name"))
.addMessageAdapterFactory(GsonMessageAdapter.Factory())
.addStreamAdapterFactory(CoroutinesStreamAdapterFactory())
.build()
return scarletInstance
}
@Provides
@Singleton
fun provideMyWebSocketService(scarlet: Scarlet) : MyWebSocketService {
return scarlet.create(MyWebSocketService::class.java)
}
in MyWebSocketService.kt, I want to define function in this way:
interface MyWebSocketService {
@Receive
fun observeWebSocketEvent(@Url url = "/connect/79004032-a52c-4c1a-b305-be12de925318"): Sequence<WebSocket.Event>
@Receive
fun observeNews(): Sequence<List<News>>
}
Is there a way to do so in scarlet?
Another question, is it possible to use the viewModel lifecycle as lifecycle of my scarlet service?
Hello all, I am working on Android by kotlin to develop a client receiving websocket message. The server team provides sample in python showing that the server side will assign a new url like ws://domain.name/connect/79004032-a52c-4c1a-b305-be12de925318, and the client should call websockets.connect (websockets is a python library) to this url. I didn't find the equivalent function of "connect" in scarlet, when the "connect" action is executed by scarlet and how to define the url of this function? and I am wondering how can I define the url in the functions of my interface by annotation, like what we can do in retrofit, @Url on the paramters of the function. Take the example of url ws://domain.name/connect/79004032-a52c-4c1a-b305-be12de925318, I want to do something in this way:
in MyWebSocketService.kt, I want to define function in this way:
Is there a way to do so in scarlet? Another question, is it possible to use the viewModel lifecycle as lifecycle of my scarlet service?
Thanks,
James