{"id":13610311,"url":"https://github.com/jordond/connectivity","last_synced_at":"2025-12-29T21:28:31.735Z","repository":{"id":243304891,"uuid":"811617911","full_name":"jordond/connectivity","owner":"jordond","description":"🛜 Monitornetwork connectivity in Kotlin Multiplatform apps","archived":false,"fork":false,"pushed_at":"2025-09-29T14:37:36.000Z","size":1043,"stargazers_count":634,"open_issues_count":7,"forks_count":14,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-29T16:10:07.184Z","etag":null,"topics":["compose-multiplatform","connectivity-checker","kotlin","kotlin-multiplatform","multiplatform","multiplatform-kotlin-library"],"latest_commit_sha":null,"homepage":"https://connectivity.jordond.dev/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jordond.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-06-07T00:45:14.000Z","updated_at":"2025-09-29T14:16:53.000Z","dependencies_parsed_at":"2024-06-14T20:26:18.280Z","dependency_job_id":"08b1823d-e9fc-4a85-9abf-02e98e421a9e","html_url":"https://github.com/jordond/connectivity","commit_stats":null,"previous_names":["jordond/connectivity"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/jordond/connectivity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordond%2Fconnectivity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordond%2Fconnectivity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordond%2Fconnectivity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordond%2Fconnectivity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jordond","download_url":"https://codeload.github.com/jordond/connectivity/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordond%2Fconnectivity/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278802799,"owners_count":26048566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compose-multiplatform","connectivity-checker","kotlin","kotlin-multiplatform","multiplatform","multiplatform-kotlin-library"],"created_at":"2024-08-01T19:01:43.486Z","updated_at":"2025-12-29T21:28:31.713Z","avatar_url":"https://github.com/jordond.png","language":"Kotlin","funding_links":[],"categories":["Kotlin","Libraries"],"sub_categories":["📱 Device"],"readme":"\u003cimg width=\"500px\" src=\"art/logo.png\" alt=\"logo\"/\u003e\n\u003cbr /\u003e\n\n[![Maven Central Version](https://img.shields.io/maven-central/v/dev.jordond.connectivity/connectivity-core)](https://central.sonatype.com/namespace/dev.jordond.connectivity)\n[![Kotlin](https://img.shields.io/badge/kotlin-v2.3.0-blue.svg?logo=kotlin)](http://kotlinlang.org)\n[![Build](https://github.com/jordond/connectivity/actions/workflows/ci.yml/badge.svg)](https://github.com/jordond/connectivity/actions/workflows/ci.yml)\n[![License](https://img.shields.io/github/license/jordond/connectivity)](https://opensource.org/license/mit/)\n\nConnectivity provides network monitoring capabilities for multiplatform projects. It can monitor\nnetwork connectivity using native APIs on Android and Apple devices, or by making HTTP requests to\nspecified hosts.\n\nYou can also\nview the generated KDoc at [connectivity.jordond.dev](https://connectivity.jordond.dev)\n\n## Table of Contents\n\n- [Features](#features)\n- [Platforms](#platforms)\n- [Setup](#setup)\n    - [Single Platform](#single-platform)\n    - [Multiplatform - Device](#multiplatform---device)\n    - [All supported platforms](#all-supported-platforms)\n- [Usage](#usage)\n  - [Options](#options)\n  - [HTTP monitoring](#http-monitoring)\n  - [Compose](#compose)\n  - [Multiple Targets](#multiple-targets)\n- [Demo](#demo)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Features\n\nMonitor network connectivity:\n\n- Native network monitoring on Android and Apple devices.\n- Using HTTP requests and polling to monitor network connectivity on all platforms.\n\n## Platforms\n\nThis library is written for Kotlin Multiplatform, and can be used on the following platforms:\n\n| Artifact                      | Android | iOS | macOS | tvOS | JVM | js/wasm |\n|-------------------------------|:-------:|:---:|:-----:|------|:---:|:-------:|\n| `connectivity-core`           |    ✅    |  ✅  |   ✅   | ✅    |  ✅  |    ✅    |\n| `connectivity-device`         |    ✅    |  ✅  |   ✅   | ✅    |  ❌  |    ❌    |\n| `connectivity-android`        |    ✅    |  ❌  |   ❌   | ❌    |  ❌  |    ❌    |\n| `connectivity-apple`          |    ❌    |  ✅  |   ✅   | ✅    |  ❌  |    ❌    |\n| `connectivity-http`           |    ✅    |  ✅  |   ✅   | ✅    |  ✅  |    ✅    |\n| `connectivity-compose`        |    ✅    |  ✅  |   ❌   | ❌    |  ✅  |    ✅    |\n| `connectivity-compose-device` |    ✅    |  ✅  |   ❌   | ❌    |  ✅  |    ✅    |\n| `connectivity-compose-http`   |    ✅    |  ✅  |   ❌   | ❌    |  ✅  |    ✅    |\n\n## Setup\n\nAdd the following dependencies to your project, depending on the platform you are targeting.\n\n```toml\n[versions]\nconnectivity = \"2.2.1\"\n\n[libraries]\nconnectivity-core = { module = \"dev.jordond.connectivity:connectivity-core\", version.ref = \"connectivity\" }\nconnectivity-device = { module = \"dev.jordond.connectivity:connectivity-device\", version.ref = \"connectivity\" }\nconnectivity-android = { module = \"dev.jordond.connectivity:connectivity-android\", version.ref = \"connectivity\" }\nconnectivity-apple = { module = \"dev.jordond.connectivity:connectivity-apple\", version.ref = \"connectivity\" }\nconnectivity-http = { module = \"dev.jordond.connectivity:connectivity-http\", version.ref = \"connectivity\" }\nconnectivity-compose = { module = \"dev.jordond.connectivity:connectivity-compose\", version.ref = \"connectivity\" }\nconnectivity-compose-device = { module = \"dev.jordond.connectivity:connectivity-compose-device\", version.ref = \"connectivity\" }\nconnectivity-compose-http = { module = \"dev.jordond.connectivity:connectivity-compose-http\", version.ref = \"connectivity\" }\n```\n\n### Single Platform\n\nHere is an example of how to add the dependencies to a single platform project targeting Android:\n\n```kotlin\ndependencies {\n  implementation(libs.connectivity.core)\n  implementation(libs.connectivity.android)\n\n  // For compose support\n  implementation(libs.connectivity.compose.device)\n}\n```\n\n### Multiplatform - Device\n\nHere is an example of how to add the dependencies to a multiplatform project that targets both\nAndroid and Apple devices:\n\n```kotlin\nkotlin {\n    sourceSets {\n        commonMain.dependencies {\n          implementation(libs.connectivity.core)\n          implementation(libs.connectivity.device)\n\n          // For compose support\n          implementation(libs.connectivity.compose.device)\n        }\n    }\n}\n```\n\n### All supported platforms\n\nHere is an example of how to add the dependencies to a multiplatform project that targets all the\nsupported platforms.\nIt uses the `connectivity-device` for mobile targets, and `connectivity-http` for the rest:\n\n```kotlin\nkotlin {\n    sourceSets {\n        commonMain.dependencies {\n          implementation(libs.connectivity.core)\n\n          // For compose support\n          implementation(libs.connectivity.compose)\n        }\n\n        val deviceMain by creating {\n            dependsOn(commonMain.get())\n            androidMain.get().dependsOn(this)\n            appleMain.get().dependsOn(this)\n            dependencies {\n              implementation(libs.connectivity.device)\n\n              // For compose support\n              implementation(libs.connectivity.compose.device)\n            }\n        }\n\n        val httpMain by creating {\n            dependsOn(commonMain.get())\n            jvmMain.get().dependsOn(this)\n            jsMain.get().dependsOn(this)\n            wasmJsMain.get().dependsOn(this)\n            dependencies {\n              implementation(libs.connectivity.http)\n\n              // For compose support\n              implementation(libs.connectivity.compose.http)\n            }\n        }\n    }\n}\n```\n\nSee the [demo](demo) project for a complete example.\n\n## Usage\n\nBasic usage of Connectivity is simple, you just need an instance of the `Connectivity` object, then\nyou can observe the network connectivity.\n\n```kotlin\nval connectivity = Connectivity()\nconnectivity.start()\ncoroutineScope.launch {\n  connectivity.statusUpdates.collect { status -\u003e\n    when (status) {\n      is Connectivity.Status.Connected -\u003e println(\"Connected to network\")\n      is Connectivity.Status.Disconnected -\u003e println(\"Disconnected from network\")\n    }\n  }\n}\n```\n\nYou can also get the current connectivity status by invoking the suspended `status()` function:\n\n```kotlin\nval connectivity = Connectivity()\ncoroutineScope.launch {\n    val status = connectivity.status()\n    when (status) {\n        is Connectivity.Status.Connected -\u003e println(\"Connected to network\")\n        is Connectivity.Status.Disconnected -\u003e println(\"Disconnected from network\")\n    }\n}\n```\n\nBy default when you construct a `Connectivity` object, it will not automatically start monitoring\nnetwork connectivity. You can enable this by passing in `ConnectivityOptions`():\n\n### Options\n\n```kotlin\nval connectivity = Connectivity {\n    autoStart = true\n}\n```\n\nYou can start or stop monitoring network connectivity manually:\n\n```kotlin\nval connectivity = Connectivity()\nconnectivity.start()\n\n// At some later point\nconnectivity.stop()\n```\n\nThe above `Connectivity()` function is a factory function provided by the platform-specific modules.\nThe `connectivity-core` module provides a factory function defined as:\n\n```kotlin\nfun Connectivity(\n    provider: ConnectivityProvider,\n    options: ConnectivityOptions = ConnectivityOptions(),\n    scope: CoroutineScope = CoroutineScope(Dispatchers.Default),\n): Connectivity\n```\n\n### HTTP monitoring\n\nThe `connectivity-http` module provides a way to monitor network connectivity by making HTTP\nrequests to specified urls. By default it will check connectivity\nto `\"google.com\"`, `\"github.com\"`, and `\"bing.com\"` on port `443`. It will check for the first\nsuccessful response, and then update the status.\n\nThe network status is updated by polling the urls at a specified interval. The default interval is\n5 minutes.\n\nYou can customize the HTTP monitoring like so:\n\n**Note:** This is only available in the `connectivity-http` module.\n\n```kotlin\nval connectivity = Connectivity {\n  urls(\"cloudflare.com\", \"my-own-domain.com\") // Defaults to [\"google.com\", \"github.com\", \"bing.com\"]\n  port = 80 // Defaults to 443\n  pollingIntervalMs = 10.minutes // Defaults to 5 minutes\n  timeoutMs = 5.seconds // Defaults to 2 seconds\n\n  // Callback for when a poll is completed\n  onPollResult { result -\u003e\n    when (result) {\n      is PollResult.Error -\u003e println(\"Poll error: ${result.error}\")\n      is PollResult.Response -\u003e println(\"Poll http response: ${result.response}\")\n    }\n  }\n}\n```\n\n### Compose\n\nConnectivity also provides support for Compose Multiplatform. To use it you will have to make sure\nyou add the dependencies for the `connectivity-compose-x` modules.\n\nThen you can use it like so:\n\n**Note:** This composable is provided by either `connectivity-compose-device`\nor `connectivity-compose-http` artifact.\n\n```kotlin\n@Composable\nfun MyApp() {\n  val state = rememberConnectivityState {\n    // Optional configurator for ConnectivityOptions\n    autoStart = true\n  }\n\n  when (state.status) {\n    is Connectivity.Status.Connected -\u003e Text(\"Connected to network\")\n    is Connectivity.Status.Disconnected -\u003e Text(\"Disconnected from network\")\n    else -\u003e {}\n  }\n}\n```\n\n### Multiple Targets\n\nIf you need to support both Device and HTTP monitoring in the same project, you will have to do\nsomething similar to [this](#all-supported-platforms).\n\nExample:\n\n```kotlin\n// commonMain/Platform.kt\nexpect fun createConnectivity(): Connectivity\n```\n\nThen define the `actual` functions:\n\n```kotlin\n// deviceMain/Platform.device.kt\nactual fun createConnectivityState(): Connectivity {\n  return Connectivity {\n    autoStart = true\n  }\n}\n\n// httpMain/Platform.http.kt\nactual fun createConnectivityState(): Connectivity {\n  return Connectivity {\n    autoStart = true\n    urls(\"cloudflare.com\", \"my-own-domain.com\")\n    port = 80\n    pollingIntervalMs = 10.minutes\n    timeoutMs = 5.seconds\n  }\n}\n```\n\nThen it can be used like so:\n\n```kotlin\n@Composable\nfun MyApp() {\n  val state = createConnectivityState()\n\n  when (state.status) {\n    is Connectivity.Status.Connected -\u003e Text(\"Connected to network\")\n    is Connectivity.Status.Disconnected -\u003e Text(\"Disconnected from network\")\n    else -\u003e {}\n  }\n}\n```\n\n## Demo\n\nA demo app is available in the `demo` directory. It is a Compose Multiplatform app that runs on\nAndroid, and iOS.\n\n## Contributing\n\nContributions are always welcome!. If you'd like to contribute, please feel free to create a PR or\nopen an issue.\n\n## License\n\nSee [LICENSE](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordond%2Fconnectivity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjordond%2Fconnectivity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordond%2Fconnectivity/lists"}