punchblock 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/lib/punchblock/command/dial.rb +1 -1
  3. data/lib/punchblock/command/join.rb +4 -4
  4. data/lib/punchblock/command/unjoin.rb +4 -4
  5. data/lib/punchblock/command_node.rb +6 -2
  6. data/lib/punchblock/component/component_node.rb +2 -2
  7. data/lib/punchblock/component/output.rb +7 -7
  8. data/lib/punchblock/component/record.rb +2 -2
  9. data/lib/punchblock/connection/xmpp.rb +18 -9
  10. data/lib/punchblock/core_ext/blather/stanza.rb +1 -1
  11. data/lib/punchblock/event/active_speaker.rb +3 -3
  12. data/lib/punchblock/event/complete.rb +2 -2
  13. data/lib/punchblock/event/joined.rb +3 -3
  14. data/lib/punchblock/event/offer.rb +1 -1
  15. data/lib/punchblock/event/unjoined.rb +3 -3
  16. data/lib/punchblock/rayo_node.rb +3 -3
  17. data/lib/punchblock/translator/asterisk.rb +5 -5
  18. data/lib/punchblock/translator/asterisk/call.rb +8 -8
  19. data/lib/punchblock/translator/asterisk/component.rb +2 -2
  20. data/lib/punchblock/version.rb +1 -1
  21. data/spec/punchblock/command/dial_spec.rb +2 -2
  22. data/spec/punchblock/command/join_spec.rb +9 -9
  23. data/spec/punchblock/command/unjoin_spec.rb +5 -5
  24. data/spec/punchblock/command_node_spec.rb +3 -3
  25. data/spec/punchblock/component/input_spec.rb +3 -3
  26. data/spec/punchblock/component/output_spec.rb +17 -17
  27. data/spec/punchblock/component/record_spec.rb +7 -7
  28. data/spec/punchblock/connection/asterisk_spec.rb +1 -1
  29. data/spec/punchblock/connection/xmpp_spec.rb +45 -16
  30. data/spec/punchblock/event/complete_spec.rb +6 -6
  31. data/spec/punchblock/event/joined_spec.rb +6 -6
  32. data/spec/punchblock/event/started_speaking_spec.rb +4 -4
  33. data/spec/punchblock/event/stopped_speaking_spec.rb +4 -4
  34. data/spec/punchblock/event/unjoined_spec.rb +6 -6
  35. data/spec/punchblock/translator/asterisk/call_spec.rb +30 -30
  36. data/spec/punchblock/translator/asterisk/component/input_spec.rb +2 -2
  37. data/spec/punchblock/translator/asterisk/component_spec.rb +1 -1
  38. data/spec/punchblock/translator/asterisk_spec.rb +2 -2
  39. data/spec/spec_helper.rb +2 -2
  40. metadata +39 -39
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # [develop](https://github.com/adhearsion/punchblock)
2
2
 
3
+ # [v0.12.0](https://github.com/adhearsion/punchblock/compare/v0.11.0...v0.12.0) - [2012-03-30](https://rubygems.org/gems/punchblock/versions/0.12.0)
4
+ * API Change: `#call_id` and `#mixer_name` attributes changed to `#target_call_id` and `#target_mixer_name`
5
+ * API Change: `#other_call_id` attributes changed to `#call_id` to better align with Rayo
6
+
3
7
  # [v0.11.0](https://github.com/adhearsion/punchblock/compare/v0.10.0...v0.11.0) - [2012-03-29](https://rubygems.org/gems/punchblock/versions/0.11.0)
4
8
  * Feature: Input & Output components on Asterisk now responds to a Stop command
5
9
  * Feature: started/stopped-speaking events are now handled
@@ -88,7 +88,7 @@ module Punchblock
88
88
  end
89
89
 
90
90
  def response=(other)
91
- @call_id = other.id if other.is_a?(Ref)
91
+ @target_call_id = other.id if other.is_a?(Ref)
92
92
  super
93
93
  end
94
94
 
