Giter Site home page Giter Site logo

fcs's Introduction

FCS: FreeSWITCH Command Socket

FCS is a lightweight api wrapper for FreeSWITCH's event socket.

Installation

Add this line to your application's Gemfile:

gem 'fcs'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fcs

Usage

Using FCS is easy and intuitive. After initializing, dispatch commands to FreeSWITCH using the .dispatch! method. See the examples below.

Initializing

fs = FCS.new(
  remote_host: 'localhost',
  remote_port: '8021'
)

Authorizing

fs.auth('ClueCon').dispatch!

Examples

FCS is basically a naive command builder for freeSWITCH. You build commands by chaining method calls that match FreeSWITCH's mod_commands like so:

request = fs.api.originate 'sofia/mydomain.com 1000'
response = request.dispatch!

This is equivalent:

response = fs.api.originate('sofia/mydomain.com', '1000').dispatch!

Both these commands result in this api command being sent to FreeSWITCH:

api originate sofia/mydomain.com 1000

These two commands are also equivalent:

fs.api.uuid_getvar('fs_id', 'varname').dispatch!
fs.api.uuid_getvar('fs_id').varname.dispatch!

This flexible syntax allows you to build commands in a very natural way that mimics FreeSWITCH's command syntax.

A more complex example:

fs.sendmsg(fs_id).call_command(:execute).execute_app_name(:playback).execute_app_arg('/tmp/sound.wav').loops(-1).event_lock(true)

The sendmsg command takes an optional uuid parameter. Since execute is so common, there's a helper method that shortens the above to:

fs.sendmsg(fs_id).execute(:playback, '/tmp/sound.wav').loops(-1).event_lock(true)

Pretty much any api method should work out of the box. A few more examples:

fs.api.sched_api('+20').originate('sofia/external &echo()').dispatch!
fs.api.uuid_send_dtmf(fs_id, 'W0W011W@250')
fs.api.uuid_kill(fs_id, 'NORMAL_CLEARING')
fs.api.sched_broadcast('+20', fs_id, 'commercial.wav').aleg
fs.bgapi.originate 'sofia/mydomain.com'    

Calling dispatch! at the end of the chain is necessary in order to dispatch the command to FreeSWITCH. Otherwise you'll get back a Request object.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

fcs's People

Contributors

markquezada avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

oshoemaker

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.