Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Feb 2, 2025
1 parent ca508d0 commit 62d720a
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 1 deletion.
48 changes: 47 additions & 1 deletion components/app/lib/call_platform/fake_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,34 @@ def audio_file_url
end
end

class DialTestNumber < TestNumber
Number = Data.define(:number)

DIAL_TO = [
Number.new(number: "85516701999"),
Number.new(number: "855715100999")
].freeze

def twiml_response
<<~TWIML
<Response>
<Dial>
<Number>#{self.class.dial_to[0].number}</Number>
<Number>#{self.class.dial_to[1].number}</Number>
</Dial>
</Response>
TWIML
end

def self.dial_to
DIAL_TO
end
end

TEST_NUMBERS = [
TestNumber.new(number: "1111", twiml_response: "<Response><Say>Hello World!</Say><Hangup /></Response>"),
ConnectTestNumberWithTwiMLResponse.new(number: "2222")
ConnectTestNumberWithTwiMLResponse.new(number: "2222"),
DialTestNumber.new(number: "3333")
].freeze

def create_inbound_call(params)
Expand All @@ -62,6 +87,27 @@ def create_media_stream(**)
AudioStreamResponse.new(id: SecureRandom.uuid)
end

def create_outbound_calls(params)
DialTestNumber.dial_to.map do |n|
OutboundPhoneCallResponse.new(
sid: SecureRandom.uuid,
parent_call_sid: params.fetch(:parent_call_sid),
account_sid: SecureRandom.uuid,
from: params.fetch(:from) || "855715100850",
routing_parameters: {
destination: n.number,
dial_string_prefix: nil,
plus_prefix: false,
national_dialing: false,
host: "sip.example.com",
username: nil,
symmetric_latching: true
},
address: nil
)
end
end

private

def validate_gateway_headers(params)
Expand Down
42 changes: 42 additions & 0 deletions components/app/spec/lib/call_platform/fake_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ module CallPlatform
twiml: include("<Connect>")
)
end

it "returns a mock <Dial> response" do
client = FakeClient.new

response = client.create_inbound_call(
to: "3333",
from: "+855715200987"
)

expect(response).to have_attributes(
twiml: include("<Dial>")
)
end
end

describe "#create_media_stream" do
Expand All @@ -61,5 +74,34 @@ module CallPlatform
)
end
end

describe "#create_outbound_calls" do
it "returns mock outbound calls" do
client = FakeClient.new

response = client.create_outbound_calls(
destinations: [ "85516701999", "855715100999" ],
parent_call_sid: "0df546d9-3348-48a7-b797-5a18dac477d2",
from: nil
)

expect(response).to contain_exactly(
have_attributes(
from: "855715100850",
parent_call_sid: "0df546d9-3348-48a7-b797-5a18dac477d2",
routing_parameters: hash_including(
destination: "85516701999"
)
),
have_attributes(
from: "855715100850",
parent_call_sid: "0df546d9-3348-48a7-b797-5a18dac477d2",
routing_parameters: hash_including(
destination: "855715100999"
)
)
)
end
end
end
end
68 changes: 68 additions & 0 deletions components/testing/tests/public_gateway/dial_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh

set -e

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_connect.xml
artifacts_dir=dial_test_files

log_file="uac_connect_*_messages.log"
rm -f $log_file

media_server="$(dig +short freeswitch)"

reset_db
create_load_balancer_entry "gw" "5060"
create_address_entry $(hostname -i)
reload_opensips_tables

rm -rf $artifacts_dir
mkdir -p $artifacts_dir

# start tcpdump in background
nohup tcpdump -Xvv -i eth0 -s0 -w $artifacts_dir/uac_connect.pcap &
tcpdump_pid=$!

sipp -sf $scenario public_gateway:5060 -key username "+855715100850" -s 3333 -m 1 -trace_msg > /dev/null

reset_db

# kill tcpdump
kill $tcpdump_pid

# extract RTP from PCAP
# tshark -n -r $artifacts_dir/uac_connect.pcap -2 -R rtp -T fields -e rtp.payload | tr -d '\n',':' | xxd -r -p > $artifacts_dir/uac_connect.rtp
# # Convert RTP to wav
# sox -t al -r 8000 -c 1 $artifacts_dir/uac_connect.rtp $artifacts_dir/uac_connect_full_audio.wav
# # Cut the audio from the ws server
# ffmpeg -y -i $artifacts_dir/uac_connect_full_audio.wav -ss 8.5 -to 12 $artifacts_dir/uac_connect_ws_server_audio.wav 2> /dev/null
# # Remove silence
# ffmpeg -y -i $artifacts_dir/uac_connect_ws_server_audio.wav -af silenceremove=1:0:-30dB,areverse,silenceremove=1:0:-30dB,areverse $artifacts_dir/uac_connect_trimmed_ws_server_audio.wav 2> /dev/null
# # Cut the play verb audio
# ffmpeg -y -i $artifacts_dir/uac_connect_full_audio.wav -ss 12.2 $artifacts_dir/uac_connect_play_verb_audio.wav 2> /dev/null
# # Remove silence
# ffmpeg -y -i $artifacts_dir/uac_connect_play_verb_audio.wav -af silenceremove=1:0:-30dB,areverse,silenceremove=1:0:-30dB,areverse $artifacts_dir/uac_connect_trimmed_play_verb_audio.wav 2> /dev/null

# ws_server_audio_md5=$(md5sum $artifacts_dir/uac_connect_trimmed_ws_server_audio.wav | head -c 32)
# play_verb_audio_md5=$(md5sum $artifacts_dir/uac_connect_trimmed_play_verb_audio.wav | head -c 32)
# expected_audio_md5="1c1542575c47ef620c8344438e75095f"

# echo "Actual ws_server_audio_md5: $ws_server_audio_md5"
# echo "Actual play_verb_audio_md5: $play_verb_audio_md5"
# echo "Expected audio_md5: $expected_audio_md5"

# if [[ "$ws_server_audio_md5" != "$expected_audio_md5" ]]; then
# exit 1
# fi

# if [[ "$play_verb_audio_md5" != "$expected_audio_md5" ]]; then
# exit 1
# fi

# # Assert correct IP in SDP
# if ! assert_in_file $log_file "c=IN IP4 $media_server"; then
# exit 1
# fi

0 comments on commit 62d720a

Please sign in to comment.