@@ -9,7 +9,7 @@ module Punchblock
9
9
  # Create a join message
10
10
  #
11
11
  # @param [Hash] options
12
- # @option options [String, Optional] :other_call_id the call ID to join
12
+ # @option options [String, Optional] :call_id the call ID to join
13
13
  # @option options [String, Optional] :mixer_name the mixer name to join
14
14
  # @option options [Symbol, Optional] :direction the direction in which media should flow
15
15
  # @option options [Symbol, Optional] :media the method by which to negotiate media
@@ -29,13 +29,13 @@ module Punchblock
29
29
 
30
30
  ##
31
31
  # @return [String] the call ID to join
32
- def other_call_id
32
+ def call_id
33
33
  read_attr :'call-id'
34
34
  end
35
35
 
36
36
  ##
37
37
  # @param [String] other the call ID to join
38
- def other_call_id=(other)
38
+ def call_id=(other)
39
39
  write_attr :'call-id', other
40
40
  end
41
41
 
@@ -76,7 +76,7 @@ module Punchblock
76
76
  end
77
77
 
78
78
  def inspect_attributes # :nodoc:
79
- [:other_call_id, :mixer_name, :direction, :media] + super
79
+ [:call_id, :mixer_name, :direction, :media] + super
80
80
  end
81
81
  end # Join
82
82
  end # Command
@@ -9,7 +9,7 @@ module Punchblock
9
9
  # Create an ujoin message
10
10
  #
11
11
  # @param [Hash] options
12
- # @option options [String, Optional] :other_call_id the call ID to unjoin
12
+ # @option options [String, Optional] :call_id the call ID to unjoin
13
13
  # @option options [String, Optional] :mixer_name the mixer name to unjoin
14
14
  #
15
15
  # @return [Command::Unjoin] a formatted Rayo unjoin command
@@ -22,13 +22,13 @@ module Punchblock
22
22
 
23
23
  ##
24
24
  # @return [String] the call ID to unjoin
25
- def other_call_id
25
+ def call_id
26
26
  read_attr :'call-id'
27
27
  end
28
28
 
29
29
  ##
30
30
  # @param [String] other the call ID to unjoin
31
- def other_call_id=(other)
31
+ def call_id=(other)
32
32
  write_attr :'call-id', other
33
33
  end
34
34
 
@@ -45,7 +45,7 @@ module Punchblock
45
45
  end
46
46
 
47
47
  def inspect_attributes # :nodoc:
48
- [:other_call_id, :mixer_name] + super
48
+ [:call_id, :mixer_name] + super
49
49
  end
50
50
  end # Unjoin
51
51
  end # Command
@@ -6,8 +6,8 @@ module Punchblock
6
6
  class CommandNode < RayoNode
7
7
  def self.new(options = {})
8
8
  super().tap do |new_node|
9
- new_node.call_id = options[:call_id]
10
- new_node.mixer_name = options[:mixer_name]
9
+ new_node.target_call_id = options[:target_call_id]
10
+ new_node.target_mixer_name = options[:target_mixer_name]
11
11
  new_node.component_id = options[:component_id]
12
12
  end
13
13
  end
@@ -45,5 +45,9 @@ module Punchblock
45
45
  @response.resource = other
46
46
  execute!
47
47
  end
48
+
49
+ def inspect_attributes
50
+ super + [:state_name]
51
+ end
48
52
  end # CommandNode
49
53
  end # Punchblock
@@ -31,7 +31,7 @@ module Punchblock
31
31
  end
32
32
 
33
33
  def write_action(action)
34
- client.execute_command action, :call_id => call_id, :component_id => component_id
34
+ client.execute_command action, :target_call_id => target_call_id, :component_id => component_id
35
35
  action
36
36
  end
37
37
 
@@ -59,7 +59,7 @@ module Punchblock
59
59
  # @return [Stop] an Rayo stop message
60
60
  #
61
61
  def stop_action
