cam: go2rtc + mic-bridge
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
.RECIPEPREFIX = >
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
BT_MAC ?= 69:B2:C0:04:A4:80
|
||||
USER_ID ?= 1001
|
||||
PCI_USB ?= 0000:00:14.0
|
||||
GAIN ?= 12
|
||||
SINKVOL ?= 70%
|
||||
ENVU = XDG_RUNTIME_DIR=/run/user/$(USER_ID) DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(USER_ID)/bus
|
||||
|
||||
.PHONY: help up down restart build rebuild ps logs logs-cam logs-mic status \
|
||||
bt audio-fix usb-reset speaker level gain-cam sink-volume \
|
||||
host-setup cron-install cron-remove cron-log update
|
||||
|
||||
help: ## Liste des commandes
|
||||
> @grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN{FS=":.*?## "}{printf " %-14s %s\n",$$1,$$2}'
|
||||
|
||||
up: ## Demarrer (build si besoin)
|
||||
> docker compose up -d --build
|
||||
|
||||
down: ## Arreter et supprimer les conteneurs
|
||||
> docker compose down
|
||||
|
||||
restart: ## Redemarrer go2rtc et mic-bridge
|
||||
> docker compose restart go2rtc mic-bridge
|
||||
|
||||
build: ## Reconstruire l'image mic-bridge
|
||||
> docker compose build mic-bridge
|
||||
|
||||
rebuild: ## Reconstruire sans cache et relancer
|
||||
> docker compose build --no-cache mic-bridge
|
||||
> docker compose up -d
|
||||
|
||||
ps: ## Etat des conteneurs
|
||||
> docker compose ps
|
||||
|
||||
logs: ## Logs des deux services (suivi)
|
||||
> docker compose logs -f --tail 50
|
||||
|
||||
logs-cam: ## Logs go2rtc (suivi)
|
||||
> docker compose logs -f --tail 50 go2rtc
|
||||
|
||||
logs-mic: ## Logs mic-bridge / Bluetooth (suivi)
|
||||
> docker compose logs -f --tail 50 mic-bridge
|
||||
|
||||
status: ## Diagnostic complet (webcam, son, Bluetooth, flux)
|
||||
> @echo "== Webcam (hote)"
|
||||
> @ls /dev/video* 2>/dev/null || echo "ABSENTE : probleme USB, voir README"
|
||||
> @grep -A1 webcam /proc/asound/cards || echo "carte son webcam ABSENTE"
|
||||
> @echo "== Conteneurs"
|
||||
> @docker compose ps
|
||||
> @echo "== Bluetooth"
|
||||
> @bluetoothctl info $(BT_MAC) | grep -E "Name|Connected" || true
|
||||
> @echo "== Flux go2rtc"
|
||||
> @docker exec mic-bridge node -e "fetch('http://go2rtc:1984/api/streams').then(r=>r.text()).then(t=>console.log(t.slice(0,300)))" || true
|
||||
|
||||
bt: ## Reconnecter l'enceinte Bluetooth
|
||||
> $(ENVU) bluetoothctl connect $(BT_MAC)
|
||||
> docker compose restart mic-bridge
|
||||
|
||||
audio-fix: ## Relancer pipewire, reconnecter l'enceinte
|
||||
> $(ENVU) systemctl --user restart pipewire pipewire-pulse wireplumber
|
||||
> sleep 3
|
||||
> $(ENVU) bluetoothctl connect $(BT_MAC)
|
||||
> docker compose restart mic-bridge
|
||||
|
||||
usb-reset: ## Reset du controleur USB (coupe aussi le Bluetooth)
|
||||
> echo $(PCI_USB) | sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind
|
||||
> sleep 3
|
||||
> echo $(PCI_USB) | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind
|
||||
> sleep 8
|
||||
> ls -l /dev/video* || echo "webcam toujours absente : debrancher/rebrancher"
|
||||
> $(MAKE) restart
|
||||
|
||||
speaker: ## Bruit de test dans l'enceinte
|
||||
> docker exec mic-bridge sh -c 'head -c 32000 /dev/urandom | paplay --raw --rate=16000 --format=s16le --channels=1'
|
||||
|
||||
level: ## Niveau du son camera (viser -25 a -30 dB)
|
||||
> docker exec go2rtc ffmpeg -hide_banner -i rtsp://127.0.0.1:8554/webcam -t 5 -vn -af volumedetect -f null - 2>&1 | grep -E "mean_volume|max_volume"
|
||||
|
||||
gain-cam: ## Gain camera : make gain-cam GAIN=15
|
||||
> sed -i -E 's/volume=[0-9.]+dB/volume=$(GAIN)dB/' go2rtc.yaml
|
||||
> docker compose restart go2rtc
|
||||
|
||||
sink-volume: ## Volume enceinte : make sink-volume SINKVOL=60%
|
||||
> sed -i -E 's/SINK_VOLUME: "[^"]*"/SINK_VOLUME: "$(SINKVOL)"/' docker-compose.yml
|
||||
> docker compose up -d mic-bridge
|
||||
|
||||
host-setup: ## A faire une fois : linger, pipewire, trust BT, volume micro
|
||||
> sudo loginctl enable-linger $$USER
|
||||
> $(ENVU) systemctl --user enable --now pipewire pipewire-pulse wireplumber
|
||||
> bluetoothctl trust $(BT_MAC)
|
||||
> sudo amixer -c 0 sset Mic 100% cap unmute
|
||||
> sudo alsactl store
|
||||
|
||||
cron-install: ## Installer la surveillance webcam (cron, chaque minute)
|
||||
> sudo install -m 755 scripts/cam-watch.sh /usr/local/bin/cam-watch
|
||||
> sudo install -m 644 scripts/cam-watch.cron /etc/cron.d/cam-watch
|
||||
> @echo "Installe. Log : /var/log/cam-watch.log"
|
||||
|
||||
cron-remove: ## Desinstaller la surveillance
|
||||
> sudo rm -f /etc/cron.d/cam-watch /usr/local/bin/cam-watch
|
||||
|
||||
cron-log: ## Voir le journal de la surveillance
|
||||
> @tail -n 30 /var/log/cam-watch.log 2>/dev/null || echo "(vide)"
|
||||
|
||||
update: ## Mettre a jour l'image go2rtc et reconstruire mic-bridge
|
||||
> docker compose pull go2rtc
|
||||
> docker compose build --pull mic-bridge
|
||||
> docker compose up -d
|
||||
@@ -0,0 +1,128 @@
|
||||
# cam : webcam, son bidirectionnel et enceinte Bluetooth via Cloudflare
|
||||
|
||||
Page web `https://kaisa.esiah.dev/mic` : video + son de la webcam du serveur,
|
||||
et micro du navigateur vers une enceinte Bluetooth branchee sur le serveur.
|
||||
Aucun port ouvert sur le routeur ni sur le serveur : tout passe par le tunnel Cloudflare.
|
||||
|
||||
## Architecture
|
||||
Navigateur --HTTPS--> Cloudflare (Access + Tunnel) --> cloudflared (app-tunnel)
|
||||
| reseau docker shared-network
|
||||
/mic* --> mic-bridge:8090 (page + WebSocket micro -> paplay -> Pulse -> Bluetooth)
|
||||
reste --> go2rtc:1984 (video MSE + son camera)
|
||||
|
||||
|
||||
- **go2rtc** : lit la webcam (`/dev/video0` + carte son ALSA `webcam`) via ffmpeg
|
||||
(H.264 baseline + AAC) et la diffuse en MSE par HTTP/WebSocket.
|
||||
- **mic-bridge** : sert la page `/mic`, recoit l'audio du navigateur en WebSocket
|
||||
(PCM 16 bits mono) et le joue sur l'enceinte via PulseAudio/PipeWire.
|
||||
Son entrypoint reconnecte l'enceinte et remet son volume toutes les 15 s.
|
||||
- **Limite** : ce n'est pas du WebRTC (Cloudflare ne transporte pas l'UDP).
|
||||
Latence du micro ~200 a 500 ms, mode ON/OFF et non duplex natif.
|
||||
|
||||
## Arborescence
|
||||
|
||||
/srv/apps/cam
|
||||
docker-compose.yml services go2rtc + mic-bridge
|
||||
go2rtc.yaml flux webcam (gain camera : volume=XXdB)
|
||||
Makefile commandes de gestion
|
||||
mic-bridge/ Dockerfile, server.js, index.html, entrypoint.sh
|
||||
scripts/cam-watch.* surveillance webcam (cron)
|
||||
|
||||
|
||||
## Prerequis
|
||||
|
||||
- Debian avec Docker + Compose, `make`, PipeWire (`pipewire-pulse`), BlueZ.
|
||||
- Reseau docker externe `shared-network` (partage avec le conteneur `app-tunnel`).
|
||||
- Utilisateur `esiahdmin` (UID 1001) : le socket Pulse est dans `/run/user/1001`.
|
||||
- Enceinte Bluetooth appairee (`69:B2:C0:04:A4:80`).
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
cd /srv/apps/cam
|
||||
make host-setup # une seule fois : linger, pipewire au boot, trust BT, micro webcam
|
||||
make up
|
||||
make cron-install # surveillance webcam
|
||||
make status
|
||||
```
|
||||
|
||||
## Configuration Cloudflare (dashboard, une seule fois)
|
||||
|
||||
1. **Tunnel** (Networks > Tunnels > Public Hostname), dans cet ordre :
|
||||
- `kaisa.esiah.dev` + chemin `mic*` -> `HTTP` `mic-bridge:8090`
|
||||
- `kaisa.esiah.dev` + chemin vide -> `HTTP` `go2rtc:1984`
|
||||
2. **Access** (Access > Applications) : une seule application sur `kaisa.esiah.dev`
|
||||
avec deux destinations : sans chemin, et `mic*`. Politique Allow limitee a votre email
|
||||
(One-time PIN si le fournisseur d'identite pose probleme).
|
||||
3. **Page d'accueil** (Rules > Redirect Rules) : `http.host eq "kaisa.esiah.dev"` et
|
||||
`http.request.uri.path eq "/"` -> redirection statique 302 vers `https://kaisa.esiah.dev/mic`.
|
||||
|
||||
Ne jamais supprimer la destination sans chemin dans Access : l'API go2rtc, camera comprise,
|
||||
deviendrait publique.
|
||||
|
||||
## Utilisation
|
||||
|
||||
- Ouvrir `https://kaisa.esiah.dev` (ou l'icone ajoutee a l'ecran d'accueil du telephone).
|
||||
- Cliquer sur la video pour activer le son de la camera.
|
||||
- Bouton **Micro ON/OFF** : active le micro du navigateur. Le son de la camera est coupe
|
||||
chez vous pendant que le micro est ON (evite l'echo).
|
||||
- Curseur **Gain** : volume de votre voix dans l'enceinte (0.2 a 5, defaut 1).
|
||||
- Le WebSocket se reconnecte seul ; l'ecran reste allume via Wake Lock si le navigateur le permet.
|
||||
|
||||
## Commandes (`make help`)
|
||||
|
||||
| Commande | Effet |
|
||||
|---|---|
|
||||
| `make up` / `down` / `restart` | Demarrer, arreter, redemarrer |
|
||||
| `make rebuild` / `update` | Reconstruire sans cache / mettre a jour les images |
|
||||
| `make status` | Diagnostic : webcam, carte son, conteneurs, Bluetooth, flux |
|
||||
| `make logs` / `logs-cam` / `logs-mic` | Logs en continu |
|
||||
| `make bt` | Reconnecter l'enceinte |
|
||||
| `make audio-fix` | Relancer pipewire + enceinte |
|
||||
| `make usb-reset` | Reset du controleur USB (coupe aussi le Bluetooth) |
|
||||
| `make speaker` | Bruit de test dans l'enceinte |
|
||||
| `make level` | Niveau du son camera (viser -25 a -30 dB) |
|
||||
| `make gain-cam GAIN=15` | Gain du son camera (dB) |
|
||||
| `make sink-volume SINKVOL=60%` | Volume de l'enceinte |
|
||||
| `make cron-install` / `cron-remove` / `cron-log` | Surveillance webcam |
|
||||
|
||||
Variables surchargeables : `BT_MAC`, `USER_ID`, `PCI_USB`, `GAIN`, `SINKVOL`.
|
||||
|
||||
## Reglages
|
||||
|
||||
- **Son camera trop faible/fort** : `make gain-cam GAIN=...` (12 par defaut, plage utile 8 a 20).
|
||||
- **Echo** : eloigner l'enceinte de la webcam, baisser `make sink-volume SINKVOL=50%`.
|
||||
- **Voix trop faible dans l'enceinte** : curseur Gain de la page, puis volume de l'enceinte.
|
||||
|
||||
## Depannage
|
||||
|
||||
| Symptome | Cause probable | Action |
|
||||
|---|---|---|
|
||||
| Pas d'image, `ERR [exec] timeout` | Webcam absente | `make status`; si `/dev/video*` absent : debrancher 30 s, rebrancher a l'arriere de la carte mere, `make restart` |
|
||||
| `dmesg` : `error -110` / `-62` sur `usb 1-3` | Alimentation/cable/port USB | Cable court, port direct, hub alimente, autre port ; sinon webcam defectueuse |
|
||||
| Image OK, pas de son camera | Son coupe par le navigateur ou gain trop bas | Cliquer sur la video ; `make level` |
|
||||
| Micro : WebSocket refuse (302) | Access ne couvre pas `/mic/ws` | Verifier les deux destinations de l'application Access |
|
||||
| Micro OK mais silence | Enceinte deconnectee | `make bt` ou `make audio-fix` ; `make speaker` pour tester |
|
||||
| `404` sur `/stream.html` | Regle tunnel manquante ou mal ordonnee | `mic*` d'abord, la regle sans chemin en dernier |
|
||||
| Boucle de 3 boutons dans la page | `/stream.html` route vers mic-bridge | Meme cause que ci-dessus |
|
||||
| Plus de son apres redemarrage pipewire | Sink Bluetooth perdu | `make audio-fix` |
|
||||
| Firefox : micro silencieux | AudioContext a 16 kHz refuse | Deja gere : la page utilise la frequence native du navigateur |
|
||||
|
||||
Journal de la surveillance : `make cron-log` (`/var/log/cam-watch.log`).
|
||||
|
||||
## Securite
|
||||
|
||||
- Aucun port publie : tout est joignable uniquement via le reseau docker et le tunnel.
|
||||
- Cloudflare Access est la seule barriere d'authentification : ne jamais la desactiver.
|
||||
- go2rtc tourne en `privileged` avec `/dev` monte pour survivre aux reenumerations USB.
|
||||
Si la webcam devient stable, remplacer par `devices: [/dev/video0, /dev/snd]` + `group_add: [video, audio]`.
|
||||
- Le conteneur mic-bridge monte `/run/user/1001` et le bus D-Bus pour piloter Bluetooth/Pulse.
|
||||
|
||||
## Sauvegarde et restauration
|
||||
|
||||
Tout est dans `/srv/apps/cam` (pas de volume de donnees). Sauvegarder ce dossier
|
||||
(par exemple dans le depot git) et rejouer :
|
||||
|
||||
```bash
|
||||
make host-setup && make up && make cron-install
|
||||
```
|
||||
@@ -0,0 +1,29 @@
|
||||
name: cam
|
||||
|
||||
services:
|
||||
go2rtc:
|
||||
image: alexxit/go2rtc
|
||||
container_name: go2rtc
|
||||
restart: unless-stopped
|
||||
privileged: true # survit aux ré-énumérations USB (video0/video1)
|
||||
volumes:
|
||||
- /dev:/dev
|
||||
- ./go2rtc.yaml:/config/go2rtc.yaml:ro
|
||||
networks: [shared-network]
|
||||
|
||||
mic-bridge:
|
||||
build: ./mic-bridge
|
||||
container_name: mic-bridge
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
BT_MAC: "69:B2:C0:04:A4:80"
|
||||
PULSE_SERVER: "unix:/run/user/1001/pulse/native"
|
||||
SINK_VOLUME: "70%"
|
||||
volumes:
|
||||
- /run/user/1001:/run/user/1001
|
||||
- /var/run/dbus:/var/run/dbus
|
||||
networks: [shared-network]
|
||||
|
||||
networks:
|
||||
shared-network:
|
||||
external: true
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
log:
|
||||
level: debug
|
||||
exec: debug
|
||||
|
||||
api:
|
||||
listen: ":1984"
|
||||
|
||||
streams:
|
||||
webcam:
|
||||
- "exec:ffmpeg -hide_banner -loglevel warning -f v4l2 -video_size 640x480 -framerate 15 -i /dev/video0 -thread_queue_size 512 -f alsa -ac 1 -ar 16000 -i hw:CARD=webcam,DEV=0 -c:v libx264 -preset ultrafast -tune zerolatency -profile:v baseline -pix_fmt yuv420p -g 30 -c:a aac -b:a 64k -af aresample=async=1,highpass=f=80,volume=20dB,alimiter=limit=0.95 -f rtsp {output}"
|
||||
@@ -0,0 +1,9 @@
|
||||
FROM node:22-slim
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
pulseaudio-utils bluez ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /app
|
||||
RUN npm i ws
|
||||
COPY server.js index.html entrypoint.sh ./
|
||||
RUN chmod +x entrypoint.sh
|
||||
CMD ["./entrypoint.sh"]
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
# Boucle de maintien : Bluetooth + volume de l'enceinte
|
||||
(
|
||||
while true; do
|
||||
if ! bluetoothctl info "$BT_MAC" 2>/dev/null | grep -q "Connected: yes"; then
|
||||
echo "[bt] connexion à $BT_MAC"
|
||||
bluetoothctl connect "$BT_MAC" >/dev/null 2>&1
|
||||
sleep 5
|
||||
fi
|
||||
if bluetoothctl info "$BT_MAC" 2>/dev/null | grep -q "Connected: yes"; then
|
||||
SINK=$(pactl list short sinks 2>/dev/null | grep -i bluez | awk '{print $2}' | head -1)
|
||||
if [ -n "$SINK" ]; then
|
||||
pactl set-default-sink "$SINK" 2>/dev/null
|
||||
pactl set-sink-volume "$SINK" "${SINK_VOLUME:-100%}" 2>/dev/null
|
||||
pactl set-sink-mute "$SINK" 0 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
sleep 15
|
||||
done
|
||||
) &
|
||||
exec node server.js
|
||||
@@ -0,0 +1,59 @@
|
||||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Cam</title>
|
||||
<body style="margin:0;font-family:sans-serif;background:#111;color:#eee">
|
||||
<iframe src="/stream.html?src=webcam&mode=mse" style="width:100%;height:62vh;border:0"></iframe>
|
||||
<div style="padding:6px 10px;display:flex;gap:10px;align-items:center">
|
||||
<span id="s" style="flex:1">micro éteint</span>
|
||||
<label>Gain <input id="g" type="range" min="0.2" max="5" step="0.1" value="1"></label>
|
||||
</div>
|
||||
<button id="b" style="width:100%;height:18vh;font-size:2rem">🎤 Micro OFF</button>
|
||||
<script>
|
||||
const s = document.getElementById('s'), b = document.getElementById('b'), g = document.getElementById('g');
|
||||
let ws, ctx, node, stream, wake, on = false, buf = [], n = 0;
|
||||
const worklet = URL.createObjectURL(new Blob([
|
||||
"class P extends AudioWorkletProcessor{process(i){const c=i[0][0];if(c)this.port.postMessage(c.slice(0));return true}}registerProcessor('p',P)"
|
||||
], { type: 'application/javascript' }));
|
||||
|
||||
function connect() {
|
||||
if (!on) return;
|
||||
ws = new WebSocket((location.protocol === 'https:' ? 'wss://' : 'ws://') + location.host + '/mic/ws');
|
||||
ws.onopen = () => { ws.send(JSON.stringify({ rate: ctx.sampleRate })); s.textContent = 'micro actif (' + ctx.sampleRate + ' Hz)'; };
|
||||
ws.onclose = () => { if (on) { s.textContent = 'reconnexion...'; setTimeout(connect, 1000); } };
|
||||
}
|
||||
async function lock() { try { wake = await navigator.wakeLock.request('screen'); } catch (e) {} }
|
||||
|
||||
async function start() {
|
||||
on = true; s.textContent = 'demande micro...';
|
||||
try { stream = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true } }); }
|
||||
catch (e) { on = false; s.textContent = 'micro refusé: ' + e.message; return; }
|
||||
ctx = new AudioContext(); await ctx.resume();
|
||||
await ctx.audioWorklet.addModule(worklet);
|
||||
const src = ctx.createMediaStreamSource(stream);
|
||||
node = new AudioWorkletNode(ctx, 'p');
|
||||
node.port.onmessage = e => {
|
||||
buf.push(e.data); n += e.data.length;
|
||||
if (n < 2048) return;
|
||||
const o = new Int16Array(n), k0 = +g.value; let k = 0;
|
||||
for (const c of buf) for (let i = 0; i < c.length; i++) o[k++] = Math.max(-1, Math.min(1, c[i] * k0)) * 32767;
|
||||
buf = []; n = 0;
|
||||
if (ws && ws.readyState === 1) ws.send(o.buffer);
|
||||
};
|
||||
const mute = ctx.createGain(); mute.gain.value = 0;
|
||||
src.connect(node); node.connect(mute); mute.connect(ctx.destination);
|
||||
connect(); lock(); try { document.querySelector('iframe').contentDocument.querySelector('video').muted = true; } catch (e) {}
|
||||
b.textContent = '🎤 Micro ON (toucher pour couper)';
|
||||
}
|
||||
function stop() {
|
||||
on = false; s.textContent = 'micro éteint'; b.textContent = '🎤 Micro OFF';
|
||||
try { node && node.disconnect(); } catch (e) {}
|
||||
stream && stream.getTracks().forEach(t => t.stop());
|
||||
ctx && ctx.close(); ws && ws.close(); wake && wake.release().catch(() => {});
|
||||
node = stream = ctx = ws = wake = null; buf = []; n = 0;
|
||||
}
|
||||
b.onclick = () => on ? stop() : start();
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (on && document.visibilityState === 'visible') { ctx && ctx.resume(); lock(); }
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,36 @@
|
||||
const http = require('http'), fs = require('fs'), { spawn } = require('child_process');
|
||||
const { WebSocketServer } = require('ws');
|
||||
const page = fs.readFileSync('index.html');
|
||||
const srv = http.createServer((q, r) => {
|
||||
if (q.url.split('?')[0] !== '/mic') { r.statusCode = 404; return r.end(); }
|
||||
r.setHeader('content-type', 'text/html');
|
||||
r.end(page);
|
||||
});
|
||||
const wss = new WebSocketServer({ server: srv, path: '/mic/ws' });
|
||||
let active = null;
|
||||
wss.on('connection', ws => {
|
||||
if (active) { try { active.ws.close(); } catch (e) {} try { active.p && active.p.stdin.end(); } catch (e) {} }
|
||||
const me = { ws, p: null };
|
||||
active = me;
|
||||
ws.isAlive = true;
|
||||
ws.on('pong', () => { ws.isAlive = true; });
|
||||
ws.on('message', (d, bin) => {
|
||||
if (!bin) {
|
||||
if (me.p) return;
|
||||
let rate = 48000;
|
||||
try { rate = parseInt(JSON.parse(d.toString()).rate) || 48000; } catch (e) {}
|
||||
me.p = spawn('paplay', ['--raw', '--rate=' + rate, '--format=s16le', '--channels=1', '--latency-msec=150']);
|
||||
me.p.on('error', e => console.log('paplay error', e.message));
|
||||
me.p.stdin.on('error', () => {});
|
||||
console.log('mic start', rate);
|
||||
return;
|
||||
}
|
||||
if (me.p) me.p.stdin.write(d);
|
||||
});
|
||||
ws.on('close', () => { if (me.p) me.p.stdin.end(); if (active === me) active = null; console.log('mic stop'); });
|
||||
});
|
||||
setInterval(() => wss.clients.forEach(ws => {
|
||||
if (!ws.isAlive) return ws.terminate();
|
||||
ws.isAlive = false; ws.ping();
|
||||
}), 20000);
|
||||
srv.listen(8090);
|
||||
@@ -0,0 +1,2 @@
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
* * * * * root /usr/local/bin/cam-watch
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
LOG=/var/log/cam-watch.log
|
||||
STAMP=/run/cam-watch.last
|
||||
STATE=/run/cam-watch.state
|
||||
COOLDOWN=120
|
||||
now=$(date +%s)
|
||||
last=$(cat "$STAMP" 2>/dev/null || echo 0)
|
||||
[ $((now - last)) -lt $COOLDOWN ] && exit 0
|
||||
|
||||
recreate() {
|
||||
echo "$(date '+%F %T') $1 : recreation go2rtc" >> "$LOG"
|
||||
(cd /srv/apps/cam && docker compose up -d --force-recreate go2rtc >/dev/null 2>&1)
|
||||
echo "$now" > "$STAMP"
|
||||
}
|
||||
|
||||
prev=$(cat "$STATE" 2>/dev/null || echo ok)
|
||||
|
||||
# Webcam reellement presente ? (lsusb plus fiable que /dev/video0 qui peut etre perime)
|
||||
if lsusb | grep -q '1d5b:0104'; then
|
||||
if [ "$prev" = "absent" ]; then
|
||||
echo "$(date '+%F %T') webcam revenue" >> "$LOG"
|
||||
echo "ok" > "$STATE"
|
||||
sleep 5
|
||||
recreate "retour webcam"
|
||||
exit 0
|
||||
fi
|
||||
echo "ok" > "$STATE"
|
||||
if [ "$(docker inspect -f '{{.State.Running}}' go2rtc 2>/dev/null)" != "true" ]; then
|
||||
recreate "go2rtc arrete"
|
||||
fi
|
||||
else
|
||||
[ "$prev" != "absent" ] && echo "$(date '+%F %T') webcam ABSENTE (probleme USB)" >> "$LOG"
|
||||
echo "absent" > "$STATE"
|
||||
fi
|
||||
Reference in New Issue
Block a user