Scarlet
Scarlet copied to clipboard
With default lifecycle config, SocketIoClient is not connecting
If I do not specify lifecycle for Scarlet.Configuration, SocketIoClient is not connecting.
My dagger module which creates Scarlet
@Module
class MykModule {
@Singleton
@Provides
fun provideScarletConfiguration(app: Application): Scarlet.Configuration {
return Scarlet.Configuration(
lifecycle = AndroidLifecycle.ofApplicationForeground(app), // With out this, Scarlet is not connectin
messageAdapterFactories = listOf(MoshiMessageAdapter.Factory()),
streamAdapterFactories = listOf(RxJava2StreamAdapterFactory()),
)
}
@Singleton
@Provides
fun provideScarlet(config: Scarlet.Configuration): Scarlet {
val client = SocketIoClient({ "https://my.api" })
return Scarlet(client, config)
}
@Singleton
@Provides
fun provideMyApi(scarlet: Scarlet): MyApi {
return scarlet.create<MyApi>()
}
@Singleton
@Provides
fun providePingTopic(scarlet: Scarlet, config: Scarlet.Configuration): PingTopic {
return scarlet.child(SocketIoEventName("ping"), config).create<PingTopic>()
}
}
I try to keep my connection alive even when the app is in background, so I can not use lifecycle AndroidLifecycle.ofApplicationForeground(app)
Im using Scarlet 0.2.1-alpha4
@hannta Thanks for bring this up! I will look into this issue
@hannta Just released 0.2.4-alpha1 to address this issue. Could you let me know if works?
@zhxnlai How bout if app is closed, it means websocket connection is also closed right? I am coming from the view of a push notification, where it is still delivered even if the app is closed.