62
- Stop.new :component_id => component_id, :call_id => call_id
62
+ Stop.new :component_id => component_id, :target_call_id => target_call_id
63
63
  end
64
64
 
65
65
  ##
@@ -145,7 +145,7 @@ module Punchblock
145
145
  # returns:
146
146
  # <pause xmlns="urn:xmpp:tropo:output:1"/>
147
147
  def pause_action
148
- Pause.new :component_id => component_id, :call_id => call_id
148
+ Pause.new :component_id => component_id, :target_call_id => target_call_id
149
149
  end
150
150
 
151
151
  ##
@@ -170,7 +170,7 @@ module Punchblock
170
170
  # returns:
171
171
  # <resume xmlns="urn:xmpp:tropo:output:1"/>
172
172
  def resume_action
173
- Resume.new :component_id => component_id, :call_id => call_id
173
+ Resume.new :component_id => component_id, :target_call_id => target_call_id
174
174
  end
175
175
 
176
176
  ##
@@ -203,7 +203,7 @@ module Punchblock
203
203
  # returns:
204
204
  # <seek xmlns="urn:xmpp:rayo:output:1"/>
205
205
  def seek_action(options = {})
206
- Seek.new({ :component_id => component_id, :call_id => call_id }.merge(options)).tap do |s|
206
+ Seek.new({ :component_id => component_id, :target_call_id => target_call_id }.merge(options)).tap do |s|
207
207
  s.original_component = self
208
208
  end
209
209
  end
@@ -268,7 +268,7 @@ module Punchblock
268
268
  # returns:
269
269
  # <speed-up xmlns="urn:xmpp:rayo:output:1"/>
270
270
  def speed_up_action
271
- SpeedUp.new(:component_id => component_id, :call_id => call_id).tap do |s|
271
+ SpeedUp.new(:component_id => component_id, :target_call_id => target_call_id).tap do |s|
272
272
  s.original_component = self
273
273
  end
274
274
  end
@@ -294,7 +294,7 @@ module Punchblock
294
294
  # returns:
295
295
  # <speed-down xmlns="urn:xmpp:rayo:output:1"/>
296
296
  def slow_down_action
297
- SlowDown.new(:component_id => component_id, :call_id => call_id).tap do |s|
297
+ SlowDown.new(:component_id => component_id, :target_call_id => target_call_id).tap do |s|
298
298
  s.original_component = self
299
299
  end
300
300
  end
@@ -362,7 +362,7 @@ module Punchblock
362
362
  # returns:
363
363
  # <volume-up xmlns="urn:xmpp:rayo:output:1"/>
364
364
  def volume_up_action
365
- VolumeUp.new(:component_id => component_id, :call_id => call_id).tap do |s|
365
+ VolumeUp.new(:component_id => component_id, :target_call_id => target_call_id).tap do |s|
366
366
  s.original_component = self
367
367
  end
368
368
  end
@@ -388,7 +388,7 @@ module Punchblock
388
388
  # returns:
389
389
  # <volume-down xmlns="urn:xmpp:rayo:output:1"/>
390
390
  def volume_down_action
391
- VolumeDown.new(:component_id => component_id, :call_id => call_id).tap do |s|
391
+ VolumeDown.new(:component_id => component_id, :target_call_id => target_call_id).tap do |s|
392
392
  s.original_component = self
393
393
  end
394
394
  end
@@ -149,7 +149,7 @@ module Punchblock
149
149
  # returns:
150
150
  # <pause xmlns="urn:xmpp:rayo:record:1"/>
151
151
  def pause_action
152
- Pause.new :component_id => component_id, :call_id => call_id
152
+ Pause.new :component_id => component_id, :target_call_id => target_call_id
153
153
  end
154
154
 
155
155
  ##
@@ -174,7 +174,7 @@ module Punchblock
174
174
  # returns:
175
175
  # <resume xmlns="urn:xmpp:rayo:record:1"/>
176
176
  def resume_action
