punchblock 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +34 -21
  3. data/Rakefile +20 -0
  4. data/lib/punchblock/client/component_registry.rb +2 -0
  5. data/lib/punchblock/client.rb +2 -2
  6. data/lib/punchblock/command/accept.rb +2 -0
  7. data/lib/punchblock/command/answer.rb +2 -0
  8. data/lib/punchblock/command/dial.rb +2 -0
  9. data/lib/punchblock/command/hangup.rb +2 -0
  10. data/lib/punchblock/command/join.rb +2 -0
  11. data/lib/punchblock/command/mute.rb +2 -0
  12. data/lib/punchblock/command/redirect.rb +2 -0
  13. data/lib/punchblock/command/reject.rb +3 -1
  14. data/lib/punchblock/command/unjoin.rb +2 -0
  15. data/lib/punchblock/command/unmute.rb +2 -0
  16. data/lib/punchblock/command.rb +2 -0
  17. data/lib/punchblock/command_node.rb +2 -0
  18. data/lib/punchblock/component/asterisk/agi/command.rb +4 -2
  19. data/lib/punchblock/component/asterisk/agi.rb +2 -0
  20. data/lib/punchblock/component/asterisk/ami/action.rb +4 -2
  21. data/lib/punchblock/component/asterisk/ami.rb +2 -0
  22. data/lib/punchblock/component/asterisk.rb +2 -0
  23. data/lib/punchblock/component/component_node.rb +2 -0
  24. data/lib/punchblock/component/input.rb +2 -0
  25. data/lib/punchblock/component/output.rb +2 -0
  26. data/lib/punchblock/component/record.rb +2 -0
  27. data/lib/punchblock/component/stop.rb +2 -0
  28. data/lib/punchblock/component.rb +2 -0
  29. data/lib/punchblock/connection/asterisk.rb +4 -1
  30. data/lib/punchblock/connection/connected.rb +2 -0
  31. data/lib/punchblock/connection/generic_connection.rb +5 -0
  32. data/lib/punchblock/connection/xmpp.rb +5 -6
  33. data/lib/punchblock/connection.rb +2 -0
  34. data/lib/punchblock/core_ext/blather/stanza/presence.rb +2 -0
  35. data/lib/punchblock/core_ext/blather/stanza.rb +2 -0
  36. data/lib/punchblock/core_ext/ruby.rb +1 -12
  37. data/lib/punchblock/disconnected_error.rb +2 -0
  38. data/lib/punchblock/event/answered.rb +2 -0
  39. data/lib/punchblock/event/asterisk/ami/event.rb +3 -1
  40. data/lib/punchblock/event/asterisk/ami.rb +2 -0
  41. data/lib/punchblock/event/asterisk.rb +2 -0
  42. data/lib/punchblock/event/complete.rb +3 -1
  43. data/lib/punchblock/event/dtmf.rb +2 -0
  44. data/lib/punchblock/event/end.rb +2 -0
  45. data/lib/punchblock/event/joined.rb +2 -0
  46. data/lib/punchblock/event/offer.rb +6 -0
  47. data/lib/punchblock/event/ringing.rb +2 -0
  48. data/lib/punchblock/event/unjoined.rb +2 -0
  49. data/lib/punchblock/event.rb +2 -0
  50. data/lib/punchblock/has_headers.rb +3 -1
  51. data/lib/punchblock/header.rb +2 -0
  52. data/lib/punchblock/key_value_pair_node.rb +2 -0
  53. data/lib/punchblock/media_container.rb +2 -0
  54. data/lib/punchblock/media_node.rb +2 -0
  55. data/lib/punchblock/protocol_error.rb +2 -0
  56. data/lib/punchblock/rayo_node.rb +4 -3
  57. data/lib/punchblock/ref.rb +2 -0
  58. data/lib/punchblock/translator/asterisk/call.rb +80 -26
  59. data/lib/punchblock/translator/asterisk/component/asterisk/agi_command.rb +3 -1
  60. data/lib/punchblock/translator/asterisk/component/asterisk/ami_action.rb +3 -1
  61. data/lib/punchblock/translator/asterisk/component/asterisk.rb +2 -0
  62. data/lib/punchblock/translator/asterisk/component/input.rb +4 -2
  63. data/lib/punchblock/translator/asterisk/component/output.rb +21 -3
  64. data/lib/punchblock/translator/asterisk/component.rb +2 -0
  65. data/lib/punchblock/translator/asterisk.rb +50 -20
  66. data/lib/punchblock/translator.rb +2 -0
  67. data/lib/punchblock/version.rb +3 -1
  68. data/lib/punchblock.rb +2 -0
  69. data/punchblock.gemspec +2 -2
  70. data/spec/capture_warnings.rb +32 -0
  71. data/spec/punchblock/client/component_registry_spec.rb +2 -0
  72. data/spec/punchblock/client_spec.rb +3 -1
  73. data/spec/punchblock/command/accept_spec.rb +3 -1
  74. data/spec/punchblock/command/answer_spec.rb +3 -1
  75. data/spec/punchblock/command/dial_spec.rb +12 -10
  76. data/spec/punchblock/command/hangup_spec.rb +3 -1
  77. data/spec/punchblock/command/join_spec.rb +11 -9
  78. data/spec/punchblock/command/mute_spec.rb +3 -1
  79. data/spec/punchblock/command/redirect_spec.rb +5 -3
  80. data/spec/punchblock/command/reject_spec.rb +7 -5
  81. data/spec/punchblock/command/unjoin_spec.rb +7 -5
  82. data/spec/punchblock/command/unmute_spec.rb +3 -1
  83. data/spec/punchblock/command_node_spec.rb +9 -7
  84. data/spec/punchblock/component/asterisk/agi/command_spec.rb +21 -19
  85. data/spec/punchblock/component/asterisk/ami/action_spec.rb +19 -17
  86. data/spec/punchblock/component/component_node_spec.rb +5 -3
  87. data/spec/punchblock/component/input_spec.rb +51 -49
  88. data/spec/punchblock/component/output_spec.rb +60 -58
  89. data/spec/punchblock/component/record_spec.rb +36 -34
  90. data/spec/punchblock/connection/asterisk_spec.rb +9 -4
  91. data/spec/punchblock/connection/xmpp_spec.rb +40 -39
  92. data/spec/punchblock/event/answered_spec.rb +4 -2
  93. data/spec/punchblock/event/asterisk/ami/event_spec.rb +9 -7
  94. data/spec/punchblock/event/complete_spec.rb +12 -10
  95. data/spec/punchblock/event/dtmf_spec.rb +6 -4
  96. data/spec/punchblock/event/end_spec.rb +6 -4
  97. data/spec/punchblock/event/joined_spec.rb +8 -6
  98. data/spec/punchblock/event/offer_spec.rb +7 -5
  99. data/spec/punchblock/event/ringing_spec.rb +4 -2
  100. data/spec/punchblock/event/unjoined_spec.rb +8 -6
  101. data/spec/punchblock/header_spec.rb +13 -11
  102. data/spec/punchblock/protocol_error_spec.rb +8 -6
  103. data/spec/punchblock/ref_spec.rb +5 -3
  104. data/spec/punchblock/translator/asterisk/call_spec.rb +261 -14
  105. data/spec/punchblock/translator/asterisk/component/asterisk/agi_command_spec.rb +13 -11
  106. data/spec/punchblock/translator/asterisk/component/asterisk/ami_action_spec.rb +4 -2
  107. data/spec/punchblock/translator/asterisk/component/input_spec.rb +10 -8
  108. data/spec/punchblock/translator/asterisk/component/output_spec.rb +111 -20
  109. data/spec/punchblock/translator/asterisk/component_spec.rb +3 -1
  110. data/spec/punchblock/translator/asterisk_spec.rb +107 -10
  111. data/spec/spec_helper.rb +23 -17
  112. data/spec/support/mock_connection_with_event_handler.rb +2 -0
  113. metadata +43 -41
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ spec/reports
11
11
  vendor
