• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    CoffeeScript
  • License
    The Unlicense
  • Created almost 13 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Node.js client and server for FreeSwitch Event Socket

This module is a promise-based, chainable, client ('inbound' event socket) and server ('outbound' event socket) for FreeSwitch, written entirely in Javascript with no dependencies on the libesl library. This module is actively maintained and used in production systems.

Build Status

Client Usage

The following code does the equivalent of fs_cli -x: it connects to the Event Socket, runs a single command, then disconnects.

FS = require('esl');

var fs_command = function(cmd) {

  var client = FS.client(function(){
    var res = await this.api(cmd)
    // res contains the headers and body of FreeSwitch's response.
    res.body.should.match(/\+OK/);
    await this.exit();
    client.end();
  });
  client.connect(8021,'127.0.0.1');

};

fs_command("reloadxml");

The API methods return promises.

The original example as CoffeeScript:

FS = require 'esl'

fs_command = (cmd) ->

  client = FS.client ->
    await @api cmd
    await @exit()
    client.end()

  client.connect 8021, '127.0.0.1'

fs_command 'reloadxml'

Server Usage

From the FreeSwitch XML dialplan, you can connect to an Event Socket server using for example:

<action application="set" data="socket_resume=true"/>
<action application="socket" data="127.0.0.1:7000 async full"/>
<action application="respond" data="500 socket failure"/>

Here is a simplistic event server:

var call_handler = function() {
  res = await this.command('play-file', 'voicemail/vm-hello')
  var foo = res.body.variable_foo;
  await this.hangup() // hang-up the call
  await this.exit()   // tell FreeSwitch we're disconnecting
};

require('esl').server(call_handler).listen(7000);

Message tracing

During development it is often useful to be able to see what messages are sent to FreeSwitch or received from FreeSwitch. This module uses the debug module for tracing; simply call your application with

DEBUG='esl:*,-esl:*:trace'

to see traces.

The names available are esl:response and esl:main.

Install

npm install esl

Examples and Documentation

The test suite in test/0001.coffee.md provides many examples.

The API provides a summary of usage.

The methods available inside the call-handler are those of the response object: api, bgapi, command, command_uuid, etc.

Overview

This module is modelled after Node.js' own httpServer and client, and uses an event-driven interface wrapper inside a promise-based API.

It offers two Event Socket handlers, client() and server().

Typically a client would be used to trigger calls asynchronously (for example in a click-to-dial application); this mode of operation is called "inbound" (to FreeSwitch) in the Event Socket FreeSwitch documentation.

A server will handle calls sent to it using the "socket" diaplan application (called "outbound" mode in the Event Socket Outbound FreeSwitch documentation). The server is available at a pre-defined port which the socket dialplan application will specify.

Support

Please use GitHub issues.

Client Notes

Note: Use call.event_json('CHANNEL_HANGUP_COMPLETE','DTMF') to start receiving event notifications.

Server Notes

For some applications you might want to capture channel events instead of using the command() / callback pattern:

var esl = require('esl'),
    util = require('util');

var call_handler = function() {

  # for debugging
  this.trace(true);

  # These are called asynchronously.
  this.onceAsync('CHANNEL_ANSWER').then( function () {
    util.log('Call was answered');
  });
  this.onceAsync('CHANNEL_HANGUP').then(  function () {
    util.log('Call hangup');
  });
  this.onceAsync('CHANNEL_HANGUP_COMPLETE').then(  function () {
    util.log('Call was disconnected');
  });
  # However note that `on` cannot use a Promise (since it only would
  # get resolved once).
  this.on('SOME_MESSAGE', function(call) {
    util.log('Got Some Message');
  });
  // Remember to accept the messages since we're using `all_events: false` below.
  this.event_json('CHANNEL_ANSWER','CHANNEL_HANGUP','CHANNEL_HANGUP_COMPLETE','SOME_MESSAGE');
};

var server = esl.server({all_events:false},call_handler)
server.listen(3232);

Migrating from earlier versions

  • once has been renamed to onceAsync; onceAsync(event) returns a Promise. once is now the regular event-emitter once(event,callback).
  • Promises are native Promises, not bluebird's.

Alternative

The present module should be more convenient if you've already coded for Node.js and are used to promises and events. If you are coming from the world of FreeSwitch and are used to the Event Socket Library API, you might want to try node-esl.

More Repositories

1

password

Memorable passwords generator
CoffeeScript
18
star
2

ccnq3

ISP VoIP (SIP) softswitch platform
CoffeeScript
13
star
3

ccnq4

Overview of the CCNQ4 SIP softswitch
11
star
4

pouchdb-calendar

A syncable, in-browser calendar
JavaScript
9
star
5

superagent-as-promised

SuperAgent as Promise(d)
GCC Machine Description
9
star
6

yate

Mirror of Yate svn repo (trunk-only) + local changes in branches
C++
7
star
7

yxa-cnam

Calling Name extension for Yxa
5
star
8

useful-wind

Shell
4
star
9

zappa-canvas

CoffeeScript
4
star
10

ccnq4-opensips

SIP proxy & registrar for CCNQ4
CoffeeScript
4
star
11

spicy-action

Web services for CCNQ4
4
star
12

ccnq2.0

CCNQ 2.0
Perl
4
star
13

well-groomed-feast

Distributed voicemail for CCNQ4
3
star
14

numbering-plans

International numbering plans
3
star
15

node-rtc-peer-connection

RTCPeerConnection for Node.js
JavaScript
3
star
16

tough-rate

Dynamic LCR engine for FreeSwitch
3
star
17

node-nomedia-webrtc

2
star
18

docker.opensips

OpenSIPS-as-docker for CCNQ4
Dockerfile
2
star
19

node-mediaproxy

Node.js MediaProxy with REST API
CoffeeScript
2
star
20

travis-freeswitch

FreeSwitch for Travis-CI
Shell
2
star
21

fr-sounds

FreeSwitch FR-fr sounds
Shell
2
star
22

jobreqs

1
star
23

esl-lite

High performance client for FreeSwitch Event System
TypeScript
1
star
24

perl-s3fs

S3fs in Perl
Perl
1
star
25

willing-toothbrush

CouchDB-backed DNS server for CCNQ4
JavaScript
1
star
26

atelier

JavaScript
1
star
27

docker-nativescript

Dockerfile
1
star
28

openbsc

C
1
star
29

nodejs-couchdb

CouchDB as Node.js
JavaScript
1
star
30

VimMate

VimMate development environment, with additions
Ruby
1
star
31

seem

Promises and Generators
JavaScript
1
star
32

umtrx-osmo-bsc

How-to get started with osmo-bsc
Shell
1
star
33

ccnq3-opensips-ga

CoffeeScript
1
star
34

LQDN-Dialer

1
star
35

docker.freeswitch

FreeSwitch-as-docker for CCNQ4
Shell
1
star
36

pico

nano's little brother
CoffeeScript
1
star
37

node-mediaproxy-webrtc

A WebRTC API for node-mediaproxy
JavaScript
1
star
38

gabby-potato

Dockerfile
1
star
39

pgcouch

TypeScript
1
star
40

shimaore.github.com

JavaScript
1
star
41

exec-as-promised

1
star
42

huge-play

FreeSwitch middleware and configuration for CCNQ4
CoffeeScript
1
star
43

rmll2012

Presentation for RMLL2012 conference
CoffeeScript
1
star