# Aura Engine Development Guide

This page gives insights on extending Aura Engine internals or through the API.

<!-- TOC -->

- [Aura Engine Development Guide](#aura-engine-development-guide)
    - [Architecture](#architecture)
        - [Components](#components)
    - [API](#api)
        - [Required Data Sources](#required-data-sources)
        - [Provided API Endpoints](#provided-api-endpoints)
    - [Web Applications using the Engine API](#web-applications-using-the-engine-api)
    - [More infos for debugging](#more-infos-for-debugging)
        - [Default ports used by Engine](#default-ports-used-by-engine)
        - [Debugging Liquidsoap](#debugging-liquidsoap)
    - [Read more](#read-more)

<!-- /TOC -->

## Architecture

AURA Engine as part of the AURA Radio Suite uses an modulear architecture
based on a REST API. All external information is retrieved using JSON data-structures.

To get the basic architectural overview, visit the [Aura Meta](https://gitlab.servus.at/autoradio/meta) repository.

### Components


**engine-core.py**: It is the server which is connected to the external programme source (e.g. aura steering and tank), to liquidsoap and is listening for redis pubsub messages. This precious little server is telling liquidsoap what to play and when.

**Liquidsoap**: The heart of AuRa Engine. It uses the built in mixer, to switch between different sources. It records everything and streams everything depending on your settings in aura.ini.

**engine-api.py**: A Flask web server which provides the API endpoints. This component can be (re-) started independently from the core engine.

## API

### Required Data Sources

The AURA Project "**Dashboard**" provides the GUI to organize shows, schedules/timelsots
and organize uploads in form of playlists. Those playlists can be organized in timeslots
using a fancy calendar interface.

These data-sources need to be configurated in the "engine.ini" configuration file:

    # STEERING
    api_steering_status = "http://localhost:8000/api/v1/"
    # The URL to get the Calendar via Steering
    api_steering_calendar="http://localhost:8000/api/v1/playout"
    # The URL to get show details via Steering
    api_steering_show="http://localhost:8000/api/v1/shows/${ID}/"


The AURA Project "**Tank**" on the other hand delivers information on the tracks, related playlists
to be played and its meta-data:

    # TANK
    api_tank_status = "http://localhost:8040/ui/"
    # The URL to get playlist details via Tank
    api_tank_playlist="http://localhost:8040/api/v1/shows/${SLUG}/playlists"


More information you can find here: <https://gitlab.servus.at/autoradio/meta/blob/master/api-definition.md>

### Provided API Endpoints

**Soundserverstate:** Returns true and false values of the internal In- and Outputs  

    /api/v1/soundserver_state

**Trackservice:**

/api/v1/trackservice/<selected_date>  
/api/v1/trackservice/


## Web Applications using the Engine API

Under `./contrib` you'll find two Web Applications which utilize the Engine API:

- [Track Service](contrib/aura-player/README.md)
- [Studio Clock](contrib/aura-clock/README.md)

When you start the engine-api using

```shell
    ./run.sh api-dev
```

this automatically builds these web applications and copies the resulting assets to the
relevant `./web/**` folders.

## More infos for debugging

### Default ports used by Engine

Aura Engine requires a number of ports for internal and external communication.

Those are the default port numbers:

* `1234` ... Liquidsoap Telnet Server
* `3333` ... Exposes the Engine API
* `5000` ... Svelte development mode; dynamically uses some other port if occupied


### Debugging Liquidsoap

Connect to Liquidsoap via Telnet

    telnet 127.0.0.1 1234

List available commands

    help

List all available channels

    list

List all input channels connected to the mixer

    mixer.input

Set the volume of mixer `input 0` to `100%`

    mixer.volume 0 100

Push some audio file to the filesystem `queue 0`

    in_filesystem_0.push /path/to/your/file.mp3


## Read more

- [Overview](/README.md)
- [Installation for Development](installation-development.md)
- [Installation for Production](installation-production.md)
- [Running with Docker](running-docker.md)
- [Setup the Audio Store](docs/setup-audio-store.md)
- [Configuration Guide](configuration-guide.md)
- [Developer Guide](developer-guide.md)
- [Engine Features](engine-features.md)
- [Frequently Asked Questions (FAQ)](docs/frequently-asked-questions.md)