12
12
  .rbx/
13
13
  *.rbc
14
+ tmp
data/CHANGELOG.md CHANGED
@@ -1,24 +1,37 @@
1
- # develop
2
-
3
- # v0.9.2 - 2012-02-18
1
+ # [develop](https://github.com/adhearsion/punchblock)
2
+
3
+ # [v0.10.0](https://github.com/adhearsion/punchblock/compare/v0.9.2...v0.10.0) - [2012-03-19](https://rubygems.org/gems/punchblock/versions/0.10.0)
4
+ * Feature: app_swift is now supported on Asterisk with a media_engine type of :swift
5
+ * Feature: Asterisk calls now support the Join API
6
+ * Feature: On Asterisk, Punchblock creates a context and extension to redirect calls to
7
+ * Bugfix: Unjoining calls now redirects both legs
8
+ * Bugfix: Unlink events on Asterisk correctly send Unjoin Punchblock events
9
+ * Bugfix: The Asterisk translator now ignores calls to 'h' or of type 'Kill'
10
+ * Bugfix: Handle more XMPP connection errors gracefully
11
+ * Bugfix: The XMPP connection ready event is now available to external handlers
12
+ * Bugfix: The Asterisk connection now passes the `:media_engine` option down to the translator
13
+ * Bugfix: Connections now always respond to `#connected?`
14
+ * Bugfix: Connection termination handled gracefully on Asterisk
15
+
16
+ # [v0.9.2](https://github.com/adhearsion/punchblock/compare/v0.9.1...v0.9.2) - [2012-02-18](https://rubygems.org/gems/punchblock/versions/0.9.2)
4
17
  * Feature: Asterisk calls receiving media commands are implicitly answered