177
- Resume.new :component_id => component_id, :call_id => call_id
177
+ Resume.new :component_id => component_id, :target_call_id => target_call_id
178
178
  end
179
179
 
180
180
  ##
@@ -34,6 +34,7 @@ module Punchblock
34
34
  @mixers_domain = options[:mixers_domain] || "mixers.#{@root_domain}"
35
35
 
36
36
  @callmap = {} # This hash maps call IDs to their XMPP domain.
37
+ @joined_mixers = []
37
38
 
38
39
  @ping_period = options.has_key?(:ping_period) ? options[:ping_period] : 60
39
40
 
@@ -59,9 +60,12 @@ module Punchblock
59
60
 
60
61
  def prep_command_for_execution(command, options = {})
61
62
  command.connection = self
62
- command.call_id ||= options[:call_id]
63
- command.mixer_name ||= options[:mixer_name]
64
- command.component_id ||= options[:component_id]
63
+ command.target_call_id ||= options[:call_id]
64
+ command.target_mixer_name ||= options[:mixer_name]
65
+ command.component_id ||= options[:component_id]
66
+ if command.is_a?(Command::Join) && command.mixer_name
67
+ @joined_mixers << command.mixer_name
68
+ end
65
69
  create_iq(jid_for_command(command)).tap do |iq|
66
70
  iq << command
67
71
  end
@@ -105,12 +109,12 @@ module Punchblock
105
109
  def jid_for_command(command)
106
110
  return root_domain if command.is_a?(Command::Dial)
107
111
 
108
- if command.call_id
109
- node = command.call_id
110
- domain = @callmap[command.call_id] || calls_domain
111
- elsif command.mixer_name
112
- node = command.mixer_name
113
- domain = @callmap[command.mixer_name] || mixers_domain
112
+ if command.target_call_id
113
+ node = command.target_call_id
114
+ domain = @callmap[command.target_call_id] || calls_domain
115
+ elsif command.target_mixer_name
116
+ node = command.target_mixer_name
117
+ domain = @callmap[command.target_mixer_name] || mixers_domain
114
118
  else
115
119
  domain = calls_domain
116
120
  end
@@ -130,6 +134,11 @@ module Punchblock
130
134
  event = p.event
131
135
  event.connection = self
132
136
  event.domain = p.from.domain
137
+ if @joined_mixers.include?(p.call_id)
138
+ event.target_mixer_name = p.call_id
139
+ else
140
+ event.target_call_id = p.call_id
141
+ end
133
142
  event_handler.call event
134
143
  end
135
144
 
@@ -8,7 +8,7 @@ module Blather
8
8
  #
9
9
  def rayo_node
10
10
  first_child = children.first
11
- Punchblock::RayoNode.import first_child, call_id, component_id if first_child
11
+ Punchblock::RayoNode.import first_child, nil, component_id if first_child
12
12
  end
13
13
 
14
14
  ##
@@ -3,16 +3,16 @@
3
3
  module Punchblock
4
4
  class Event
5
5
  module ActiveSpeaker
6
- def other_call_id
6
+ def call_id
7
7
  read_attr :'call-id'
8
8
  end
9
9
 
10
- def other_call_id=(other)
10
+ def call_id=(other)
11
11
  write_attr :'call-id', other
12
12
  end
13
13
 
14
14
  def inspect_attributes # :nodoc:
15
- [:other_call_id] + super
15
+ [:call_id] + super
16
16
  end
17
17
  end
18
18
  end
@@ -13,7 +13,7 @@ module Punchblock
13
13
  element = find_first('*')
14
14
  if element
15
15
  RayoNode.import(element).tap do |reason|
16
- reason.call_id = call_id
16
+ reason.target_call_id = target_call_id
17
17
  reason.component_id = component_id
18
18
  end
19
19
  end
@@ -28,7 +28,7 @@ module Punchblock
28
28
  element = find_first('//ns:recording', :ns => RAYO_NAMESPACES[:record_complete])
29
29
  if element
30
30
  RayoNode.import(element).tap do |recording|
