Class: Freec

Inherits:
Object show all
Includes:
CallVariables, FreeswitchApplications
Defined in:
lib/freec_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CallVariables

#channel_destination_number, #sip_from_user, #sip_to_user

Methods included from FreeswitchApplications

#answer, #bridge, #execute_app, #hangup, #playback, #read, #record, #set_variable, #speak, #spell, #start_recording, #stop_recording, #transfer

Constructor Details

#initialize(io, log, config) ⇒ Freec

:nodoc:



15
16
17
18
19
20
21
22
# File 'lib/freec_base.rb', line 15

def initialize(io, log, config) #:nodoc:
  @call_vars = {}
  @want_events_from = []
  @last_app_executed = 'initial_step'
  @io = io    
  @log = log
  @config = config
end

Instance Attribute Details

#call_varsObject (readonly)

Returns the value of attribute call_vars.



13
14
15
# File 'lib/freec_base.rb', line 13

def call_vars
  @call_vars
end

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/freec_base.rb', line 13

def config
  @config
end

#event_bodyObject (readonly)

Returns the value of attribute event_body.



13
14
15
# File 'lib/freec_base.rb', line 13

def event_body
  @event_body
end

#logObject (readonly)

Returns the value of attribute log.



13
14
15
# File 'lib/freec_base.rb', line 13

def log
  @log
end

Instance Method Details

#execute_completed?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/freec_base.rb', line 52

def execute_completed?
  channel_execute_complete? || channel_destroyed_after_bridge? || disconnect_notice?
end

#handle_callObject

:nodoc:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/freec_base.rb', line 24

def handle_call #:nodoc:
  call_initialization    
  loop do
    subscribe_to_new_channel_events
    if last_event_dtmf? && respond_to?(:on_dtmf)
      callback(:on_dtmf, call_vars[:dtmf_digit])
    elsif waiting_for_this_response? || execute_completed?
      reset_wait_for if waiting_for_this_response?
      reload_application_code
      break if disconnect_notice? || !callback(:step)
    end
    read_and_parse_response
  end
  callback(:on_hangup)
  hangup unless @io.closed?
  send_and_read('exit') unless @io.closed?
end

#reset_wait_forObject



47
48
49
50
# File 'lib/freec_base.rb', line 47

def reset_wait_for
  wait_for(nil, nil)
  true 
end

#wait_for(key, value) ⇒ Object



42
43
44
45
# File 'lib/freec_base.rb', line 42

def wait_for(key, value)
  @waiting_for_key = key && key.to_sym
  @waiting_for_value = value
end