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

Creating a second Service causes socket reconnection #189

Open
tobioyelekan opened this issue Jul 2, 2021 · 1 comment
Open

Creating a second Service causes socket reconnection #189

tobioyelekan opened this issue Jul 2, 2021 · 1 comment

Comments

@tobioyelekan
Copy link

Creating a second Service like this makes the socket reconnect, thereby opening multiple connections

@Provides
@Singleton
fun provideAuthService(scarlet: Scarlet): Service1 {
    return scarlet.create(Service1::class.java)
}

@Provides
@Singleton
fun providesUserService(scarlet: Scarlet): Service2 {
    return scarlet.create(Service2::class.java)
}

@Provides
@Singleton
fun providesScarlet(): Scarlet {
    val client = OkHttpClient.Builder()
        .connectTimeout(60, TimeUnit.SECONDS)
        .readTimeout(60, TimeUnit.SECONDS)
        .writeTimeout(60, TimeUnit.SECONDS)

    return Scarlet.Builder()
        .webSocketFactory(client.build().newWebSocketFactory(baseUrl))
        .addMessageAdapterFactory(
            WebSocketMessageAdapter.Factory()
        )
        .addStreamAdapterFactory(FlowStreamAdapter.Factory)
        //.lifecycle(AndroidLifecycle.ofApplicationForeground(application))
        .backoffStrategy(BACKOFF_STRATEGY) //remove
        .build()
}

Is this an intended behavior? because having just one service with a long list of @Send and @Receive doesn't look neat.

@boronov
Copy link

boronov commented Jul 26, 2023

Сould you 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