Module: Signalwire::Relay::Calling::CallDetectMethods
- Included in:
- Call
- Defined in:
- lib/signalwire/relay/calling/call_detect_methods.rb
Instance Method Summary collapse
- #detect(detect:, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
- #detect!(detect:, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
- #detect_digit(digits: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
- #detect_digit!(digits: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
- #detect_fax(tone: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
- #detect_fax!(tone: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
- #detect_human(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
- #detect_human!(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
- #detect_machine(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
- #detect_machine!(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
- #prepare_fax_arguments(tone) ⇒ Object
Instance Method Details
#detect(detect:, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
3 4 5 6 7 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 3 def detect(detect:, timeout: Relay::DEFAULT_CALL_TIMEOUT) component = Signalwire::Relay::Calling::Detect.new(call: self, detect: detect, timeout: timeout) component.wait_for(Relay::CallDetectState::FINISHED, Relay::CallDetectState::ERROR) DetectResult.new(component: component) end |
#detect!(detect:, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
9 10 11 12 13 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 9 def detect!(detect:, timeout: Relay::DEFAULT_CALL_TIMEOUT) component = Signalwire::Relay::Calling::Detect.new(call: self, detect: detect, timeout: timeout) component.execute DetectAction.new(component: component) end |
#detect_digit(digits: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 77 def detect_digit(digits: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) detect = { type: Relay::CallDetectType::DIGIT, params: {} } detect[:params][:digits] = digits if digits detect(detect: detect, timeout: timeout) end |
#detect_digit!(digits: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 86 def detect_digit!(digits: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) detect = { type: Relay::CallDetectType::DIGIT, params: {} } detect[:params][:digits] = digits if digits detect!(detect: detect, timeout: timeout) end |
#detect_fax(tone: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 61 def detect_fax(tone: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) detect, events = prepare_fax_arguments(tone) component = Signalwire::Relay::Calling::Detect.new(call: self, detect: detect, timeout: timeout) component.wait_for(*events) DetectResult.new(component: component) end |
#detect_fax!(tone: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 69 def detect_fax!(tone: nil, timeout: Relay::DEFAULT_CALL_TIMEOUT) detect, events = prepare_fax_arguments(tone) component = Signalwire::Relay::Calling::Detect.new(call: self, detect: detect, timeout: timeout) component.setup_waiting_events(events) component.execute DetectAction.new(component: component) end |
#detect_human(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 15 def detect_human(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) detect = { type: Relay::CallDetectType::MACHINE, params: params } component = Signalwire::Relay::Calling::Detect.new(call: self, detect: detect, timeout: timeout) component.wait_for(Relay::CallDetectState::FINISHED, Relay::CallDetectState::ERROR, Relay::CallDetectState::HUMAN) DetectResult.new(component: component) end |
#detect_human!(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 25 def detect_human!(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) detect = { type: Relay::CallDetectType::MACHINE, params: params } component = Signalwire::Relay::Calling::Detect.new(call: self, detect: detect, timeout: timeout) component.setup_waiting_events([Relay::CallDetectState::FINISHED, Relay::CallDetectState::ERROR, Relay::CallDetectState::HUMAN]) component.execute DetectAction.new(component: component) end |
#detect_machine(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 36 def detect_machine(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) detect = { type: Relay::CallDetectType::MACHINE, params: params } component = Signalwire::Relay::Calling::Detect.new(call: self, detect: detect, timeout: timeout) component.wait_for(Relay::CallDetectState::FINISHED, Relay::CallDetectState::ERROR, Relay::CallDetectState::MACHINE, Relay::CallDetectState::READY, Relay::CallDetectState::NOT_READY) DetectResult.new(component: component) end |
#detect_machine!(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 48 def detect_machine!(params: {}, timeout: Relay::DEFAULT_CALL_TIMEOUT) detect = { type: Relay::CallDetectType::MACHINE, params: params } component = Signalwire::Relay::Calling::Detect.new(call: self, detect: detect, timeout: timeout) component.setup_waiting_events([Relay::CallDetectState::FINISHED, Relay::CallDetectState::ERROR, Relay::CallDetectState::MACHINE, Relay::CallDetectState::READY, Relay::CallDetectState::NOT_READY]) component.execute DetectAction.new(component: component) end |
#prepare_fax_arguments(tone) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/signalwire/relay/calling/call_detect_methods.rb', line 95 def prepare_fax_arguments(tone) fax_events = [Relay::CallDetectState::CED, Relay::CallDetectState::CNG] events = [Relay::CallDetectState::FINISHED, Relay::CallDetectState::ERROR] detect = { type: Relay::CallDetectType::FAX, params: {} } if fax_events.include?(tone) detect[:params] = { tone: tone } events << tone else events = events + fax_events end [detect, events] end |