I am currently experimenting with adding a higher-level wrapper for AudioSocket
support to my Seaskirt Python API module. I have an example FastAGI script, which I intend to publish. It is being invoked via a dialplan context like this:
[fastagi-audio-player]
; see fastagi_audio_player_async example script for how this works
exten => _X.,1,Verbose(entering FastAGI/AudioSocket setup)
exten => _X.,n,AGI(agi://127.0.0.1:9902/start,${EXTEN},UUID,SVC)
exten => _X.,n,Verbose(entering FastAGI/AudioSocket audio player)
exten => _X.,n,AudioSocket(${UUID},${SVC})
exten => _X.,n,Verbose(exiting FastAGI/AudioSocket audio player)
exten => _X.,n,Hangup()
Notice how it is passed the extension being dialled, which in the script is mapped to an audio file to be played. It is also passed two strings, being the names of variables to be used in the actual AudioSocket()
dialplan command to establish the audio connection.
I have been testing it to ensure it handles both the situation where the caller hangs up before the audio finishes playing, and also when the end of the audio is reached, in which case it terminates the AudioSocket connection. At this point, I expect the dialplan to continue execution, and display that “exiting” message before hanging up.
However, what I find is that that message never appears. Seems like once a channel enters AudioSocket mode, it has to stay that way until the call is hung up, one way or another.
Is this right? I can’t find anything in the documentation that makes that clear.
Also, another thing I found is that, if I simply close my end of the AudioSocket connection, then Asterisk doesn’t seem to correctly hang up the channel. I have to explicitly send a packet with ID code 0 (“terminate the connection”, as per the protocol) before closing, and then the channel correctly disappears. But not before producing a somewhat untidy error message:
ERROR[2140][C-00000013]: app_audiosocket.c:206 audiosocket_run: Failed to receive frame from AudioSocket message forchannel PJSIP/test-client-00000012
(Note how the words “for” and “channel” are run together.)
I am doing this testing with Asterisk 20.6 in an Ubuntu 24.04 container, that being the oldest Asterisk version currently in support, I believe. I also intend to test against Asterisk 22 in my Debian host OS at some point. (Asterisk 20 was never packaged for Debian, which is why I installed Ubuntu for that.)
Feel free to let me know if anything looks wrong.