Class: WebRTC::RTCDTMFSender
- Inherits:
-
Object
- Object
- WebRTC::RTCDTMFSender
- Defined in:
- lib/webrtc/dtmf_sender.rb
Constant Summary collapse
- VALID_TONES =
'0123456789ABCD*#,'
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#inter_tone_gap ⇒ Object
readonly
Returns the value of attribute inter_tone_gap.
-
#tone_buffer ⇒ Object
readonly
Returns the value of attribute tone_buffer.
Instance Method Summary collapse
- #can_insert_dtmf? ⇒ Boolean
-
#initialize(options = {}) ⇒ RTCDTMFSender
constructor
A new instance of RTCDTMFSender.
- #insert_dtmf(tones, duration: 100, inter_tone_gap: 70) ⇒ Object
- #on_tone_change(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ RTCDTMFSender
Returns a new instance of RTCDTMFSender.
9 10 11 12 13 14 15 |
# File 'lib/webrtc/dtmf_sender.rb', line 9 def initialize( = {}) @sender = [:sender] @tone_buffer = '' @duration = 100 @inter_tone_gap = 70 @callbacks = {} end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
7 8 9 |
# File 'lib/webrtc/dtmf_sender.rb', line 7 def duration @duration end |
#inter_tone_gap ⇒ Object (readonly)
Returns the value of attribute inter_tone_gap.
7 8 9 |
# File 'lib/webrtc/dtmf_sender.rb', line 7 def inter_tone_gap @inter_tone_gap end |
#tone_buffer ⇒ Object (readonly)
Returns the value of attribute tone_buffer.
7 8 9 |
# File 'lib/webrtc/dtmf_sender.rb', line 7 def tone_buffer @tone_buffer end |
Instance Method Details
#can_insert_dtmf? ⇒ Boolean
17 18 19 |
# File 'lib/webrtc/dtmf_sender.rb', line 17 def can_insert_dtmf? @sender&.track&.kind == :audio end |
#insert_dtmf(tones, duration: 100, inter_tone_gap: 70) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/webrtc/dtmf_sender.rb', line 21 def insert_dtmf(tones, duration: 100, inter_tone_gap: 70) raise InvalidStateError, 'Cannot insert DTMF' unless can_insert_dtmf? validate_tones!(tones) validate_duration!(duration) validate_inter_tone_gap!(inter_tone_gap) @duration = duration @inter_tone_gap = inter_tone_gap @tone_buffer = tones.upcase schedule_tone_playback end |
#on_tone_change(&block) ⇒ Object
35 36 37 |
# File 'lib/webrtc/dtmf_sender.rb', line 35 def on_tone_change(&block) @callbacks[:tone_change] = block end |