public
Description: A ruby library for integrating with the FreeSWITCH phone system through its Event Socket interface
Homepage: http://code.rubyists.com/projects/fs
Clone URL: git://github.com/bougyman/freeswitcher.git
name age message
file .gitignore Mon May 18 16:24:58 -0700 2009 Version 0.3.0 [bougyman]
file AUTHORS Tue Nov 17 22:46:00 -0800 2009 updated authors and changelog for next release [TJ Vanderpoel]
file CHANGELOG Tue Nov 17 22:46:00 -0800 2009 updated authors and changelog for next release [TJ Vanderpoel]
file License.txt Tue Feb 17 11:45:53 -0800 2009 Add MIT License. [deathsyn]
file MANIFEST Tue Nov 17 22:03:59 -0800 2009 upped version to 0.4.3, encompassing harryv bug... [TJ Vanderpoel]
file NEWS Wed Apr 08 13:46:15 -0700 2009 added EM dependency to gemspec, updated news [bougyman]
file README Tue Sep 22 07:31:14 -0700 2009 instance_eval event hooks [ichverstehe]
file Rakefile Tue Nov 17 22:01:06 -0800 2009 removed non-UTF characters from inbound.rb [TJ Vanderpoel]
directory contrib/ Tue May 19 12:13:47 -0700 2009 reverted regression to listeners, back to funct... [freeswitch]
directory examples/ Thu Aug 27 06:40:04 -0700 2009 When using an FSR::App object with a FSR::Liste... [Jayson Vaughn]
file freeswitcher.gemspec Tue Nov 17 22:03:59 -0800 2009 upped version to 0.4.3, encompassing harryv bug... [TJ Vanderpoel]
directory lib/ Tue Nov 17 22:43:28 -0800 2009 commented out more debugging [TJ Vanderpoel]
directory spec/ Mon Nov 16 06:09:04 -0800 2009 reconnect inbound listener when no connection h... [ichverstehe]
directory tasks/ Sun Jun 21 18:45:56 -0700 2009 removed rcov dependency, added setup_spec task ... [bougyman]
README
=========================================================
FreeSWITCHeR
Copyright (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel, Michael Fellinger, Kevin Berry) 
Distributed under the terms of the MIT License.
==========================================================

ABOUT
-----
A ruby library for interacting with the "FreeSWITCH" (http://www.freeswitch.org) opensource telephony platform

REQUIREMENTS
------------
* ruby (>= 1.8)
* eventmachine (If you wish to use Outbound and Inbound listener)

USAGE
-----

An Outbound Event Listener Example that reads and returns DTMF input:
--------------------------------------------------------------------

Simply just create a subclass of FSR::Listner::Outbound and all
new calls/sessions will invoke the "session_initiated" callback method.
 
<b>NOTE</b>: FSR uses blocks within the 'session_inititated' method to ensure that the next "freeswich command" is not 
executed until the previous "Freeswitch command" has finished.  (Basically a continuation) This is kicked off by "answer 
do". 

  #!/usr/bin/ruby
  require 'fsr'
  require 'fsr/listener/outbound'

  class OutboundDemo < FSR::Listener::Outbound

    def session_initiated
      exten = @session.headers[:caller_caller_id_number]
      FSR::Log.info "*** Answering incoming call from #{exten}"

      answer do
        FSR::Log.info "***Reading DTMF from #{exten}"
        read("/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav", 4, 10, "input", 7000) do |read_var|
          FSR::Log.info "***Success, grabbed #{read_var.to_s.strip} from #{exten}"
          # Tell the caller what they entered
          speak("Got the DTMF of: #{read_var.to_s.strip}") do 
            #Hangup the call
            hangup 
          end
        end
      end

    end

  end

  FSR.start_oes! OutboundDemo, :port => 8084, :host => "127.0.0.1"

An Inbound Event Socket Listener example using FreeSWITCHeR's hook system:
--------------------------------------------------------------------------

  #!/usr/bin/ruby
  require 'pp'
  require 'fsr'
  require "fsr/listener/inbound"

  # EXAMPLE 1 
  # This adds a hook on CHANNEL_CREATE events. You can also create a method to handle the event you're after. See the 
  next example
  FSL::Inbound.add_event_hook(:CHANNEL_CREATE) { FSR::Log.info "*** [#{event.content[:unique_id]}] Channel created - 
  greetings from the hook!" }

  # EXAMPLE 2
  # Define a method to handle CHANNEL_HANGUP events.
  def custom_channel_hangup_handler(event)
    FSR::Log.info "*** [#{event.content[:unique_id]}] Channel hangup. The event:"
    pp event
  end

  # This adds a hook for EXAMPLE 2
  FSL::Inbound.add_event_hook(:CHANNEL_HANGUP) { custom_channel_hangup_handler(event) }


  # Start FSR Inbound Listener
  FSR.start_ies!(FSL::Inbound, :host => "localhost", :port => 8021)


An Inbound Event Socket Listener example using the on_event callback method instead of hooks:
---------------------------------------------------------------------------------------------

  #!/usr/bin/ruby
  require 'pp'
  require 'fsr'
  require "fsr/listener/inbound"


  class IesDemo < FSR::Listener::Inbound

    def on_event
      pp event.headers
      pp event.content[:event_name]
    end

  end

  FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021, :auth => "ClueCon")


An example of using FSR::CommandSocket to originate a new call in irb:
----------------------------------------------------------------------

  irb(main):001:0> require 'fsr'
  => true

  irb(main):002:0> FSR.load_all_commands
  => [:sofia, :originate]

  irb(main):003:0> sock = FSR::CommandSocket.new
  => #<FSR::CommandSocket:0xb7a89104 @server="127.0.0.1", @socket=#<TCPSocket:0xb7a8908c>, @port="8021", 
  @auth="ClueCon">

  irb(main):007:0> sock.originate(:target => 'sofia/gateway/carlos/8179395222', :endpoint => 
  FSR::App::Bridge.new("user/bougyman")).run
  => {"Job-UUID"=>"732075a4-7dd5-4258-b124-6284a82a5ae7", "body"=>"", "Content-Type"=>"command/reply", 
  "Reply-Text"=>"+OK Job-UUID: 732075a4-7dd5-4258-b124-6284a82a5ae7"}



SUPPORT
-------
Home page at http://code.rubyists.com/projects/fs
#rubyists on FreeNode