# Janus SDK for Flutter

This directory contains the Flutter wrapper for the Janus SDK, allowing you to integrate privacy consent management into Flutter applications.

## Repository Structure

* **janus_sdk_flutter** - Flutter plugin that wraps the native Android and iOS SDKs
* **build_ scripts** - build scripts for the Flutter project

## Requirements and Setup

### Requirements

If these are not already installed, `flutter doctor` (run below) will verify they are installed and setup correctly and guide you on any missing steps.

* **Flutter/Dart**
* **Android Studio:**
* **XCode with Cocoapods**

### Flutter Installation

Install Flutter:

On macOS, Flutter can be installed using brew:
`brew install --cask flutter`

There are also the official installation guides to follow:
https://docs.flutter.dev/get-started/install

Last, if you plan to manage multiple versions of Flutter on our machine, fvm is a good choice:
```
brew tap leoafarias/fvm
brew install fvm
fvm install stable
```

Regardless of your installation method it's important to make sure that flutter is included in your path (if not already handled by brew install), by running/adding this to ~/.zshrc:

```bash
export PATH="$PATH:[PATH_TO_FLUTTER_DIRECTORY]/bin"
```

Verify your installation by running:
```bash
flutter doctor
```

Address any issues identified by `flutter doctor`. This may include:
* Installing Android Studio and SDK tools
* Installing Xcode and command-line tools
* Accepting licenses with `flutter doctor --android-licenses`
* Setting up an iOS development environment


## Development Workflow

The Janus SDK for Flutter is implemented as a Flutter plugin that wraps the native Android and iOS SDKs. This approach ensures feature parity with the native SDKs while providing a simple and idiomatic Flutter API.

### Building the SDK

To build the SDK:

```bash
./build_flutter_sdk.sh
```

This will run the builds for the iOS and Android SDK and prepare them for consumption by the Flutter SDK, then run the tests and build the Flutter example for both platforms.

The example apps can be run on each platform using Android Studio or

```bash
cd janus_sdk_flutter/example
flutter run
```

## Using Logdy for Local Log Monitoring

The example app includes an optional HTTPLogger that can send logs to a local [logdy](https://logdy.dev) instance for real-time log viewing and debugging.

### Installing Logdy

Install logdy using brew

```bash
brew install logdy
```

### Running Logdy

Start logdy with these settings to work with the example app:

```bash
logdy --no-analytics -p 8181 --api-key foobar
```

### Viewing Logs

Once logdy is running, simply run the example app and Janus SDK logs will appear in the logdy web interface at http://localhost:8181.

**Note:** The Flutter example automatically detects the platform and uses the correct endpoint:
- **Android**: Uses `10.0.2.2` for emulator localhost access
- **iOS**: Uses `localhost` for simulator and devices

### Testing

To run tests:

```bash
cd janus_sdk_flutter
flutter test
```

### Code Coverage

To run tests with code coverage:

```bash
cd janus_sdk_flutter
flutter test --coverage
```

This will generate a coverage report in LCOV format at `coverage/lcov.info`.

To generate an HTML report from the coverage data:

```bash
# First, install lcov if you don't have it
# macOS
brew install lcov
# Ubuntu/Debian
sudo apt-get install lcov

# Then generate the HTML report
cd janus_sdk_flutter
genhtml coverage/lcov.info -o coverage/html
```

Alternatively, you can use our coverage report script:

```bash
cd Flutter
./coverage_report.sh
```

This script will:
1. Run tests with coverage if needed
2. Generate an HTML report
3. Display the coverage percentage
4. Open the report in your browser (on macOS)

The HTML report will be available at `janus_sdk_flutter/coverage/html/index.html`


### Publishing the SDK - Creating a Release

Use the publish script in the root of the project, with a dry run, then drop the dry-run parameter.

**Important** - Without the --dry-run parameter, this script WILL make commits to multiple repos and push to origin on your behalf.

```bash
./publish.sh --flutter--dry-run
```

## Technical Architecture

The SDK follows this architecture:

1. **Flutter API Layer** - Dart classes providing a simple API for Flutter apps
2. **Platform Channel** - Bridges between Dart and native code
3. **Native Wrappers** - Thin wrappers around the native Janus SDKs
4. **Native SDKs** - The core functionality implemented in the native Android and iOS SDKs

This approach ensures:
- Maximum code reuse
- Native performance for critical operations
- Consistent behavior across platforms
- Simple API for Flutter developers