I'm initiating a call from a WebRTC browser and SIP client and want to play a .wav file using endless_playback after a call is bridged to another party over the PTSN. I tried two things, neither of which works.
a) Using the dialplan
<action application="endless_playback" data="the path of wav file"/> //option 1
<action application="bridge" data="the call info"/>
<action application="endless_playback" data="the path of wav file"/> //option 2
The problem is that in option 1 the file plays but the call is never bridged and in option 2 the file plays after the receiving call hangs up.
b) Using a LUA script
local TheSound = "the path of the wav file"
if (session:ready() == true) then
session:execute("playback", TheSound)
end
This seemed more likely to work but it didn't because I need to execute the playback after the bridge occured.
I think I need to change the LUA script line to the following pseudocode
listen for call connected event and then
session:execute("playback", TheSound)
How could I do this?
I found a working solution using uuid_broadcast
Step 1: in the dialplan, add this line just before the bridge
<action application="export" data="nolocal:execute_on_answer=lua somescript.lua"/>
<action application="bridge" data="the bridge info"/>
Note that if you're setting the value of a variable before the bridge and need to access it from the lua script after the bridge, make sure to also add this line:
<action application="export" data="thevariable=${thevariable}"/>
Step 2: in the somescript.lua file, you need to first determine the uuid of the call and then you can broadcast a sound into that call, and even choose into which leg you're playing the file:
local theuuid = session:getVariable('uuid')
api = freeswitch.API()
local thesoundcast = "uuid_broadcast "..theuuid.."pathofsoundfile.wav aleg"
api:executeString(thesoundcast)
And voilà.