File size: 3,219 Bytes
773fdad
85de5c2
3eab2ab
c923cfb
3eab2ab
 
e63c7b1
d7655f5
 
e63c7b1
d7655f5
7f8eb3f
d7655f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f8eb3f
61ef63c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7655f5
 
61ef63c
d7655f5
 
 
e63c7b1
0fef9c7
0187cb0
653ab24
8e8e54f
e63c7b1
157d570
6f68c21
d7655f5
6f68c21
 
 
e1d4625
6f68c21
 
653ab24
 
 
 
 
 
e63c7b1
 
653ab24
 
 
 
 
 
 
 
 
 
3eab2ab
0693322
7a4972b
 
 
 
 
53d2b30
c923cfb
3eab2ab
 
 
 
c923cfb
3eab2ab
 
 
5704cbc
c923cfb
 
 
 
 
3eab2ab
 
ea56e9c
3eab2ab
9ef2a90
 
b05ceb8
3eab2ab
0211e6d
3eab2ab
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash

set -e

# Detect external/public IP dynamically (you can hardcode this if needed)
# EXTERNAL_IP=$(curl -s https://ifconfig.me)
echo "Starting ngrok in background..."
NGROK_LOG=/tmp/ngrok.log
ngrok start turn_tls --config /ngrok2/ngrok.yml --log=stdout --log-level=debug > "$NGROK_LOG" 2>&1 &
NGROK_PID=$!

echo "Waiting for ngrok TCP tunnel..."

# Retry loop to wait until the TCP URL appears
for i in $(seq 1 30); do
    # Look for tcp:// in stdout
    PUBLIC_TCP=$(grep -o 'tcp://[0-9a-zA-Z\.-]*:[0-9]*' "$NGROK_LOG" | head -n 1)
    if [ -n "$PUBLIC_TCP" ]; then
        break
    fi
    sleep 1
done

if [ -z "$PUBLIC_TCP" ]; then
    echo "Error: Could not find ngrok TCP public URL."
    exit 1
fi

echo "Ngrok public TCP URL: $PUBLIC_TCP"
# Retry loop until public TCP address is available
# PUBLIC_TCP=""
# while [[ -z "$PUBLIC_TCP" ]]; do
#     sleep 2

#     # Get tunnels JSON safely
#     JSON=$(curl -s http://127.0.0.1:7860/api/tunnels || echo "{}")

#     # Try parsing TCP tunnel
#     PUBLIC_TCP=$(echo "$JSON" | python3 -c "
# import sys, json
# try:
#     data = json.load(sys.stdin)
#     tunnels = data.get('tunnels', [])
#     for t in tunnels:
#         if t.get('proto')=='tcp':
#             print(t.get('public_url','').replace('tcp://',''))
#             break
# except Exception:
#     pass
# " || echo "")

# done 
# echo "PUBLIC ip :$PUBLIC_TCP"
# # Extract host and host:port
 TURN_HOST="${PUBLIC_TCP%%:*}"
 TURN_HOST_PORT="$PUBLIC_TCP"

export TURN_PUBLIC_ADDR="$TURN_HOST_PORT"
export TURN_HOST="$TURN_HOST"
export TURN_HOST_PORT="$TURN_HOST_PORT"

echo "Server $TURN_PUBLIC_ADDR, ** $TURN_HOST ** $TURN_HOST_PORT"
echo "Starting turnserver..."
exec turnserver \
#     -c /etc/coturn/turnserver.conf \
#     --listening-ip=0.0.0.0 \
     --listening-port=7860 \
     --tls-listening-port=5349 \
     --external-ip="$TURN_PUBLIC_ADDR" \
#     --cert=/etc/turn/certs/turn_server_cert.pem \
#     --pkey=/etc/turn/certs/turn_server_pkey.pem \
     --user=myuser:mypassword \
#     --realm="$TURN_PUBLIC_ADDR" \
     --log-file=stdout \
     --simple-log \
     --no-cli &
TURN_PID=$!









# Now exec turnserver as PID 1 (so Docker will forward signals to it)


#cat /ngrok2/ngrok.yml
#ngrok start turn_tls --config /ngrok2/ngrok.yml --log=stdout --log-level=debug

  
 

# turnserver \
# -c /etc/coturn/turnserver.conf \
# --user=myuser:mypassword \
# --no-cli &
# #TURN_PID=$!


# ngrok config add-authtoken "$NGROK_AUTHTOKEN"
# ngrok authtoken "$NGROK_AUTHTOKEN"
# ngrok tls 7860 -url heather-tressy-paxton.ngrok-free.app
# ngrok tcp 7860 --log=stdout &

# ngrok start cli-quickstart
# ngrok config check --config ngrok2/ngrok.yml
# ngrok start turn_tls --config=ngrok2/ngrok.yml



# #!/bin/bash
# set -e

# # Optional: Print ngrok config
# cat /ngrok2/ngrok.yml

# # Start turnserver in background
#turnserver -c /etc/coturn/turnserver.conf --no-cli &
#TURN_PID=$!

# ngrok start turn_tls --config /ngrok2/ngrok.yml --log=stdout --log-level=debug

# # Trap termination signals to cleanly stop turnserver
# trap "echo 'Stopping turnserver'; kill $TURN_PID; wait $TURN_PID; exit" SIGINT SIGTERM

# # Exec the CMD (ngrok command) passed as args to this script
# exec "$@"