Class: WebRTC::RTCDTMFSender

Inherits:
Object
  • Object
show all
Defined in:
lib/webrtc/dtmf_sender.rb

Constant Summary collapse

VALID_TONES =
'0123456789ABCD*#,'

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @sender = options[:sender]
  @tone_buffer = ''
  @duration = 100
  @inter_tone_gap = 70
  @callbacks = {}
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



7
8
9
# File 'lib/webrtc/dtmf_sender.rb', line 7

def duration
  @duration
end

#inter_tone_gapObject (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_bufferObject (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

Returns:

  • (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

Raises:



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