Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Mar 27, 2024
1 parent c7a59e0 commit bd02905
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 227 deletions.
2 changes: 1 addition & 1 deletion components/testing/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ "$1" = 'start' ]; then
WS_SERVER_PORT="${WS_SERVER_PORT:="3001"}"

sipp -sf ./scenarios/uas.xml -bg -trace_msg
nohup node ./support/ws_server/server_twilio.js "$WS_SERVER_AUDIO_OUTPUT" --port "$WS_SERVER_PORT" > ws-server.log &
nohup node ./support/ws_server/test_server.js --port "$WS_SERVER_PORT" > ws-server.log &
tail -f /dev/null
fi

Expand Down
Binary file removed components/testing/scenarios/files/8kalaw.wav
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<!-- Sipp 'uac' scenario with pcap (rtp) play -->
<!-- -->

<scenario name="UAC with media">
<scenario name="UAC to test Connect Stream">
<!-- In client mode (sipp placing calls), the Call-ID MUST be -->
<!-- generated by sipp. To do so, use [call_id] keyword. -->
<send retrans="500">
Expand Down
131 changes: 0 additions & 131 deletions components/testing/scenarios/uac_pcap.xml

This file was deleted.

35 changes: 0 additions & 35 deletions components/testing/support/ws_server/server.js

This file was deleted.

54 changes: 0 additions & 54 deletions components/testing/support/ws_server/server_twilio.js

This file was deleted.

57 changes: 57 additions & 0 deletions components/testing/support/ws_server/test_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const WebSocket = require("ws");
const AudioTestStream = require("./audio_test_stream.js")

const argv = require("minimist")(process.argv);
const port = argv.port && parseInt(argv.port) ? parseInt(argv.port) : 3001;

const wss = new WebSocket.Server({
port,
handleProtocols: () => {
return "audio.somleng.org";
},
});

const audioStream = new AudioTestStream();
wss.on("connection", (ws) => {
ws.on("message", (message) => {
console.log(`received message: ${message}`);
console.log(`message type: ${message.type}`);

if (message.type === "utf8") {
try {
const data = JSON.parse(message.utf8Data);
if (data.event === "connected") {
log("From Twilio: Connected event received: ", data);
}
if (data.event === "start") {
log("From Twilio: Start event received: ", data);
audioStream.initializeAudio(data['streamSid'])
}
if (data.event === "media") {
log("From Twilio: Media event received: ", data);
const b64string = data['media']["payload"]
audioStream.appendAudio(Buffer.from(b64string, 'base64'))
}
if (data.event === "dtmf") {
log("From Twilio: DTMF event received: ", data);
audioStream.streamStoredAudio(ws);
}
if (data.event === "mark") {
log("From Twilio: Mark event received", data);
audioStream.streamStoredAudio(ws);
}
if (data.event === "close") {
log("From Twilio: Close event received: ", data);
ws.close();
}
} catch (e) {
console.log(`received message <err>: ${message}`);
console.log(e)
}
}
});

ws.on("close", (code, reason) => {
console.log(`socket closed ${code}:${reason}`);
});
});
16 changes: 11 additions & 5 deletions components/testing/tests/public_gateway/connect_stream_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ current_dir=$(dirname "$(readlink -f "$0")")
source $current_dir/support/test_helpers.sh
source $current_dir/../support/test_helpers.sh

scenario=$current_dir/../../scenarios/uac_twilio.xml
scenario=$current_dir/../../scenarios/uac_connect.xml

log_file="uac_pcap_*_messages.log"
rm -f $log_file
Expand All @@ -26,10 +26,10 @@ sipp -sf $scenario public_gateway:5060 -key username "+855715100850" -s 2222 -m

echo "Killing TCPDUMP after sipp"

#kill tcpdump
kill $TCPDUMP_PID
# kill tcpdump
kill $TCPDUMP_PID

#extact audio
# extract audio
tshark -n -r capture.pcap -2 -R rtp -T fields -e rtp.payload | tr -d '\n',':' | xxd -r -p >call.rtp
sox -t al -r 8000 -c 1 call.rtp call.wav

Expand All @@ -38,7 +38,13 @@ expectedFile=$current_dir/../../scenarios/files/expected.wav

reset_db

if [[ "$(md5sum call.wav)" != "$(md5sum $expectedFile)" ]]; then
actual_md5=$(md5sum call.wav | head -c 32)
expected_md5=$(md5sum $expectedFile | head -c 32)

echo "Act MD5: $actual_md5"
echo "Exp MD5: $expected_md5"

if [[ "$actual_md5" != "$expected_md5" ]]; then
exit 1
fi
# Assert correct IP in SDP
Expand Down

0 comments on commit bd02905

Please sign in to comment.