1 unstable release
new 0.1.0 | Apr 20, 2025 |
---|
#8 in #kotlin
130KB
2.5K
SLoC
VideoCall Mobile Bindings
Native mobile bindings for the VideoCall project, providing iOS (Swift) and Android (Kotlin) interfaces to the core WebTransport functionality.
Overview
This crate extends the VideoCall project by providing native bindings for iOS and Android platforms using the UniFFI library. It allows mobile developers to easily integrate the VideoCall WebTransport functionality into their iOS and Android applications.
The bindings expose the core VideoCall functionality through platform-specific interfaces, handling the complexities of cross-language communication while maintaining the performance benefits of the Rust implementation.
Features
- Native Mobile Integration: Seamless integration with iOS and Android applications
- WebTransport Support: Access to the VideoCall WebTransport functionality from mobile platforms
- Datagram Management: Efficient handling of datagrams for real-time data transmission
- Error Handling: Comprehensive error handling with detailed error messages
- Thread-Safe: Built with thread safety in mind for concurrent operations
- Simple API: Easy-to-use API for connecting, sending data, and managing connections
Installation
iOS
- Add the XCFramework to your Xcode project
- Import the Swift module in your code
- Use the provided API to connect and send/receive data
import VideoCallKit
// Create a client
let client = WebTransportClient()
// Connect to a server
try client.connect(url: "https://example.com")
// Send data
try client.sendDatagram(data: [1, 2, 3, 4])
// Create a queue for receiving data
let queue = DatagramQueue()
// Subscribe to datagrams
try client.subscribeToDatagrams(queue: queue)
// Check if datagrams are available
if try queue.hasDatagrams() {
// Receive a datagram
let data = try queue.receiveDatagram()
// Process the data
}
Android
- Add the AAR to your Android project
- Import the Kotlin module in your code
- Use the provided API to connect and send/receive data
import com.videocall.uniffi.WebTransportClient
import com.videocall.uniffi.DatagramQueue
// Create a client
val client = WebTransportClient()
// Connect to a server
client.connect("https://example.com")
// Send data
client.sendDatagram(byteArrayOf(1, 2, 3, 4))
// Create a queue for receiving data
val queue = DatagramQueue()
// Subscribe to datagrams
client.subscribeToDatagrams(queue)
// Check if datagrams are available
if (queue.hasDatagrams()) {
// Receive a datagram
val data = queue.receiveDatagram()
// Process the data
}
Building from Source
Prerequisites
- Rust (latest stable)
- Android NDK (for Android builds)
- Xcode (for iOS builds)
- Java 17 (for Android builds)
- UniFFI CLI (
cargo install uniffi
)
Building for iOS
cd videocall-sdk
./build_ios.sh
This will generate:
- An XCFramework at
VideoCallKit/Frameworks/VideoCallIOS.xcframework
- Swift bindings at
VideoCallKit/Sources/VideoCallKit/videocall.swift
Building for Android
cd videocall-sdk
./build_android.sh
This will generate:
- An AAR file at
target/videocall-sdk.aar
- Kotlin bindings at
target/kotlin/com/videocall/uniffi/videocall.kt
How It Works
This crate uses UniFFI to generate language-specific bindings for the VideoCall core functionality:
- Interface Definition: The
videocall.udl
file defines the interface that will be exposed to Swift and Kotlin - Code Generation: UniFFI generates the necessary code to bridge between Rust and the target languages
- Build Process: The build scripts compile the Rust code and generate the platform-specific artifacts
Error Handling
The library provides comprehensive error handling through the WebTransportError
enum:
ConnectionError
: Errors related to the connectionTlsError
: TLS-related errorsStreamError
: Errors related to data streamsInvalidUrl
: Invalid URL formatRuntimeError
: Runtime-related errorsCertificateError
: Certificate-related errorsClientError
: Errors related to the clientQueueError
: Errors related to the datagram queue
License
This project is licensed under either of the following licenses:
- MIT License (LICENSE-MIT)
- Apache License, Version 2.0 (LICENSE-APACHE)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Dependencies
~32–48MB
~833K SLoC