Search code examples
audioluaplaybackfreeswitch

Stop a playback in Freeswitch


I have some code in Lua that answers a call, and after performing a series of operations bridges the call to a new leg.

The operations take from a few seconds to several minutes.

To keep the client I need to play a sound the issue I have is that the playback is still going on after the call is bridged.

The specific question is, how to stop a sound called from a playback ?

My code looks like

session:answer()
session:execute("playback", '/some/file.wav')
.
.
.
local connectionString = '{bypass_media=true,origination_caller_id_number=555,destination_number=646}'
connectionString = connectionString .. 'sofia/external/192.168.0.1@1000'
session:execute('bridge', connectionString)

Solution

  • I had a similar task, and solved it by launching a new script for the outbound leg. When the outbound leg is answered, I send uuid_break to the inbound leg, and let the channels bridge together. It's done in Perl, but Lua should be quite similar: https://github.com/xlab1/freeswitch_secretary_bug (the scripts are in scripts directory).

    From the mod_commands documentation:

    uuid_break

    Break out of media being sent to a channel. For example, if an audio file is being played to a channel, issuing uuid_break will discontinue the media and the call will move on in the dialplan, script, or whatever is controlling the call.

    Usage: uuid_break <uuid> [all]

    If the all flag is used then all audio files/prompts/etc. that are queued up to be played to the channel will be stopped and removed from the queue, otherwise only the currently playing media will be stopped.

    But in general, it's much easier to implement such scenarios via ESL: your program can handle multiple channels via ESL asynchronously, and perform all the needed playbacks and breaks easily. Here I made a simple prototype in Golang to implement a similar scenario via ESL: https://github.com/xlab1/go-fs-secretary-prototype (here I used the synchronous outbound ESL socket, but it shouldn't be too difficult to implement it also in asynchronous inbound mode).

    I hope this helps :)