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
- Host: GitHub
- URL: https://github.com/mirego/konnectivity
- Owner: mirego
- License: bsd-3-clause
- Created: 2022-08-29T22:04:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-03T21:52:35.000Z (10 months ago)
- Last Synced: 2025-09-29T08:36:14.800Z (3 months ago)
- Topics: connectivity, kotlin-flow, kotlin-multiplatform, network-state, reachability
- Language: Kotlin
- Homepage:
- Size: 110 KB
- Stars: 10
- Watchers: 20
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
## 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.