31
- recording.call_id = call_id
31
+ recording.target_call_id = target_call_id
32
32
  recording.component_id = component_id
33
33
  end
34
34
  end
@@ -7,13 +7,13 @@ module Punchblock
7
7
 
8
8
  ##
9
9
  # @return [String] the call ID that was joined
10
- def other_call_id
10
+ def call_id
11
11
  read_attr :'call-id'
12
12
  end
13
13
 
14
14
  ##
15
15
  # @param [String] other the call ID that was joined
16
- def other_call_id=(other)
16
+ def call_id=(other)
17
17
  write_attr :'call-id', other
18
18
  end
19
19
 
@@ -30,7 +30,7 @@ module Punchblock
30
30
  end
31
31
 
32
32
  def inspect_attributes # :nodoc:
33
- [:other_call_id, :mixer_name] + super
33
+ [:call_id, :mixer_name] + super
34
34
  end
35
35
  end # Joined
36
36
  end
@@ -28,7 +28,7 @@ module Punchblock
28
28
  end
29
29
 
30
30
  def inspect
31
- "#<Punchblock::Event::Offer to=\"#{to}\", from=\"#{from}\", call_id=\"#{call_id}\""
31
+ "#<Punchblock::Event::Offer to=\"#{to}\", from=\"#{from}\", call_id=\"#{target_call_id}\""
32
32
  end
33
33
  end # Offer
34
34
  end
@@ -7,13 +7,13 @@ module Punchblock
7
7
 
8
8
  ##
9
9
  # @return [String] the call ID that was unjoined
10
- def other_call_id
10
+ def call_id
11
11
  read_attr :'call-id'
12
12
  end
13
13
 
14
14
  ##
15
15
  # @param [String] other the call ID that was unjoined
16
- def other_call_id=(other)
16
+ def call_id=(other)
17
17
  write_attr :'call-id', other
18
18
  end
19
19
 
@@ -30,7 +30,7 @@ module Punchblock
30
30
  end
31
31
 
32
32
  def inspect_attributes # :nodoc:
33
- [:other_call_id, :mixer_name] + super
33
+ [:call_id, :mixer_name] + super
34
34
  end
35
35
  end # Unjoined
36
36
  end
@@ -9,7 +9,7 @@ module Punchblock
9
9
 
10
10
  class_attribute :registered_ns, :registered_name
11
11
 
12
- attr_accessor :call_id, :mixer_name, :component_id, :domain, :connection, :client, :original_component
12
+ attr_accessor :target_call_id, :target_mixer_name, :component_id, :domain, :connection, :client, :original_component
13
13
 
14
14
  # Register a new stanza class to a name and/or namespace
15
15
  #
@@ -48,7 +48,7 @@ module Punchblock
48
48
  else
49
49
  new.inherit node
50
50
  end.tap do |event|
51
- event.call_id = call_id
51
+ event.target_call_id = call_id
52
52
  event.component_id = component_id
53
53
  end
54
54
  end
@@ -64,7 +64,7 @@ module Punchblock
64
64
  end
65
65
 
66
66
  def inspect_attributes # :nodoc:
67
- [:call_id, :component_id]
67
+ [:target_call_id, :component_id, :target_mixer_name]
68
68
  end
69
69
 
70
70
  def inspect
@@ -82,10 +82,10 @@ module Punchblock
82
82
  pb_logger.trace "Executing command #{command.inspect}"
83
83
  command.request!
84
84
 
85
- command.call_id ||= options[:call_id]
85
+ command.target_call_id ||= options[:call_id]
86
86
  command.component_id ||= options[:component_id]
87
87
 
88
- if command.call_id
88
+ if command.target_call_id
89
89
  execute_call_command command
90
90
  elsif command.component_id
91
91
  execute_component_command command
@@ -95,10 +95,10 @@ module Punchblock
95
95
  end
96
96
 
97
97
  def execute_call_command(command)
