Skip to content

Commit

Permalink
Merge pull request #1462 from WalletConnect/exponenctial_backoff_stra…
Browse files Browse the repository at this point in the history
…tegy

ExponentialBackoffStrategy for WSS reconnection
  • Loading branch information
jakubuid authored Jul 31, 2024
2 parents feccebb + 61fd9ff commit 93507e7
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.tinder.scarlet.Scarlet
import com.tinder.scarlet.lifecycle.LifecycleRegistry
import com.tinder.scarlet.lifecycle.android.AndroidLifecycle
import com.tinder.scarlet.messageadapter.moshi.MoshiMessageAdapter
import com.tinder.scarlet.retry.LinearBackoffStrategy
import com.tinder.scarlet.retry.ExponentialBackoffStrategy
import com.tinder.scarlet.websocket.okhttp.newWebSocketFactory
import com.walletconnect.android.BuildConfig
import com.walletconnect.android.internal.common.connection.ConnectivityState
Expand All @@ -28,7 +28,8 @@ import org.koin.core.qualifier.named
import org.koin.dsl.module
import java.util.concurrent.TimeUnit

private const val DEFAULT_BACKOFF_SECONDS = 5L
private const val INIT_BACKOFF_MILLIS = 1L
private const val MAX_BACKOFF_SEC = 20L

@Suppress("LocalVariableName")
@JvmSynthetic
Expand Down Expand Up @@ -119,13 +120,13 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType,
}
}

single { LinearBackoffStrategy(TimeUnit.SECONDS.toMillis(DEFAULT_BACKOFF_SECONDS)) }
single { ExponentialBackoffStrategy(INIT_BACKOFF_MILLIS, TimeUnit.SECONDS.toMillis(MAX_BACKOFF_SEC)) }

single { FlowStreamAdapter.Factory() }

single(named(AndroidCommonDITags.SCARLET)) {
Scarlet.Builder()
.backoffStrategy(get<LinearBackoffStrategy>())
.backoffStrategy(get<ExponentialBackoffStrategy>())
.webSocketFactory(get<OkHttpClient>(named(AndroidCommonDITags.OK_HTTP)).newWebSocketFactory(get<String>(named(AndroidCommonDITags.RELAY_URL))))
.lifecycle(get(named(AndroidCommonDITags.LIFECYCLE)))
.addMessageAdapterFactory(get<MoshiMessageAdapter.Factory>(named(AndroidCommonDITags.MSG_ADAPTER)))
Expand Down

0 comments on commit 93507e7

Please sign in to comment.