Skip to content
deathsyn edited this page Mar 10, 2011 · 1 revision

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")