Skip to content

Instantly share code, notes, and snippets.

@toraritte
Last active May 13, 2023 06:06
Show Gist options
  • Save toraritte/cfad6adc3ee4faf9ba220c4164ff171f to your computer and use it in GitHub Desktop.
Save toraritte/cfad6adc3ee4faf9ba220c4164ff171f to your computer and use it in GitHub Desktop.
FreeSWITCH notes (and Stackoverflow backup)

TODO Start saving posts off Stackoverflow, and only contribute conservatively.

What is the purpose of FreeSWITCH's mod_esl?

There is another question trying to figure out the connection between mod_event_socket and the Event Socket Library (ESL).

The Event Socket Library itself is a C library (libesl) that can be used to build external C applications to control FreeSWITCH via its event system.

As far as I understand, mod_esl is only a FreeSWITCH module wrapper around libesl, used to extend programming languages with the same functionality (i.e., to control a FreeSWITCH instance). The documentation doesn't mention this, but basing this assumption on the quoted sources below, and on the fact that I couldn't find anyone ever using it directly (i.e., found no mailing list question, nothing on slack, no SO questions, no blog posts, the books also barely mention it, and so on). Are there any other use cases that I'm missing?

Installation

There are several options to configure mod_esl to add support for multiple languages.

First, in libs/esl, type make

# Under the FreeSWITCH source top-level directory
cd /usr/src/freeswitch/libs/esl
make

Then, to enable specific languages type make + one of:

perlmod-install to add Perl support phpmod to add PHP support ...

Example:

make perlmod-install

Note Windows users must build mod_esl with Microsoft Visual Studio (the pre-compiled binaries will not suffice). Right-click on mod_esl and click on Build. It will create esl.dll. Place this file in your Lua installation's clib sub-folder. When running a Lua script in Windows, use the command prompt and execute lua followed by the name of the script. For example: lua single_command.lua.

As for what the difference between FreeSWITCH built-in languages and ESL scripting, see this question.

What is the relation between the Event Socket Library (ESL) and mod_event_socket?

Is there any? Based on the ways the Event Socket Library (ESL) documentation (and FreeSWITCH books) refer to mod_event_socket, I was under the impression that mod_event_socket (src) (and derivatives, such as mod_erlang_event, mod_kazoo, etc.) are all built on libesl. As it turns out, only mod_esl (src) uses it.

The way I currently understand it, both tap into FreeSWITCH's event system to control it, but

  • ESL is a C library (libesl) that can be used to build external applications, and extend programming languages (via mod_esl?) such as Perl, Python, etc., and
  • mod_event_socket et al. are modules providing network interfaces via an API similar to ESL (i.e., mod_event_socket via TCP, mod_erlang_event and mod_kazoo via Erlang on top of TCP, etc.)

So they are disparate entities but follow a common (and implicit) API specification. Put it another way, there is an idea of how to interact with the event system from an external application, and it is independently implemented in ESL, mod_event_socket and co.

What is the difference between built-in (or embedded) languages in FreeSWITCH and scripts using the Event Socket Library (ESL)?

Many languages are embedded into FreeSWITCH (such as JavaScript, see the docs), made possible by SWIG "to make the core FreeSWITCH library accessible to scripting".

Languages can also use the Event Socket Library for the same purpose, so what is the difference?

As the FreeSWITCH 1.2 book points out, they are indeed not the same:

ESL scripts versus built-in languages

Keep in mind that ESL-based programs are not the same as using built-in languages. The FreeSWITCH event socket is a TCP-based connection to FreeSWITCH. The ESL is an abstraction library that is available for more languages than just the few that are built-in to FreeSWITCH. You must first install the Lua, Perl, Python, or PHP for your system before using ESL.

Built-in languages ship with a FreeSWITCH installation by default, and they can be used to write scripts to control (and configure1) a FreeSWITCH instance instead of editing the XML files to achieve the same. These scripts can only be called either from a dialplan action or form the console as an API call (e.g., look for luarun or jsrun).

Scripts using the Event Socket Library (ESL) can be run from anywhere achieving the same results as built-in languages, but first they establish a network connection to the FreeSWITCH instance to be able to send API calls.


1 See Serving Configuration with mod_lua and Serving Configuration with JavaScript documentation pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment