URI:
       tadd the http listener daemon - dmt - source code for the kunsthal art installation
  HTML git clone git://parazyd.org/dmt.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 94b9549f46cc6c7728b51c6f22e9a6e1a31d15a1
   DIR parent 4ac934837cf0043f9801867dc248265112fa7cee
  HTML Author: parazyd <parazyd@dyne.org>
       Date:   Fri, 17 Nov 2017 22:28:51 +0100
       
       add the http listener daemon
       
       Diffstat:
         A http-api/README.md                  |      26 ++++++++++++++++++++++++++
         A http-api/config.py                  |      17 +++++++++++++++++
         A http-api/http_listener.py           |      50 +++++++++++++++++++++++++++++++
       
       3 files changed, 93 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/http-api/README.md b/http-api/README.md
       t@@ -0,0 +1,26 @@
       +http-listener
       +=============
       +
       +http-listener is a small Flask daemon acting as a HTTP API listening for
       +callbacks from the FreePBX log handler.
       +
       +It offers callbacks for `/callanswered` and `/callended`.
       +
       +The former will mute the playback of our sound input on the speakers and
       +enable it on the phone.
       +
       +The latter will do the opposite.
       +
       +
       +Dependencies
       +------------
       +
       +```
       +python3-flask
       +```
       +
       +
       +Deployment
       +----------
       +
       +Deploy this by running `./http_listener.py` on the Caller Station.
   DIR diff --git a/http-api/config.py b/http-api/config.py
       t@@ -0,0 +1,17 @@
       +# See LICENSE file for copyright and license details.
       +"""
       +HTTP API handler configuration
       +"""
       +
       +# We are using the following USB sound card:
       +# input: GeneralPlus USB Audio Device as /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.3/0003:1B3F:2008.0003/input/input17
       +# hid-generic 0003:1B3F:2008.0003: input,hidraw0: USB HID v2.01 Device [GeneralPlus USB Audio Device] on usb-0000:00:1a.0-1.2/input3
       +
       +# Card number (found in ALSA)
       +cardno = '1'
       +
       +# Mic capture line (for amixer)
       +mic_cap = "numid=4,iface=MIXER,name='Mic Playback Volume'"
       +
       +# Mic playback line (for amixer)
       +mic_play = "numid=8,iface=MIXER,name='Mic Capture Volume'"
   DIR diff --git a/http-api/http_listener.py b/http-api/http_listener.py
       t@@ -0,0 +1,50 @@
       +#!/usr/bin/env python3
       +# See LICENSE file for copyright and license details.
       +"""
       +HTTP API handler for the Caller Station
       +"""
       +
       +from subprocess import Popen
       +from flask import Flask
       +
       +from config import (cardno, mic_cap, mic_play)
       +
       +APP = Flask(__name__)
       +
       +
       +@APP.route('/')
       +def main():
       +    """
       +    Main routine (noop)
       +    """
       +    return '\n'
       +
       +
       +@APP.route('/callanswered')
       +def callanswered():
       +    """
       +    Handler for the answered phone call.
       +    """
       +    print('Call answered')
       +
       +    Popen(['amixer', '-c', cardno, 'cset', mic_play, '0'])
       +    Popen(['amixer', '-c', cardno, 'cset', mic_cap, '100'])
       +
       +    return 'Call answered\n'
       +
       +
       +@APP.route('/callended')
       +def callended():
       +    """
       +    Handler for the ended phone call.
       +    """
       +    print('Call ended')
       +
       +    Popen(['amixer', '-c', cardno, 'cset', mic_play, '100'])
       +    Popen(['amixer', '-c', cardno, 'cset', mic_cap, '0'])
       +
       +    return 'Call ended\n'
       +
       +
       +if __name__ == '__main__':
       +    APP.run(host='0.0.0.0', port=8000, threaded=True, debug=True)