98
- if call = call_with_id(command.call_id)
98
+ if call = call_with_id(command.target_call_id)
99
99
  call.execute_command! command
100
100
  else
101
- command.response = ProtocolError.new.setup 'call-not-found', "Could not find a call with ID #{command.call_id}", command.call_id
101
+ command.response = ProtocolError.new.setup 'call-not-found', "Could not find a call with ID #{command.target_call_id}", command.target_call_id
102
102
  end
103
103
  end
104
104
 
@@ -106,7 +106,7 @@ module Punchblock
106
106
  if (component = component_with_id(command.component_id))
107
107
  component.execute_command! command
108
108
  else
109
- command.response = ProtocolError.new.setup 'component-not-found', "Could not find a component with ID #{command.component_id}", command.call_id, command.component_id
109
+ command.response = ProtocolError.new.setup 'component-not-found', "Could not find a component with ID #{command.component_id}", command.target_call_id, command.component_id
110
110
  end
111
111
  end
112
112
 
@@ -98,7 +98,7 @@ module Punchblock
98
98
 
99
99
  def answer_if_not_answered
100
100
  return if answered? || outbound?
101
- execute_command Command::Answer.new
101
+ execute_command Command::Answer.new.tap { |a| a.request! }
102
102
  end
103
103
 
104
104
  def channel=(other)
@@ -137,11 +137,11 @@ module Punchblock
137
137
  event = case ami_event['Bridgestate']
138
138
  when 'Link'
139
139
  Event::Joined.new.tap do |e|
140
- e.other_call_id = other_call.id
140
+ e.call_id = other_call.id
141
141
  end
142
142
  when 'Unlink'
143
143
  Event::Unjoined.new.tap do |e|
144
- e.other_call_id = other_call.id
144
+ e.call_id = other_call.id
145
145
  end
146
146
  end
147
147
  send_pb_event event
@@ -150,7 +150,7 @@ module Punchblock
150
150
  other_call_channel = ([ami_event['Channel1'], ami_event['Channel2']] - [channel]).first
151
151
  if other_call = translator.call_for_channel(other_call_channel)
152
152
  event = Event::Unjoined.new.tap do |e|
153
- e.other_call_id = other_call.id
153
+ e.call_id = other_call.id
154
154
  end
155
155
  send_pb_event event
156
156
  end
@@ -187,11 +187,11 @@ module Punchblock
187
187
  command.response = true
188
188
  end
189
189
  when Command::Join
190
- other_call = translator.call_with_id command.other_call_id
190
+ other_call = translator.call_with_id command.call_id
191
191
  pending_joins[other_call.channel] = command
192
192
  send_agi_action 'EXEC Bridge', other_call.channel
193
193
  when Command::Unjoin
194
- other_call = translator.call_with_id command.other_call_id
194
+ other_call = translator.call_with_id command.call_id
195
195
  redirect_back other_call
196
196
  when Punchblock::Component::Asterisk::AGI::Command
197
197
  execute_component Component::Asterisk::AGICommand, command
@@ -206,7 +206,7 @@ module Punchblock
206
206
 
207
207
  def send_agi_action(command, *params, &block)
208
208
  pb_logger.trace "Sending AGI action #{command}"
209
- @current_agi_command = Punchblock::Component::Asterisk::AGI::Command.new :name => command, :params => params, :call_id => id
209
+ @current_agi_command = Punchblock::Component::Asterisk::AGI::Command.new :name => command, :params => params, :target_call_id => id
210
210
  @current_agi_command.request!
211
211
  @current_agi_command.register_handler :internal, Punchblock::Event::Complete do |e|
212
212
  pb_logger.trace "AGI action received complete event #{e.inspect}"
@@ -259,7 +259,7 @@ module Punchblock
259
259
  end
260
260
 
261
261
  def send_pb_event(event)
262
- event.call_id = id
262
+ event.target_call_id = id
263
263
  pb_logger.trace "Sending Punchblock event: #{event.inspect}"
264
264
  translator.handle_pb_event! event
265
265
  end