5
18
  * Bugfix: Unrenderable output documents on Asterisk should return a sensible error
6
19
  * Bugfix: Log the target of commands correctly
7
20
  * Bugfix: Do not wrap exceptions in ProtocolError
8
21
 
9
- # v0.9.1 - 2012-01-30
22
+ # [v0.9.1](https://github.com/adhearsion/punchblock/compare/v0.9.0...v0.9.1) - [2012-01-30](https://rubygems.org/gems/punchblock/versions/0.9.1)
10
23
  * Bugfix: Closing an disconnected XMPP connection is a no-op
11
24
 
12
- # v0.9.0 - 2012-01-30
25
+ # [v0.9.0](https://github.com/adhearsion/punchblock/compare/v0.8.4...v0.9.0) - [2012-01-30](https://rubygems.org/gems/punchblock/versions/0.9.0)
13
26
  * Bugfix: Remove the rest of the deprecated Tropo components (conference)
14
27
  * Feature: Outbound dials on Asterisk now respect the dial timeout
15
28
  * Bugfix: Registering stanza handlers on an XMPP connection now sets them in the correct order such that they do not override the internally defined handlers
16
29
 
17
- # v0.8.4 - 2012-01-19
30
+ # [v0.8.4](https://github.com/adhearsion/punchblock/compare/v0.8.3...v0.8.4) - [2012-01-19](https://rubygems.org/gems/punchblock/versions/0.8.4)
18
31
  * Bugfix: End, Ringing & Answered events are allowed to have headers
19
32
  * Feature: Dial commands may have an optional timeout
20
33
 
21
- # v0.8.3 - 2012-01-17
34
+ # [v0.8.3](https://github.com/adhearsion/punchblock/compare/v0.8.2...v0.8.3) - [2012-01-17](https://rubygems.org/gems/punchblock/versions/0.8.3)
22
35
  * Feature: Return an error when trying to execute a command for unknown calls/components or when not understood
23
36
  * Feature: Log calls/translator shutting down
24
37
  * Feature: Calls and components should log their IDs
@@ -35,20 +48,20 @@
35
48
  * Bugfix: A call being hung up should terminate the call actor
36
49
  * Bugfix: Fix a mock expectation error in a test
37
50
 
38
- # v0.8.2 - 2012-01-10
51
+ # [v0.8.2](https://github.com/adhearsion/punchblock/compare/v0.8.1...v0.8.2) - [2012-01-10](https://rubygems.org/gems/punchblock/versions/0.8.2)
39
52
  * Feature: Support outbound dial on Asterisk
40
53
  * Bugfix: Asterisk hangup causes should map to correct Rayo End reason
41
54
 
42
- # v0.8.1 - 2012-01-09
55
+ # [v0.8.1](https://github.com/adhearsion/punchblock/compare/v0.8.0...v0.8.1) - [2012-01-09](https://rubygems.org/gems/punchblock/versions/0.8.1)
43
56
  * Feature: Support DTMF Input components on Asterisk
44
57
 
45
- # v0.8.0 - 2012-01-06
58
+ # [v0.8.0](https://github.com/adhearsion/punchblock/compare/v0.7.2...v0.8.0) - [2012-01-06](https://rubygems.org/gems/punchblock/versions/0.8.0)
46
59
  * Feature: Expose Blather's connection timeout config when creating a Connection::XMPP
47
60
  * Bugfix: Remove some deprecated Tropo extension components
48
61
  * Bugfix: Remove reconnection logic since it really belongs in the consumer
49
62
  * Feature: Raise a DisconnectedError when a disconnection is detected
50
63
 
51
- # v0.7.2 - 2011-12-28
64
+ # [v0.7.2](https://github.com/adhearsion/punchblock/compare/v0.7.1...v0.7.2) - [2011-12-28](https://rubygems.org/gems/punchblock/versions/0.7.2)
52
65
  * Feature: Allow sending commands to mixers easily
53
66
  * Feature: Allow configuration of Rayo XMPP domains (root, call and mixer)
54
67
  * Feature: Log Blather messages to the trace log level
@@ -60,12 +73,12 @@
60
73
  * Bugfix: Asterisk media output should default to Asterisk native output (STREAM FILE)
61
74
  * Bugfix: An Output node's default max_time value should be nil rather than zero
62
75
 
63
- # v0.7.1 - 2011-11-24
76
+ # [v0.7.1](https://github.com/adhearsion/punchblock/compare/v0.7.0...v0.7.1) - [2011-11-24](https://rubygems.org/gems/punchblock/versions/0.7.1)
64
77
  * [FEATURE] Add `Connection#not_ready!`, to instruct the server not to send any more offers.
65
78
  * [BUGFIX] Translate all exceptions raised by the XMPP connection into a ProtocolError
66
79
  * [UPDATE] Blather dependency to >= 0.5.9
67
80
 
68
- # v0.7.0 - 2011-11-22
81
+ # [v0.7.0](https://github.com/adhearsion/punchblock/compare/v0.6.2...v0.7.0) - [2011-11-22](https://rubygems.org/gems/punchblock/versions/0.7.0)
69
82
  * Bugfix: Some spec mistakes
70
83
  * Feature: Allow execution of actions against global components on Asterisk
71
84
  * API change: The console has been removed
@@ -74,37 +87,37 @@
74
87
  * Bugfix: Bump the Celluloid dependency to avoid spec failures on JRuby and monkey-patching for mockability
75
88
  * API change: Event handlers registered on components are no longer triggered by incoming events internally to Punchblock. These events must be consumed via a Client's event handlers or event queue and manually triggered on a component using ComponentNode#trigger_event_handler
76
89
 
77
- # v0.6.2
90
+ # [v0.6.2](https://github.com/adhearsion/punchblock/compare/v0.6.1...v0.6.2)
78
91
  # Feature: Added basic support for running Punchblock apps on Asterisk. Calls coming in to AsyncAGI result in the client receiving an Offer, hangup events are sent, and accept/answer/hangup commands work.
79
92
  # API change: The logger is now set using Punchblock.logger= rather than as a hash key to Connection.new
80
93
 
81
- # v0.6.1
94
+ # [v0.6.1](https://github.com/adhearsion/punchblock/compare/v0.6.0...v0.6.1)
82
95
  * Feature: Allow instructing the connection we are ready. An XMPP connection will send initial presence with a status of 'chat' to the rayo domain
83
96
  * Bugfix: When running on Asterisk, two FullyBooted events will now trigger a connected event
84
97
  * Bugfix: No longer ignore offers from the specified rayo domain on XMPP connections
85
98
  * Feature: Tag all event objects with the XMPP domain they came from
86
99
 
87
- # v0.6.0
100
+ # [v0.6.0](https://github.com/adhearsion/punchblock/compare/v0.5.1...v0.6.0)
88
101
  * API change: Punchblock consumers now need to instantiate both a Connection and a Client (see the punchblock-console gem for an example)
89
102
  * Feature: Added a Connection for Asterisk, utilising RubyAMI to open an AMI connection to Asterisk, and allowing AMI actions to be executed. AMI events are handled by the client event handler.
90
103
  * Deprecation: The punchblock-console and the associated DSL are now deprecated and the punchblock-console gem should be used instead
91
104
 
92
- # v0.5.1
105
+ # [v0.5.1](https://github.com/adhearsion/punchblock/compare/v0.5.0...v0.5.1)
93
106
  API change: Connections now raise a Punchblock::Connection::Connected instance as an event, rather than the class itself
94
107
 
95
- # v0.5.0
108
+ # [v0.5.0](https://github.com/adhearsion/punchblock/compare/v0.4.3...v0.5.0)
96
109
  * Refactoring/API change: Client and connection level concerns are now separated, and one must create a Connection to be passed to a Client on creation. Client now has the choice between an event queue and guarded event handlers.
97
110
 
98
- # v0.4.3
111
+ # [v0.4.3](https://github.com/adhearsion/punchblock/compare/v0.4.2...v0.4.3)
99
112
  * Feature: Support for meta-data on recordings (size & duration)
100
113
  * Feature: Allow specifying all of Blather's setup options (required to use PB as an XMPP component)
101
114
  * Bugfix: Rayo events are discarded if they don't come from the specified domain
102
115
  * Bugfix: Component execution in the sample DSL now doesn't expect events on the main queue
103
116
 
104
- # v0.4.2
117
+ # [v0.4.2](https://github.com/adhearsion/punchblock/compare/v0.4.1...v0.4.2)
105
118
  * Bugfix: Conference complete event was not being handled
106
119
 
107
- # v0.4.1
120
+ # [v0.4.1](https://github.com/adhearsion/punchblock/compare/v0.4.0...v0.4.1)
108
121
  * Feature/API change: Components no longer have an event queue, but instead it is possible to define guarded event handlers via #register_event_handler
109
122
 
110
123
  # v0.4.0
data/Rakefile CHANGED
@@ -8,6 +8,7 @@ require 'ci/reporter/rake/rspec'
8
8
  RSpec::Core::RakeTask.new(:spec) do |spec|
9
9
  spec.pattern = 'spec/**/*_spec.rb'
10
10
  spec.rspec_opts = '--color'
11
+ spec.ruby_opts = "-w -r./spec/capture_warnings"
11
12
  end
12
13
 
13
14
  task :default => :spec
@@ -16,3 +17,22 @@ task :hudson => :ci
16
17
 
17
18
  require 'yard'
18
19
  YARD::Rake::YardocTask.new
20
+
21
+ task :encodeify do
22
+ Dir['{lib,spec}/**/*.rb'].each do |filename|
23
+ File.open filename do |file|
24
+ first_line = file.first
25
+ if first_line == "# encoding: utf-8\n"
26
+ puts "#{filename} is utf-8"
27
+ else
28
+ puts "Making #{filename} utf-8..."
29
+ File.unlink filename
30
+ File.open filename, "w" do |new_file|
31
+ new_file.write "# encoding: utf-8\n\n"
32
+ new_file.write first_line
33
+ new_file.write file.read
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Client
3
5
  class ComponentRegistry
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Client
3
5
  extend ActiveSupport::Autoload
@@ -24,7 +26,6 @@ module Punchblock
24
26
 
25
27
  def handle_event(event)
26
28
  event.client = self
27
- pb_logger.debug "Handling event #{event} with source #{event.source}."
28
29
  if event.source
29
30
  event.source.add_event event
30
31
  else
@@ -51,7 +52,6 @@ module Punchblock
51
52
  end
52
53
 
53
54
  def execute_command(command, options = {})
54
- pb_logger.debug "Executing command: #{command.inspect} with options #{options.inspect}"
55
55
  async = options.has_key?(:async) ? options.delete(:async) : true
56
56
  command.client = self
57
57
  if command.respond_to?(:register_handler)
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  class Accept < CommandNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  class Answer < CommandNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  class Dial < CommandNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  class Hangup < CommandNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  class Join < CommandNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  class Mute < CommandNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  class Redirect < CommandNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  class Reject < CommandNode
@@ -53,7 +55,7 @@ module Punchblock
53
55
  if reject_reason && !VALID_REASONS.include?(reject_reason.to_sym)
54
56
  raise ArgumentError, "Invalid Reason (#{reject_reason}), use: #{VALID_REASONS*' '}"
55
57
  end
56
- children.each &:remove
58
+ children.each(&:remove)
57
59
  self << RayoNode.new(reject_reason)
58
60
  end
59
61
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  class Unjoin < CommandNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  class Unmute < CommandNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Command
3
5
  extend ActiveSupport::Autoload
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'state_machine'
2
4
 
3
5
  module Punchblock
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Component
3
5
  module Asterisk
@@ -23,7 +25,7 @@ module Punchblock
23
25
  # @return [Array[String]] array of values of params
24
26
  #
25
27
  def params_array
26
- params.map &:value
28
+ params.map(&:value)
27
29
  end
28
30
 
29
31
  ##
@@ -39,7 +41,7 @@ module Punchblock
39
41
  # @param [Hash, Array] params A hash of key-value param pairs, or an array of Param objects
40
42
  #
41
43
  def params=(params)
42
- find('//ns:param', :ns => self.class.registered_ns).each &:remove
44
+ find('//ns:param', :ns => self.class.registered_ns).each(&:remove)
43
45
  [params].flatten.each { |i| self << Param.new(i) } if params.is_a? Array
44
46
  end
45
47
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Component
3
5
  module Asterisk
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'punchblock/key_value_pair_node'
2
4
 
3
5
  module Punchblock
@@ -44,7 +46,7 @@ module Punchblock
44
46
  # @param [Hash, Array] params A hash of key-value param pairs, or an array of Param objects
45
47
  #
46
48
  def params=(params)
47
- find('//ns:param', :ns => self.class.registered_ns).each &:remove
49
+ find('//ns:param', :ns => self.class.registered_ns).each(&:remove)
48
50
  if params.is_a? Hash
49
51
  params.each_pair { |k,v| self << Param.new(k, v) }
50
52
  elsif params.is_a? Array
@@ -120,7 +122,7 @@ module Punchblock
120
122
  # @param [Hash, Array] attributes A hash of key-value attribute pairs, or an array of Attribute objects
121
123
  #
122
124
  def attributes=(attributes)
123
- find('//ns:attribute', :ns => self.class.registered_ns).each &:remove
125
+ find('//ns:attribute', :ns => self.class.registered_ns).each(&:remove)
124
126
  if attributes.is_a? Hash
125
127
  attributes.each_pair { |k,v| self << Attribute.new(k, v) }
126
128
  elsif attributes.is_a? Array
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Component
3
5
  module Asterisk
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Component
3
5
  module Asterisk
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Component
3
5
  class ComponentNode < CommandNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Component
3
5
  class Input < ComponentNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Component
3
5
  class Output < ComponentNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Component
3
5
  class Record < ComponentNode
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Component
3
5
  class Stop < CommandNode # :nodoc:
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Component
3
5
  extend ActiveSupport::Autoload
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'ruby_ami'
2
4
 
3
5
  module Punchblock
@@ -8,13 +10,14 @@ module Punchblock
8
10
 
9
11
  def initialize(options = {})
10
12
  @ami_client = RubyAMI::Client.new options.merge(:event_handler => lambda { |event| translator.handle_ami_event! event }, :logger => pb_logger)
11
- @translator = Translator::Asterisk.new @ami_client, self
13
+ @translator = Translator::Asterisk.new @ami_client, self, options[:media_engine]
12
14
  super()
13
15
  end
14
16
 
15
17
  def run
16
18
  pb_logger.debug "Starting the RubyAMI client"
17
19
  ami_client.start
20
+ raise DisconnectedError
18
21
  end
19
22
 
20
23
  def stop
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Connection
3
5
  Connected = Class.new do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Connection
3
5
  class GenericConnection
@@ -10,6 +12,9 @@ module Punchblock
10
12
 
11
13
  def not_ready!
12
14
  end
15
+
16
+ def connected?
17
+ end
13
18
  end
14
19
  end
