Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions languages/javascript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ title: "JavaScript"
description: "Use iroh from Node.js via the iroh-ffi bindings."
---

The JavaScript bindings to iroh are published on npm as [`@number0/iroh`](https://www.npmjs.com/package/@number0/iroh) and shipped from [iroh-ffi](https://github.com/n0-computer/iroh-ffi). They're built with [napi-rs](https://napi.rs/), so the package distributes prebuilt native binaries — no Rust toolchain or local compilation needed.
| Platform | Architectures |
| --- | --- |
| macOS | arm64 |
| Linux | x86_64, aarch64 (glibc and musl), armv7 |
| Windows | x86_64, aarch64 |
| Android | aarch64, armv7 |

All platforms require Node.js 20.3.0 or newer.

- **API reference:** [JavaScript API docs](https://n0-computer.github.io/iroh-ffi/js/)
- **Example code:** [iroh-js test scripts](https://github.com/n0-computer/iroh-ffi/tree/main/iroh-js/test), runnable scripts covering endpoints, keys, and relays
- **All languages:** [platform support matrix](/languages#platform-support)

The JavaScript bindings to iroh are published on npm as [`@number0/iroh`](https://www.npmjs.com/package/@number0/iroh) and shipped from [iroh-ffi](https://github.com/n0-computer/iroh-ffi). They're built with [napi-rs](https://napi.rs/), so the package distributes prebuilt native binaries. No Rust toolchain or local compilation is needed.

## Install

Expand Down Expand Up @@ -37,7 +50,7 @@ await ep.close()
A minimal sender/receiver pair over a bidirectional stream:

```javascript
// main.mjsrun: `node main.mjs receiver` or `node main.mjs sender <ticket>`
// main.mjs: run `node main.mjs receiver` or `node main.mjs sender <ticket>`
import { Endpoint, EndpointTicket } from '@number0/iroh'

const ALPN = Array.from(Buffer.from('hello-iroh/0'))
Expand Down
19 changes: 15 additions & 4 deletions languages/kotlin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ title: "Kotlin"
description: "Use iroh from Kotlin on the JVM or Android."
---

| Platform | Architectures |
| --- | --- |
| macOS | arm64, x86_64 |
| Linux | x86_64, aarch64 (glibc) |
| Windows | x86_64 |
| Android | aarch64, armv7 (requires [building from source](#building-from-source)) |

- **API reference:** [Kotlin API docs](https://n0-computer.github.io/iroh-ffi/kotlin/)
- **Example app:** [hello-iroh-ffi](https://github.com/n0-computer/hello-iroh-ffi/tree/main/kotlin-android), a Jetpack Compose demo that streams live positions between two devices
- **All languages:** [platform support matrix](/languages#platform-support)

The Kotlin bindings live in [iroh-ffi](https://github.com/n0-computer/iroh-ffi), generated by [uniffi-rs](https://github.com/mozilla/uniffi-rs) from the same Rust core as the Swift and Python bindings. Published to Maven Central as `computer.iroh:iroh`.

## Prerequisites
Expand All @@ -25,7 +36,7 @@ dependencies {
```

<Note>
The published artifact is single-platform — it does not yet ship a multiplatform build, so it won't cover Android or arbitrary host triples out of the box. If you need a target the artifact doesn't cover, [build the bindings from source](#building-from-source).
The published artifact is single-platform. It does not yet ship a multiplatform build, so it won't cover Android or arbitrary host triples out of the box. If you need a target the artifact doesn't cover, [build the bindings from source](#building-from-source).
</Note>

## Hello, iroh
Expand All @@ -45,7 +56,7 @@ fun main() = runBlocking {
}
```

Drop this in any module that depends on the generated `computer.iroh` package. The API mirrors the Swift and Python bindings same `Endpoint.bind`, same `EndpointOptions`, same presets.
Drop this in any module that depends on the generated `computer.iroh` package. The API mirrors the Swift and Python bindings: same `Endpoint.bind`, same `EndpointOptions`, same presets.

## Next steps

Expand All @@ -67,13 +78,13 @@ Drop this in any module that depends on the generated `computer.iroh` package. T

## Foreground and backgrounding

On Android, the OS aggressively suspends background processes sockets get torn down, threads stop scheduling, and an iroh endpoint that was happily accepting connections a moment ago goes silent. Treat each foreground/background transition as a lifecycle event for your endpoint:
On Android, the OS aggressively suspends background processes: sockets get torn down, threads stop scheduling, and an iroh endpoint that was happily accepting connections a moment ago goes silent. Treat each foreground/background transition as a lifecycle event for your endpoint:

- **Going to background**: call `ep.shutdown()` to close cleanly and release sockets. Persist the endpoint's secret key (`ep.secretKey().toBytes()`) somewhere durable (e.g. `EncryptedSharedPreferences`) so the next bind keeps the same endpoint id.
- **Returning to foreground**: re-bind with `EndpointOptions(secretKey = persistedBytes, preset = presetN0(), ...)`. Discovery republishes the new direct addresses automatically.
- **Staying live while backgrounded**: run iroh inside an [Android foreground service](https://developer.android.com/develop/background-work/services/foreground-services) (with the appropriate `FOREGROUND_SERVICE_*` permission for your use case). Without one, Android will eventually kill the network sockets regardless of how the coroutine scope is structured.

For desktop JVM apps these constraints don't apply — keep the endpoint bound for the lifetime of the process and call `shutdown()` on exit.
For desktop JVM apps these constraints don't apply. Keep the endpoint bound for the lifetime of the process and call `shutdown()` on exit.

## Building from source

Expand Down
12 changes: 11 additions & 1 deletion languages/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ title: "Python"
description: "Use iroh from Python via the iroh-ffi bindings."
---

| Platform | Architectures |
| --- | --- |
| macOS | arm64, x86_64 |
| Linux | x86_64, aarch64 (glibc) |
| Windows | x86_64 |

- **API reference:** [Python API docs](https://n0-computer.github.io/iroh-ffi/python/)
- **Example app:** [main.py](https://github.com/n0-computer/iroh-ffi/blob/main/python/main.py), a two-peer echo over QUIC
- **All languages:** [platform support matrix](/languages#platform-support)

The Python bindings to iroh are published as prebuilt wheels on [PyPI](https://pypi.org/project/iroh/) and shipped from [iroh-ffi](https://github.com/n0-computer/iroh-ffi). The bindings are generated by [uniffi-rs](https://github.com/mozilla/uniffi-rs), so every class, method, and enum carries a docstring you can introspect from a REPL.

## Install
Expand Down Expand Up @@ -76,7 +86,7 @@ The [main.py example](https://github.com/n0-computer/iroh-ffi/blob/main/python/m
# Terminal 1
python main.py serve

# Terminal 2paste the ticket printed from Terminal 1
# Terminal 2: paste the ticket printed from Terminal 1
python main.py connect <ticket>
```

Expand Down
12 changes: 12 additions & 0 deletions languages/rust.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ title: "Rust"
description: "Add iroh to your Rust project."
---

| Platform | Architectures |
| --- | --- |
| iOS | device and simulator |
| Android | aarch64, armv7 |
| macOS | arm64, x86_64 |
| Linux | x86_64, aarch64, armv7 (glibc and musl) |
| Windows | x86_64, aarch64 |

- **API reference:** [docs.rs/iroh](https://docs.rs/iroh)
- **Example app:** [sendme](https://github.com/n0-computer/sendme), a CLI for direct file transfers between devices
- **All languages:** [platform support matrix](/languages#platform-support)

iroh is written in Rust, so the Rust crate is the most fully-featured way to use it. Everything in these docs assumes Rust unless explicitly tagged otherwise.

## Install
Expand Down
21 changes: 15 additions & 6 deletions languages/swift.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ title: "Swift"
description: "Build an iOS + macOS app on top of iroh via the Swift bindings."
---

The Swift bindings to iroh ship from [iroh-ffi](https://github.com/n0-computer/iroh-ffi) and are generated by [uniffi-rs](https://github.com/mozilla/uniffi-rs). The package distributes a prebuilt xcframework for iOS device, iOS simulator, and macOS, so adding iroh to your app is the same as adding any other Swift Package — no Rust toolchain required.
| Platform | Architectures |
| --- | --- |
| iOS | device and simulator |
| macOS | arm64 |

- **API reference:** [Swift API docs](https://n0-computer.github.io/iroh-ffi/swift/documentation/irohlib/)
- **Example app:** [hello-iroh-ffi](https://github.com/n0-computer/hello-iroh-ffi/tree/main/swift), a SwiftUI demo that streams live positions between two devices
- **All languages:** [platform support matrix](/languages#platform-support)

The Swift bindings to iroh ship from [iroh-ffi](https://github.com/n0-computer/iroh-ffi) and are generated by [uniffi-rs](https://github.com/mozilla/uniffi-rs). The package distributes a prebuilt xcframework for iOS device, iOS simulator, and macOS, so adding iroh to your app is the same as adding any other Swift Package, with no Rust toolchain required.

This tutorial walks through creating a new Xcode project from scratch and wiring up a SwiftUI app that binds an iroh `Endpoint` and prints its endpoint id.

Expand Down Expand Up @@ -124,7 +133,7 @@ Pick a destination and hit Run.
- **iOS Simulator**: choose any iPhone simulator destination.
- **iOS device**: select your device. You'll need to trust your developer certificate in **Settings → General → VPN & Device Management** the first time.

Two different installs print two different endpoint ids — that's expected, since each launch generates a fresh `SecretKey`. If you want a stable identity across launches, persist `endpoint.secretKey().toBytes()` (e.g. in `UserDefaults` for a demo, Keychain for production) and pass it back via `EndpointOptions(secretKey: ...)` on subsequent launches.
Two different installs print two different endpoint ids. That's expected, since each launch generates a fresh `SecretKey`. If you want a stable identity across launches, persist `endpoint.secretKey().toBytes()` (e.g. in `UserDefaults` for a demo, Keychain for production) and pass it back via `EndpointOptions(secretKey: ...)` on subsequent launches.

## Building against an unreleased iroh-ffi

Expand All @@ -151,7 +160,7 @@ Then in Xcode, **File → Add Package Dependencies… → Add Local…** and pic
</Card>

<Card title="Swift API reference" icon="book" href="https://n0-computer.github.io/iroh-ffi/swift/documentation/irohlib/" horizontal>
Full DocC reference for `IrohLib` every type, method, and option generated from the bindings.
Full DocC reference for `IrohLib`: every type, method, and option generated from the bindings.
</Card>

<Card title="Endpoints" icon="circle-nodes" href="/concepts/endpoints" horizontal>
Expand All @@ -164,12 +173,12 @@ Then in Xcode, **File → Add Package Dependencies… → Add Local…** and pic

## Troubleshooting

**`Undefined symbols: _nw_interface_get_index` on iOS.** You skipped step 3 — add `-framework Network` to **Other Linker Flags** for the iOS SDKs.
**`Undefined symbols: _nw_interface_get_index` on iOS.** You skipped step 3. Add `-framework Network` to **Other Linker Flags** for the iOS SDKs.

**`product being built is not an allowed client of SwiftUICore`.** You skipped step 5 — set **Enable Previews** to **No**.
**`product being built is not an allowed client of SwiftUICore`.** You skipped step 5. Set **Enable Previews** to **No**.

**`No such module 'IrohLib'`.** The package didn't resolve. Pull down the package from **File → Packages → Reset Package Caches** and try the resolve again.

**`bind failed: NoNetwork` or hang on macOS.** Check **Signing & Capabilities** both **Incoming** and **Outgoing** network sandbox boxes need to be checked.
**`bind failed: NoNetwork` or hang on macOS.** Check **Signing & Capabilities**: both **Incoming** and **Outgoing** network sandbox boxes need to be checked.

**`The developer disk image could not be mounted on this device`.** Your device is running a newer iOS than your Xcode supports. Update Xcode (App Store for stable, [developer.apple.com](https://developer.apple.com/download/applications) for betas) so the matching Developer Disk Image is available, or fall back to the simulator while you wait.
Loading