Add extra network for doorbell
This commit is contained in:
parent
2dfeb3dcaf
commit
f0f636d337
4 changed files with 24 additions and 18 deletions
|
|
@ -5,5 +5,5 @@ custom-utils.validatePortAttrset {
|
|||
unifi.tcp = 8443;
|
||||
doorbell-audiosocket.tcp = 9092;
|
||||
doorbell-webrtc.tcp = 8889;
|
||||
doorbell-webrtc-ice.udp = 8189;
|
||||
doorbell-webrtc-ice.tcp = 8189;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,11 @@ in
|
|||
enable = true;
|
||||
bindAddress = "192.168.0.1";
|
||||
webrtcPort = ports.doorbell-webrtc.tcp;
|
||||
webrtcIceUdpPort = ports.doorbell-webrtc-ice.udp;
|
||||
webrtcIceTcpPort = ports.doorbell-webrtc-ice.tcp;
|
||||
};
|
||||
};
|
||||
networking.firewall.interfaces.lechner.allowedTCPPorts = [ ports.doorbell-webrtc.tcp ];
|
||||
networking.firewall.interfaces.lechner.allowedUDPPorts = [ ports.doorbell-webrtc-ice.udp ];
|
||||
networking.firewall.interfaces.lechner.allowedTCPPorts = [
|
||||
ports.doorbell-webrtc.tcp
|
||||
ports.doorbell-webrtc-ice.tcp
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue