Hangup and DTMF event listening in LUA with eventConsumer

For a simple example, let’s say caller A is “listening” in on DTMF events from Caller B. When Caller B presses 1, Caller A hears “1”. Caller B may not press anything, so Caller A wants to leave this situation by hanging up or pressing *.

When using eventConsumer and con:pop(1), the entire call is blocked so DTMF and hangups are not detected. Caller A cannot exit from this situation, and even if Caller A hangs up the session is not destroyed since con:pop is still waiting for that event.

As a workaround, I’ve done:

while session:ready() do
    event = con:pop()
     if event ~= nil then
          -- Parse the event
     end
end
...

This wastes CPU cycles.

What is a better way to subscribe to events that may not happen, while playing audio to the caller during the wait, as well as allowing the caller to break out of the subscription with DTMF input, and gracefully accept hangup?

Just because you can do this, doesn’t mean you should, what is your ultimate goal? Because your blocking the session thread again. the EventConsumer isn’t to be used like this.

/b

We’re essentially trying to eavesdrop on a channel’s events without using eavesdrop. There are a few reasons for this, mainly:

  • We don’t want the eavesdropper to hear the person on the other end of the line, just to hear the audio being streamed to the caller from FS.
  • This may be happening on a remote FS server that is not part of this cluster so we cannot directly access the audio. (But we do have the same files so we can stream the same WAV library)

By using ESL I can subscribe to the events happening on that channel, but then the user is stuck and cannot exit, hang up, or hear any audio.

As you noted in my other thread, I did discover that adding freeswitch:sleep(50) yields the thread back to the session and all these items start to work, but it seems wasteful and bad practice to do it that way.

You do it from outside the session, you can hook onto events via lua.conf.xml and process all this without trying to do it inside the session thread, you’re literally blocking the session using the eventConsumer inside a session lua interpreter.

/b