FreeSwitch controlled by Node.js middleware
useful-wind is a middleware framework for FreeSwitch.
This module extends
useful-wind with web and notification services to support call-handling.
This module also provides a working FreeSwitch image as a Docker container under the name
- Docker image with FreeSwitch and Node.js
- FreeSwitch calls are controlled by Node.js using the Event Socket
- Realtime statistical reporting via extendable web services
- Realtime notifications via extendable Socket.IO client
Three processes are managed by a common supervisord instance:
configapplication is ran once at startup to provide configuration, especially to create the FreeSwitch XML configuration file;
serverapplication provides the Event Socket handler, web services, etc.
Supervisord can be controlled using its HTTP interface.
config application will run any
config middleware function.
It will then create a FreeSwitch XML configuration file by rendering the
freeswitch template in the configuration object. The templace could be an
acoustic-line template, or any function that will return a valid FreeSwitch XML configuration file.
Finally it will start the
server application, and FreeSwitch itself.
Note: if the configuration contains a
server_only flag, no FreeSwitch configuration is created, and FreeSwitch is not started.
server application with first run any
server_pre middleware function. This is used for example in the
docker.tough-rate server module to initialize database access, etc.
The application will then start the Event Socket server (
web service, and the
Finally it will run any
server_post middleware function.
The web service provides by default:
It may be extended by
web middleware functions.
The notification service provides by default:
addmessages when data is modified in a statistics object
callmessages during call processing
reportmessages to indicate provisioning errors
These messages might be
emitted against the
statistics object during call processing. You must create the
statistics object on the
this.cfg object for these notifications to work. See the
init function in tough-rate's setup middleware for an example.
The notification service may be extended by
notify middleware functions.
Middleware modules are declared by setting
cfg.use. They may contain the following fields:
name: the middleware name (string)
config: startup (function)
init: call-processing initialization (function)
include: call-processing middleware (function)
web: web service (function)
notify: notification service (function)
The functions are executed as indicated below, in the order they are declared in the
They are executed inside a Promise chain and may therefor return Promises.
thinkable-ducks middleware module may contain
config-time middleware functions which are ran inside the
config application. The
config application is a separate process and runs before the
server application and FreeSwitch are started.
configmiddleware in a context comprising of
this.cfg object is shared amongst all these functions, but not with the modules in the
server application (since that application is a separate process and is ran after the
config application is completed).
thinkable-ducks middleware module may contain
server-time middleware functions which are ran inside the
server application. The
server application is a Node.js process which runs concurrently to FreeSwitch.
Some functions are executed by
initis ran after the call-router is created but before call-routing starts taking place; this is a good place to extend the
cfgobject with any application-specific call-processing-related data.
includeis used to process FreeSwich calls.
Some functions are executed by this module (
webruns in the context of a
zappajsapplication, extended with a
this.cfghelper, and is used to provide web services.
notifyruns in a context comprising of
this.socket(the Socket.IO client), and is used to notify and receive notifications from e.g. a
this.cfg object is shared amongst all these functions.
An application is build out of middleware modules. The main application may look as follows.
cfg = require process.env.CONFIG cfg.use = [ require 'huge-play/middleware/setup' require 'huge-play/middleware/client/media' # etc. `require` any middleware module you might need ] # A renderable `acoustic-line` templace to generate # the FreeSwitch XML configuration. cfg.freeswitch = require 'tough-rate/conf/freeswitch' ducks = require 'thinkable-ducks' ducks cfg
coffee-script is required by the
npm install --save coffee-script
Install any middleware package you may require (including your own packages).
npm install --save thinkable-ducks huge-play tough-rate ...
FROM shimaore/thinkable-ducks COPY . /opt/thinkable-ducks RUN npm install
Build using docker.io
docker build .