Add extra network for doorbell

This commit is contained in:
Jakob Lechner 2023-12-02 17:25:56 +00:00
parent 2dfeb3dcaf
commit f0f636d337
No known key found for this signature in database
GPG key ID: 996082EFB5906C10
4 changed files with 24 additions and 18 deletions

View file

@ -5,18 +5,18 @@ let
mediamtxConfig = pkgs.writeTextFile {
name = "myintercom-doorbell-cam-proxy-config";
text = lib.generators.toJSON { } {
paths.sprechanlage.source = "rtsp://${cfg.username}:__PASSWORD__@${cfg.host}/axis-media/media.amp?videocodec=h264&resolution=1280x720&fps=8&audio=0";
protocols = [ "udp" ];
paths.sprechanlage = {
source = "rtsp://${cfg.username}:__PASSWORD__@${cfg.host}/axis-media/media.amp?videocodec=h264&resolution=1280x720&fps=8&audio=0";
rtspTransport = "tcp";
};
protocols = [ "tcp" ];
hls = false;
rtmp = false;
rtsp = false;
srt = false;
webrtc = true;
webrtcAddress = "${cfg.cam.bindAddress}:${toString cfg.cam.webrtcPort}";
webrtcICEHostNAT1To1IPs = [ cfg.cam.bindAddress ];
webrtcICEUDPMuxAddress = ":${toString cfg.cam.webrtcIceUdpPort}";
webrtcAdditionalHosts = [ cfg.cam.bindAddress ];
webrtcLocalTCPAddress = "${cfg.cam.bindAddress}:${toString cfg.cam.webrtcIceTcpPort}";
};
};
in
@ -35,7 +35,7 @@ in
description = "Port the WebRTC service binds to.";
default = 8889;
};
webrtcIceUdpPort = mkOption {
webrtcIceTcpPort = mkOption {
type = types.port;
description = "Port (udp) the WebRTC ICE service binds to.";
default = 8189;
@ -128,6 +128,7 @@ in
Environment = [
"LISTEN_ADDRESS=${cfg.audiosocket.address}"
"LISTEN_PORT=${toString cfg.audiosocket.port}"
"HOST=${cfg.host}"
"USERNAME=${cfg.username}"
"PASSWORD_FILE=%d/password"
];

View file

@ -8,7 +8,7 @@ from threading import Thread
from .audiosocket import Audiosocket
def open_url(direction, connection, username, password):
def open_url(direction, connection, host, username, password):
print(f"start {direction}", flush=True)
if direction not in ("transmit", "receive"):
raise NotImplementedError
@ -17,7 +17,7 @@ def open_url(direction, connection, username, password):
"transmit": ("POST", {"Content-Type": "audio/basic", "Content-Length": "0"}),
}[direction]
url = f"http://192.168.0.74/axis-cgi/audio/{direction}.cgi"
url = f"http://{host}/axis-cgi/audio/{direction}.cgi"
http = urllib3.PoolManager()
@ -44,18 +44,18 @@ def open_url(direction, connection, username, password):
connection.send_bytes(data)
def handle_connection(call, username, password):
def handle_connection(call, host, username, password):
print(f"Received connection from {call.peer_addr}")
pipe_transmit_in, pipe_transmit_out = Pipe()
doorbell_transmit_process = Process(
target=open_url, args=("transmit", pipe_transmit_out, username, password)
target=open_url, args=("transmit", pipe_transmit_out, host, username, password)
)
doorbell_transmit_process.start()
pipe_receive_in, pipe_receive_out = Pipe()
doorbell_receive_process = Process(
target=open_url, args=("receive", pipe_receive_in, username, password)
target=open_url, args=("receive", pipe_receive_in, host, username, password)
)
doorbell_receive_process.start()
@ -80,6 +80,7 @@ def main():
audiosocket.prepare_input(inrate=8000, channels=1, ulaw2lin=True)
print("Listening for new connections " f"from Asterisk on port {audiosocket.port}")
host = os.environ["HOST"]
username = os.environ["USERNAME"]
with open(os.environ["PASSWORD_FILE"], "r", encoding="utf-8") as f:
@ -88,7 +89,9 @@ def main():
while True:
call = audiosocket.listen()
call_thread = Thread(target=handle_connection, args=(call, username, password))
call_thread = Thread(
target=handle_connection, args=(call, host, username, password)
)
call_thread.start()
call_thread.join()