An open API service indexing awesome lists of open source software.

https://github.com/mirego/konnectivity

📡 A lightweight Kotlin Multiplatform library to monitor network state changes
https://github.com/mirego/konnectivity

connectivity kotlin-flow kotlin-multiplatform network-state reachability

Last synced: 3 months ago
JSON representation

📡 A lightweight Kotlin Multiplatform library to monitor network state changes

Awesome Lists containing this project

README

          




A lightweight Kotlin Multiplatform library to monitor network state changes





## Preview

This preview shows _Konnectivity_ running in a Web, iOS and Android app from our [sample](./sample).

https://user-images.githubusercontent.com/5982196/233498817-240ccf01-63f3-4fe0-abd5-f538f1339343.mov

## Installation

### Gradle

Add the dependency to your common source-set dependencies:
```kotlin
sourceSets {
commonMain {
dependencies {
api("com.mirego:konnectivity:0.3.0")
}
}
}
```

Make sure you have [Mirego](https://open.mirego.com/)'s public Maven in your list of repositories:
```kotlin
repositories {
maven("https://s3.amazonaws.com/mirego-maven/public")
}
```

Using the [Kotlin CocoaPods Plugin](https://kotlinlang.org/docs/native-cocoapods.html), add the [Reachability](https://cocoapods.org/pods/Reachability) pod dependency:
```kotlin
kotlin {
cocoapods {
pod("Reachability", "~> 3.2")
}
}
```

## Usage

```kotlin
import com.mirego.konnectivity.Konnectivity
import com.mirego.konnectivity.NetworkState
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

val konnectivity = Konnectivity()

konnectivity.networkState
.onEach { networkState ->
when (networkState) {
is NetworkState.Reachable -> when {
networkState.metered -> println("You're online, but your connection is metered.")
else -> println("You're online!")
}
NetworkState.Unreachable -> println("You're offline.")
}
}
.launchIn(MainScope())
```

## License

Konnectivity is © 2023 [Mirego](https://www.mirego.com) and may be freely distributed under
the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See
the [`LICENSE.md`](https://github.com/mirego/konnectivity/blob/main/LICENSE.md) file.

## About Mirego

[Mirego](https://www.mirego.com) is a team of passionate people who believe that work is a place
where you can innovate and have fun. We’re a team of [talented people](https://life.mirego.com) who
imagine and build beautiful Web and mobile applications. We come together to share ideas
and [change the world](http://www.mirego.org).

We also [love open-source software](https://open.mirego.com) and we try to give back to the
community as much as we can.