title: Lua script in FreeSWITCH exits bridge immediately when bypass_media = true
body: <p>How do I make the script wait for the bridge to terminate before continuing when I have "bypass_media" set to true?</p>
  
  <p>This snippet -</p>
  
  <pre><code>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")
  </code></pre>
  
  <p>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).</p>
  
  <p>But with bypass set to true, the script continues without pausing, and the session is no longer ready (session:ready() == false).</p>
  
  <p>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.</p>
  
  <p>Same happens if i do the bridge in XML dialplan, immediately carries on causing my housekeeping to fire early.</p>
  
  <p>FreeSWITCH (Version 1.6.20 git 43a9feb 2018-05-07 18:56:11Z 64bit)
  Lua 5.2</p>
  
  <p>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.</p>