All Projects → shimaore → esl

shimaore / esl

Licence: Unlicense license
Node.js client and server for FreeSwitch Event Socket

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to esl

sipp2freeswitch
sample sipp scenarios for testing freeswitch
Stars: ✭ 18 (-83.02%)
Mutual labels:  freeswitch
xui
XUI is a micro UI framework and implementation for FreeSWITCH
Stars: ✭ 86 (-18.87%)
Mutual labels:  freeswitch
NEventSocket
A reactive FreeSwitch eventsocket library for Modern .Net
Stars: ✭ 68 (-35.85%)
Mutual labels:  freeswitch
FSlmx
FreeSWITCH GUI 简体中文GUI for PHP (UTF8)
Stars: ✭ 43 (-59.43%)
Mutual labels:  freeswitch
switchy
async FreeSWITCH cluster control
Stars: ✭ 67 (-36.79%)
Mutual labels:  freeswitch
freeswitch-esl-all
freeswitch event socket base on netty 4 and has some new features.
Stars: ✭ 110 (+3.77%)
Mutual labels:  freeswitch
pyfreebilling
Routing and rating VoIP application for service providers - API based - AGPL v3 - Based on kamailio
Stars: ✭ 75 (-29.25%)
Mutual labels:  freeswitch
freeswitch-docker
Dockerfile for freeswitch
Stars: ✭ 40 (-62.26%)
Mutual labels:  freeswitch
siphub
sip capture server by hep。work with OpenSIPS, Kamailo, and FreeSWITCH。
Stars: ✭ 23 (-78.3%)
Mutual labels:  freeswitch
books-and-articles
Books written from me to my own language
Stars: ✭ 15 (-85.85%)
Mutual labels:  freeswitch
paStash
pastaʃ'ʃ = Spaghetti I/O Event Data Processing, Interpolation, Correlation and beyond 🍝
Stars: ✭ 89 (-16.04%)
Mutual labels:  freeswitch
mod event kafka
Freeswitch Kafka Plugin
Stars: ✭ 20 (-81.13%)
Mutual labels:  freeswitch
freeswitch-asr
TTS and ASR module with auto Voice Active Detecting supported for Freeswitch. I build it for Nature sound interactive, With the embedded LUA engine we could easly build a Freeswtich application like this.
Stars: ✭ 36 (-66.04%)
Mutual labels:  freeswitch

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].