Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set the url of connect #187

Open
gzhhong opened this issue Jun 13, 2021 · 1 comment
Open

set the url of connect #187

gzhhong opened this issue Jun 13, 2021 · 1 comment

Comments

@gzhhong
Copy link

gzhhong commented Jun 13, 2021

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?

Thanks,

James

@Warhedgehog
Copy link

Did you ever find a solution ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants