Scarlet icon indicating copy to clipboard operation
Scarlet copied to clipboard

With default lifecycle config, SocketIoClient is not connecting

Open hannta opened this issue 7 years ago • 3 comments

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 avatar Nov 28 '18 14:11 hannta

@hannta Thanks for bring this up! I will look into this issue

zhxnlai avatar Nov 29 '18 15:11 zhxnlai

@hannta Just released 0.2.4-alpha1 to address this issue. Could you let me know if works?

zhxnlai avatar Jan 18 '19 02:01 zhxnlai

@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.

iadcialim avatar Nov 24 '21 11:11 iadcialim