Lua script in FreeSWITCH exits bridge immediately when bypass_media = true

1.8k views Asked by At

How do I make the script wait for the bridge to terminate before continuing when I have "bypass_media" set to true?

This snippet -

freeswitch.consoleLog("err","session before="..tostring(session:ready()).."\n")
session:execute("set","bypass_media=true")
session:execute("bridge","sofia/gateway/carrierb/12345678")
freeswitch.consoleLog("err","session after="..tostring(session:ready()).."\n")

from an audio perspective, it works perfectly with bridge_media set to either true or false, and a wireshark trace shows the audio either passing through (false) or end to end (true).

But with bypass set to true, the script continues without pausing, and the session is no longer ready (session:ready() == false).

The channel seems to go into a hibernate state, but I have housekeeping to do after the bridge is finished which I simply cannot do.

Same happens if i do the bridge in XML dialplan, immediately carries on causing my housekeeping to fire early.

FreeSWITCH (Version 1.6.20 git 43a9feb 2018-05-07 18:56:11Z 64bit) Lua 5.2

EDIT 1 - I can get "api_hangup_hook=lua housekeeping.lua" to work, but then I have to pass tons of variables and it fires up a new process/thread/whatever, which seems a little overkill unless that's the only way.

1

There are 1 answers

2
David Wylie On

I have a workaround, but would still like an answer to the question if anyone has one (ie how to stop the bridge exiting immediately).

If I set this before the bridge :

session:execute("set","bypass_media=true")
session:execute("set","session_in_hangup_hook=true")
session:execute("set","api_hangup_hook=lua housekeeping.lua "..<vars>)

then "housekeeping.lua" fires when the bridge actually terminates (which is long after the script does).

In housekeeping.lua I can then do :

session:getVariable("billmsec")

and it seems to have the correct values in them, allowing me to do my housekeeping.

My problem with this is the uncertainty of playing with variables from a session that appears to have gone away from a script that fires at some point in the future.

Anyway, it'll have to do until I can find out how to keep control inside the original script.