#!/bin/bash
json() {
	python3 -c "
import json,sys
try:
	print(json.load(sys.stdin)$@)
except IndexError:
	pass
"
}

while true; do
	ENDPOINTS=$(curl -s http://127.0.0.1:8080/colibri/stats |json "['local_active_endpoints']")
	[ "$ENDPOINTS" = "0" -o -z "$ENDPOINTS" ] && break
	sleep 1m
done
echo IDLE

/federated/bin/stop jitsi
/federated/bin/start jitsi
