Kaynağa Gözat

Merge branch 'master' of https://gogs.halsbox.ru/RRT/pbx

Hal De 4 yıl önce
ebeveyn
işleme
2bd9dddf91
9 değiştirilmiş dosya ile 145 ekleme ve 15 silme
  1. 2 2
      pjsua/Dockerfile
  2. 6 4
      pjsua/auto-answer
  3. 52 0
      pjsua/busy
  4. 6 5
      pjsua/dial
  5. 2 0
      pjsua/docker-entrypoint.sh
  6. 12 0
      pjsua/profile
  7. 4 4
      pjsua/register
  8. 52 0
      pjsua/reject
  9. 9 0
      sip_test.sh

+ 2 - 2
pjsua/Dockerfile

@@ -4,14 +4,14 @@ ENV ENV="/etc/profile"
 ENV WORKDIR /app
 WORKDIR ${WORKDIR}
 
-RUN apk add --update --no-cache \
-      pjsua \
+RUN apk add --update --no-cache pjsua\
  && echo "export PATH=\"${WORKDIR}:${PATH}\"" > /etc/profile.d/pjsua-path.sh \
  && chmod +x /etc/profile.d/pjsua-path.sh \
  && rm -rf /var/cache/apk/* \
            /tmp/* \
            /var/tmp/*
 
+COPY profile /etc/profile
 COPY . .
 
 ENTRYPOINT ["/app/docker-entrypoint.sh"]

+ 6 - 4
pjsua/auto-answer

@@ -8,7 +8,7 @@ if [ "${SIP_USERNAME}" == "" ]; then
 fi
 
 SIP_SERVER_HOST=${SIP_SERVER_HOST:-asterisk}
-SIP_SERVER_PORT=${SIP_SERVER_PORT:-5160}
+SIP_SERVER_PORT=5160
 SIP_PASSWORD=${SIP_PASSWORD:-asterisk}
 
 # udp, tcp
@@ -19,11 +19,12 @@ LOCAL_PORT=$(shuf -i 50001-55999 -n 1)
 RTP_PORT=$(shuf -i 56001-59999 -n 1)
 
 pjsua \
-  --log-level=0 \
-  --app-log-level=0 \
+  --log-level=3 \
+  --app-log-level=3 \
   --no-stderr \
   --color \
   --light-bg \
+  --use-cli \
   --null-audio \
   --snd-auto-close=0 \
   --max-calls=15 \
@@ -47,4 +48,5 @@ pjsua \
   --id="sip:${SIP_USERNAME}@${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
   --username="${SIP_USERNAME}" \
   --password="${SIP_PASSWORD}" \
-  --auto-answer=200
+  --auto-answer=200 \
+  --duration=90

+ 52 - 0
pjsua/busy

@@ -0,0 +1,52 @@
+#!/bin/sh
+
+SIP_USERNAME=$1
+
+if [ "${SIP_USERNAME}" == "" ]; then
+  echo "Missing CLI argument: SIP_USERNAME. Exiting"
+  exit 1
+fi
+
+SIP_SERVER_HOST=${SIP_SERVER_HOST:-asterisk}
+SIP_SERVER_PORT=5160
+SIP_PASSWORD=${SIP_PASSWORD:-asterisk}
+
+# udp, tcp
+SIP_TRANSPORT=${SIP_TRANSPORT:-udp}
+
+# random ports in a range
+LOCAL_PORT=$(shuf -i 50001-55999 -n 1)
+RTP_PORT=$(shuf -i 56001-59999 -n 1)
+
+# https://stackoverflow.com/questions/48338005/how-to-hang-up-call-in-pjsip-while-its-ringing
+pjsua \
+  --log-level=3 \
+  --app-log-level=3 \
+  --no-stderr \
+  --color \
+  --light-bg \
+  --use-cli \
+  --null-audio \
+  --snd-auto-close=0 \
+  --max-calls=15 \
+  --no-vad \
+  --use-compact-form \
+  --reg-timeout=90 \
+  --rereg-delay=90 \
+  --use-srtp=0 \
+  --srtp-secure=0 \
+  --rtcp-mux \
+  --use-timer=1 \
+  --reg-use-proxy=3 \
+  --auto-update-nat=1 \
+  --disable-stun \
+  --local-port=${LOCAL_PORT} \
+  --rtp-port=${RTP_PORT} \
+  --realm="*" \
+  --registrar="sip:${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
+  --proxy="sip:${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
+  --outbound="sip:${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
+  --id="sip:${SIP_USERNAME}@${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
+  --username="${SIP_USERNAME}" \
+  --password="${SIP_PASSWORD}" \
+  --auto-answer=486

+ 6 - 5
pjsua/dial

@@ -14,7 +14,7 @@ if [ "${DESTINATION}" == "" ]; then
 fi
 
 SIP_SERVER_HOST=${SIP_SERVER_HOST:-asterisk}
-SIP_SERVER_PORT=${SIP_SERVER_PORT:-5160}
+SIP_SERVER_PORT=5160
 SIP_PASSWORD=${SIP_PASSWORD:-asterisk}
 
 # udp, tcp
@@ -25,14 +25,14 @@ LOCAL_PORT=$(shuf -i 50001-55999 -n 1)
 RTP_PORT=$(shuf -i 56001-59999 -n 1)
 
 pjsua \
-  --log-level=0 \
-  --app-log-level=0 \
+  --log-level=3 \
+  --app-log-level=3 \
   --no-stderr \
   --color \
   --light-bg \
   --null-audio \
   --snd-auto-close=0 \
-  --max-calls=15 \
+  --max-calls=4 \
   --no-vad \
   --use-compact-form \
   --reg-timeout=90 \
@@ -53,4 +53,5 @@ pjsua \
   --id="sip:${SIP_USERNAME}@${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
   --username="${SIP_USERNAME}" \
   --password="${SIP_PASSWORD}" \
-  "sip:${DESTINATION}@${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}"
+  "sip:${DESTINATION}@${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
+  --duration=90

+ 2 - 0
pjsua/docker-entrypoint.sh

@@ -1,3 +1,5 @@
 #!/bin/sh
 
+. /etc/profile
+
 exec "$@"

+ 12 - 0
pjsua/profile

@@ -0,0 +1,12 @@
+export CHARSET=UTF-8
+export LANG=C.UTF-8
+export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+export PAGER=less
+export PS1='\h:\w\$ '
+umask 022
+
+for script in /etc/profile.d/*.sh ; do
+        if [ -r $script ] ; then
+                . $script
+        fi
+done

+ 4 - 4
pjsua/register

@@ -8,7 +8,7 @@ if [ "${SIP_USERNAME}" == "" ]; then
 fi
 
 SIP_SERVER_HOST=${SIP_SERVER_HOST:-asterisk}
-SIP_SERVER_PORT=${SIP_SERVER_PORT:-5160}
+SIP_SERVER_PORT=5160
 SIP_PASSWORD=${SIP_PASSWORD:-asterisk}
 
 # udp, tcp
@@ -19,14 +19,14 @@ LOCAL_PORT=$(shuf -i 50001-55999 -n 1)
 RTP_PORT=$(shuf -i 56001-59999 -n 1)
 
 pjsua \
-  --log-level=0 \
-  --app-log-level=0 \
+  --log-level=3 \
+  --app-log-level=3 \
   --no-stderr \
   --color \
   --light-bg \
   --null-audio \
   --snd-auto-close=0 \
-  --max-calls=15 \
+  --max-calls=4 \
   --no-vad \
   --use-compact-form \
   --reg-timeout=90 \

+ 52 - 0
pjsua/reject

@@ -0,0 +1,52 @@
+#!/bin/sh
+
+SIP_USERNAME=$1
+
+if [ "${SIP_USERNAME}" == "" ]; then
+  echo "Missing CLI argument: SIP_USERNAME. Exiting"
+  exit 1
+fi
+
+SIP_SERVER_HOST=${SIP_SERVER_HOST:-asterisk}
+SIP_SERVER_PORT=5060
+SIP_PASSWORD=${SIP_PASSWORD:-asterisk}
+
+# udp, tcp
+SIP_TRANSPORT=${SIP_TRANSPORT:-udp}
+
+# random ports in a range
+LOCAL_PORT=$(shuf -i 50001-55999 -n 1)
+RTP_PORT=$(shuf -i 56001-59999 -n 1)
+
+# https://stackoverflow.com/questions/48338005/how-to-hang-up-call-in-pjsip-while-its-ringing
+pjsua \
+  --log-level=3 \
+  --app-log-level=3 \
+  --no-stderr \
+  --color \
+  --light-bg \
+  --use-cli \
+  --null-audio \
+  --snd-auto-close=0 \
+  --max-calls=15 \
+  --no-vad \
+  --use-compact-form \
+  --reg-timeout=90 \
+  --rereg-delay=90 \
+  --use-srtp=0 \
+  --srtp-secure=0 \
+  --rtcp-mux \
+  --use-timer=1 \
+  --reg-use-proxy=3 \
+  --auto-update-nat=1 \
+  --disable-stun \
+  --local-port=${LOCAL_PORT} \
+  --rtp-port=${RTP_PORT} \
+  --realm="*" \
+  --registrar="sip:${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
+  --proxy="sip:${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
+  --outbound="sip:${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
+  --id="sip:${SIP_USERNAME}@${SIP_SERVER_HOST}:${SIP_SERVER_PORT};transport=${SIP_TRANSPORT}" \
+  --username="${SIP_USERNAME}" \
+  --password="${SIP_PASSWORD}" \
+  --auto-answer=603

+ 9 - 0
sip_test.sh

@@ -0,0 +1,9 @@
+#!/bin/bash
+ACC=$2
+set -a
+source <(cat .env app.env | sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g")
+set +a
+PASS=$(curl -s -X GET "http://127.0.0.1:${APP_API_PORT}/ami/auths" -H  "${APP_AUTH_HEADER}: ${APP_AUTH_SECRET}" | jq -r ".data.\"${ACC}\"")
+docker run -ti --rm --net=host -e SIP_SERVER_HOST=${APP_AMI_HOST} -e SIP_SERVER_PORT=5160 -e SIP_PASSWORD=${PASS} halsbox/pjsua "$@"
+reset
+