15
20
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  %w{
2
4
  timeout
3
5
  blather/client/dsl
@@ -25,7 +27,7 @@ module Punchblock
25
27
  def initialize(options = {})
26
28
  raise ArgumentError unless (@username = options[:username]) && options[:password]
27
29
 
28
- setup *[:username, :password, :host, :port, :certs, :connection_timeout].map { |key| options.delete key }
30
+ setup(*[:username, :password, :host, :port, :certs, :connection_timeout].map { |key| options.delete key })
29
31
 
30
32
  @root_domain = Blather::JID.new(options[:root_domain] || options[:rayo_domain] || @username).domain
31
33
  @calls_domain = options[:calls_domain] || "calls.#{@root_domain}"
@@ -61,7 +63,6 @@ module Punchblock
61
63
  command.mixer_name ||= options[:mixer_name]
62
64
  command.component_id ||= options[:component_id]
63
65
  create_iq(jid_for_command(command)).tap do |iq|
64
- pb_logger.debug "Sending IQ ID #{iq.id} #{command.inspect} to #{iq.to}"
65
66
  iq << command
66
67
  end
67
68
  end
@@ -76,7 +77,7 @@ module Punchblock
76
77
  def connect
77
78
  begin
78
79
  EM.run { client.run }
79
- rescue Blather::Stream::ConnectionFailed, Blather::Stream::ConnectionTimeout => e
80
+ rescue Blather::Stream::ConnectionFailed, Blather::Stream::ConnectionTimeout, Blather::StreamError => e
80
81
  raise DisconnectedError.new(e.class.to_s, e.message)
81
82
  end
82
83
  end
@@ -125,9 +126,7 @@ module Punchblock
125
126
 
126
127
  def handle_presence(p)
127
128
  throw :pass unless p.rayo_event?
128
- pb_logger.info "Receiving event for call ID #{p.call_id}"
129
129
  @callmap[p.call_id] = p.from.domain
130
- pb_logger.debug p.inspect
131
130
  event = p.event
132
131
  event.connection = self
133
132
  event.domain = p.from.domain
@@ -137,7 +136,6 @@ module Punchblock
137
136
  def handle_iq_result(iq, command)
138
137
  # FIXME: Do we need to raise a warning if the domain changes?
139
138
  @callmap[iq.from.node] = iq.from.domain
140
- pb_logger.debug "Command #{iq.id} completed successfully"
141
139
  command.response = iq.rayo_node.is_a?(Ref) ? iq.rayo_node : true
142
140
  end
143
141
 
@@ -153,6 +151,7 @@ module Punchblock
153
151
  event_handler.call Connected.new
154
152
  pb_logger.info "Connected to XMPP as #{@username}"
155
153
  @rayo_ping = EM::PeriodicTimer.new(@ping_period) { ping_rayo } if @ping_period
154
+ throw :pass
156
155
  end
157
156
 
158
157
  disconnected do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  module Connection
3
5
  extend ActiveSupport::Autoload
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Blather
2
4
  class Stanza
3
5
  class Presence
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Blather
2
4
  class Stanza
3
5
  ##
@@ -1,15 +1,4 @@
1
- class Hash
2
- def select(&block)
3
- val = super(&block)
4
- if val.is_a?(Array)
5
- val = val.inject({}) do |accumulator, element|
6
- accumulator[element[0]] = element[1]
7
- accumulator
8
- end
9
- end
10
- val
11
- end
12
- end
1
+ # encoding: utf-8
13
2
 
14
3
  class NullObject
15
4
  def method_missing(*args)
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  ##
3
5
  # This exception may be raised if the connection to the server is interrupted.
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Event
3
5
  class Answered < Event
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'punchblock/key_value_pair_node'
2
4
 
3
5
  module Punchblock
@@ -44,7 +46,7 @@ module Punchblock
44
46
  # @param [Hash, Array] attributes A hash of key-value attribute pairs, or an array of Attribute objects
45
47
  #
46
48
  def attributes=(attributes)
47
- find('//ns:attribute', :ns => self.class.registered_ns).each &:remove
49
+ find('//ns:attribute', :ns => self.class.registered_ns).each(&:remove)
48
50
  if attributes.is_a? Hash
49
51
  attributes.each_pair { |k,v| self << Attribute.new(k, v) }
50
52
  elsif attributes.is_a? Array
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Event
3
5
  module Asterisk
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Event
3
5
  module Asterisk
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Event
3
5
  class Complete < Event
@@ -18,7 +20,7 @@ module Punchblock
18
20
  end
19
21
 
20
22
  def reason=(other)
21
- children.map &:remove
23
+ children.map(&:remove)
22
24
  self << other
23
25
  end
24
26
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Event
3
5
  class DTMF < Event
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Event
3
5
  class End < Event
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Event
3
5
  class Joined < Event
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Event
3
5
  class Offer < Event
@@ -24,6 +26,10 @@ module Punchblock
24
26
  def inspect_attributes # :nodoc:
25
27
  [:to, :from] + super
26
28
  end
29
+
30
+ def inspect
31
+ "#<Punchblock::Event::Offer to=\"#{to}\", from=\"#{from}\", call_id=\"#{call_id}\""
32
+ end
27
33
  end # Offer
28
34
  end
29
35
  end # Punchblock
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Punchblock
2
4
  class Event
3
5
  class Ringing < Event