punchblock 1.8.0 → 1.8.1
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -1
- data/lib/punchblock/component/component_node.rb +1 -1
- data/lib/punchblock/component/stop.rb +2 -2
- data/lib/punchblock/connection/asterisk.rb +3 -3
- data/lib/punchblock/connection/freeswitch.rb +2 -2
- data/lib/punchblock/connection/xmpp.rb +1 -1
- data/lib/punchblock/translator.rb +1 -0
- data/lib/punchblock/translator/asterisk.rb +10 -9
- data/lib/punchblock/translator/asterisk/call.rb +15 -7
- data/lib/punchblock/translator/asterisk/component/asterisk/ami_action.rb +1 -1
- data/lib/punchblock/translator/asterisk/component/input.rb +3 -4
- data/lib/punchblock/translator/asterisk/component/output.rb +6 -6
- data/lib/punchblock/translator/asterisk/component/record.rb +7 -7
- data/lib/punchblock/translator/asterisk/component/stop_by_redirect.rb +3 -3
- data/lib/punchblock/translator/dtmf_recognizer.rb +87 -0
- data/lib/punchblock/translator/freeswitch.rb +9 -7
- data/lib/punchblock/translator/freeswitch/call.rb +6 -4
- data/lib/punchblock/translator/freeswitch/component/input.rb +1 -2
- data/lib/punchblock/translator/freeswitch/component/output.rb +1 -2
- data/lib/punchblock/translator/freeswitch/component/tts_output.rb +1 -1
- data/lib/punchblock/translator/input_component.rb +17 -64
- data/lib/punchblock/version.rb +1 -1
- data/punchblock.gemspec +1 -1
- data/spec/punchblock/component/input_spec.rb +1 -1
- data/spec/punchblock/component/output_spec.rb +33 -3
- data/spec/punchblock/component/record_spec.rb +1 -1
- data/spec/punchblock/connection/asterisk_spec.rb +3 -3
- data/spec/punchblock/connection/freeswitch_spec.rb +3 -2
- data/spec/punchblock/connection/xmpp_spec.rb +18 -6
- data/spec/punchblock/translator/asterisk/call_spec.rb +83 -31
- data/spec/punchblock/translator/asterisk/component/input_spec.rb +1 -1
- data/spec/punchblock/translator/asterisk/component/output_spec.rb +32 -27
- data/spec/punchblock/translator/asterisk/component/record_spec.rb +47 -43
- data/spec/punchblock/translator/asterisk/component/stop_by_redirect_spec.rb +2 -2
- data/spec/punchblock/translator/asterisk_spec.rb +28 -26
- data/spec/punchblock/translator/freeswitch/call_spec.rb +24 -15
- data/spec/punchblock/translator/freeswitch/component/input_spec.rb +1 -1
- data/spec/punchblock/translator/freeswitch/component/output_spec.rb +2 -3
- data/spec/punchblock/translator/freeswitch/component/record_spec.rb +1 -1
- data/spec/punchblock/translator/freeswitch_spec.rb +75 -18
- data/spec/spec_helper.rb +1 -1
- metadata +24 -74
|
@@ -70,12 +70,13 @@ module Punchblock
|
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
it "should execute Swift" do
|
|
73
|
-
mock_call.should_receive(:send_agi_action
|
|
73
|
+
mock_call.async.should_receive(:send_agi_action).once.with 'EXEC Swift', ssml_with_options
|
|
74
74
|
subject.execute
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
it 'should send a complete event when Swift completes' do
|
|
78
|
-
|
|
78
|
+
async_proxy = mock_call.async
|
|
79
|
+
def async_proxy.send_agi_action(*args, &block)
|
|
79
80
|
block.call Punchblock::Component::Asterisk::AGI::Command::Complete::Success.new(:code => 200, :result => 1)
|
|
80
81
|
end
|
|
81
82
|
subject.execute
|
|
@@ -86,7 +87,7 @@ module Punchblock
|
|
|
86
87
|
context "set to nil" do
|
|
87
88
|
let(:command_opts) { { :interrupt_on => nil } }
|
|
88
89
|
it "should not add interrupt arguments" do
|
|
89
|
-
mock_call.should_receive(:send_agi_action
|
|
90
|
+
mock_call.async.should_receive(:send_agi_action).once.with 'EXEC Swift', ssml_with_options
|
|
90
91
|
subject.execute
|
|
91
92
|
end
|
|
92
93
|
end
|
|
@@ -95,7 +96,7 @@ module Punchblock
|
|
|
95
96
|
let(:command_opts) { { :interrupt_on => :any } }
|
|
96
97
|
it "should add the interrupt options to the argument" do
|
|
97
98
|
expect_answered
|
|
98
|
-
mock_call.should_receive(:send_agi_action
|
|
99
|
+
mock_call.async.should_receive(:send_agi_action).once.with 'EXEC Swift', ssml_with_options('', '|1|1')
|
|
99
100
|
subject.execute
|
|
100
101
|
end
|
|
101
102
|
end
|
|
@@ -104,7 +105,7 @@ module Punchblock
|
|
|
104
105
|
let(:command_opts) { { :interrupt_on => :dtmf } }
|
|
105
106
|
it "should add the interrupt options to the argument" do
|
|
106
107
|
expect_answered
|
|
107
|
-
mock_call.should_receive(:send_agi_action
|
|
108
|
+
mock_call.async.should_receive(:send_agi_action).once.with 'EXEC Swift', ssml_with_options('', '|1|1')
|
|
108
109
|
subject.execute
|
|
109
110
|
end
|
|
110
111
|
end
|
|
@@ -123,7 +124,7 @@ module Punchblock
|
|
|
123
124
|
context "set to nil" do
|
|
124
125
|
let(:command_opts) { { :voice => nil } }
|
|
125
126
|
it "should not add a voice at the beginning of the argument" do
|
|
126
|
-
mock_call.should_receive(:send_agi_action
|
|
127
|
+
mock_call.async.should_receive(:send_agi_action).once.with 'EXEC Swift', ssml_with_options
|
|
127
128
|
subject.execute
|
|
128
129
|
end
|
|
129
130
|
end
|
|
@@ -131,7 +132,7 @@ module Punchblock
|
|
|
131
132
|
context "set to Leonard" do
|
|
132
133
|
let(:command_opts) { { :voice => "Leonard" } }
|
|
133
134
|
it "should add a voice at the beginning of the argument" do
|
|
134
|
-
mock_call.should_receive(:send_agi_action
|
|
135
|
+
mock_call.async.should_receive(:send_agi_action).once.with 'EXEC Swift', ssml_with_options('Leonard^', '')
|
|
135
136
|
subject.execute
|
|
136
137
|
end
|
|
137
138
|
end
|
|
@@ -158,14 +159,14 @@ module Punchblock
|
|
|
158
159
|
end
|
|
159
160
|
|
|
160
161
|
def expect_mrcpsynth_with_options(options)
|
|
161
|
-
mock_call.should_receive(:send_agi_action
|
|
162
|
+
mock_call.async.should_receive(:send_agi_action).once.with do |*args|
|
|
162
163
|
args[0].should be == 'EXEC MRCPSynth'
|
|
163
164
|
args[2].should match options
|
|
164
165
|
end
|
|
165
166
|
end
|
|
166
167
|
|
|
167
168
|
it "should execute MRCPSynth" do
|
|
168
|
-
mock_call.should_receive(:send_agi_action
|
|
169
|
+
mock_call.async.should_receive(:send_agi_action).once.with 'EXEC MRCPSynth', ssml_doc.to_s.squish.gsub(/["\\]/) { |m| "\\#{m}" }, ''
|
|
169
170
|
subject.execute
|
|
170
171
|
end
|
|
171
172
|
|
|
@@ -177,7 +178,7 @@ module Punchblock
|
|
|
177
178
|
end
|
|
178
179
|
|
|
179
180
|
it 'should escape TTS strings containing a comma' do
|
|
180
|
-
mock_call.should_receive(:send_agi_action
|
|
181
|
+
mock_call.async.should_receive(:send_agi_action).once.with do |*args|
|
|
181
182
|
args[0].should be == 'EXEC MRCPSynth'
|
|
182
183
|
args[1].should match(/this\\, here\\, is a test/)
|
|
183
184
|
end
|
|
@@ -186,7 +187,8 @@ module Punchblock
|
|
|
186
187
|
end
|
|
187
188
|
|
|
188
189
|
it 'should send a complete event when MRCPSynth completes' do
|
|
189
|
-
|
|
190
|
+
async_proxy = mock_call.async
|
|
191
|
+
def async_proxy.send_agi_action(*args, &block)
|
|
190
192
|
block.call Punchblock::Component::Asterisk::AGI::Command::Complete::Success.new(:code => 200, :result => 1)
|
|
191
193
|
end
|
|
192
194
|
subject.execute
|
|
@@ -358,11 +360,11 @@ module Punchblock
|
|
|
358
360
|
[:asterisk, nil].each do |media_engine|
|
|
359
361
|
context "with a media engine of #{media_engine.inspect}" do
|
|
360
362
|
def expect_playback(filename = audio_filename)
|
|
361
|
-
mock_call.should_receive(:send_agi_action
|
|
363
|
+
mock_call.async.should_receive(:send_agi_action).once.with 'EXEC Playback', filename
|
|
362
364
|
end
|
|
363
365
|
|
|
364
366
|
def expect_playback_noanswer
|
|
365
|
-
mock_call.should_receive(:send_agi_action
|
|
367
|
+
mock_call.async.should_receive(:send_agi_action).once.with 'EXEC Playback', audio_filename + ',noanswer'
|
|
366
368
|
end
|
|
367
369
|
|
|
368
370
|
let(:audio_filename) { 'http://foo.com/bar.mp3' }
|
|
@@ -411,7 +413,8 @@ module Punchblock
|
|
|
411
413
|
def mock_call.answered?
|
|
412
414
|
true
|
|
413
415
|
end
|
|
414
|
-
|
|
416
|
+
async_proxy = mock_call.async
|
|
417
|
+
def async_proxy.send_agi_action(*args, &block)
|
|
415
418
|
block.call Punchblock::Component::Asterisk::AGI::Command::Complete::Success.new(:code => 200, :result => 1)
|
|
416
419
|
end
|
|
417
420
|
subject.execute
|
|
@@ -435,7 +438,8 @@ module Punchblock
|
|
|
435
438
|
|
|
436
439
|
it 'should send a complete event when the file finishes playback' do
|
|
437
440
|
expect_answered
|
|
438
|
-
|
|
441
|
+
async_proxy = mock_call.async
|
|
442
|
+
def async_proxy.send_agi_action(*args, &block)
|
|
439
443
|
block.call Punchblock::Component::Asterisk::AGI::Command::Complete::Success.new(:code => 200, :result => 1)
|
|
440
444
|
end
|
|
441
445
|
subject.execute
|
|
@@ -503,7 +507,8 @@ module Punchblock
|
|
|
503
507
|
|
|
504
508
|
it 'should send a complete event after the final file has finished playback' do
|
|
505
509
|
expect_answered
|
|
506
|
-
|
|
510
|
+
async_proxy = mock_call.async
|
|
511
|
+
def async_proxy.send_agi_action(*args, &block)
|
|
507
512
|
block.call Punchblock::Component::Asterisk::AGI::Command::Complete::Success.new(:code => 200, :result => 1)
|
|
508
513
|
end
|
|
509
514
|
latch = CountDownLatch.new 1
|
|
@@ -682,7 +687,7 @@ module Punchblock
|
|
|
682
687
|
it "does not redirect the call" do
|
|
683
688
|
expect_answered
|
|
684
689
|
expect_playback
|
|
685
|
-
mock_call.should_receive(:redirect_back
|
|
690
|
+
mock_call.async.should_receive(:redirect_back).never
|
|
686
691
|
subject.execute
|
|
687
692
|
original_command.response(0.1).should be_a Ref
|
|
688
693
|
send_ami_events_for_dtmf 1
|
|
@@ -699,19 +704,19 @@ module Punchblock
|
|
|
699
704
|
|
|
700
705
|
context "when a DTMF digit is received" do
|
|
701
706
|
it "sends the correct complete event" do
|
|
702
|
-
mock_call.should_receive :redirect_back
|
|
707
|
+
mock_call.async.should_receive :redirect_back
|
|
703
708
|
subject.execute
|
|
704
709
|
original_command.response(0.1).should be_a Ref
|
|
705
710
|
original_command.should_not be_complete
|
|
706
711
|
send_ami_events_for_dtmf 1
|
|
707
|
-
mock_call.process_ami_event
|
|
712
|
+
mock_call.async.process_ami_event ami_event
|
|
708
713
|
sleep 0.2
|
|
709
714
|
original_command.should be_complete
|
|
710
715
|
reason.should be_a Punchblock::Component::Output::Complete::Success
|
|
711
716
|
end
|
|
712
717
|
|
|
713
718
|
it "redirects the call back to async AGI" do
|
|
714
|
-
mock_call.should_receive(:redirect_back
|
|
719
|
+
mock_call.async.should_receive(:redirect_back).once
|
|
715
720
|
subject.execute
|
|
716
721
|
original_command.response(0.1).should be_a Ref
|
|
717
722
|
send_ami_events_for_dtmf 1
|
|
@@ -729,19 +734,19 @@ module Punchblock
|
|
|
729
734
|
|
|
730
735
|
context "when a DTMF digit is received" do
|
|
731
736
|
it "sends the correct complete event" do
|
|
732
|
-
mock_call.should_receive :redirect_back
|
|
737
|
+
mock_call.async.should_receive :redirect_back
|
|
733
738
|
subject.execute
|
|
734
739
|
original_command.response(0.1).should be_a Ref
|
|
735
740
|
original_command.should_not be_complete
|
|
736
741
|
send_ami_events_for_dtmf 1
|
|
737
|
-
mock_call.process_ami_event
|
|
742
|
+
mock_call.async.process_ami_event ami_event
|
|
738
743
|
sleep 0.2
|
|
739
744
|
original_command.should be_complete
|
|
740
745
|
reason.should be_a Punchblock::Component::Output::Complete::Success
|
|
741
746
|
end
|
|
742
747
|
|
|
743
748
|
it "redirects the call back to async AGI" do
|
|
744
|
-
mock_call.should_receive(:redirect_back
|
|
749
|
+
mock_call.async.should_receive(:redirect_back).once
|
|
745
750
|
subject.execute
|
|
746
751
|
original_command.response(0.1).should be_a Ref
|
|
747
752
|
send_ami_events_for_dtmf 1
|
|
@@ -782,7 +787,7 @@ module Punchblock
|
|
|
782
787
|
|
|
783
788
|
it "should use the media renderer set and not the platform default" do
|
|
784
789
|
expect_answered
|
|
785
|
-
mock_call.should_receive(:send_agi_action
|
|
790
|
+
mock_call.async.should_receive(:send_agi_action).once.with 'EXEC Playback', audio_filename
|
|
786
791
|
subject.execute
|
|
787
792
|
end
|
|
788
793
|
end
|
|
@@ -818,13 +823,13 @@ module Punchblock
|
|
|
818
823
|
end
|
|
819
824
|
|
|
820
825
|
it "sets the command response to true" do
|
|
821
|
-
mock_call.should_receive(:redirect_back
|
|
826
|
+
mock_call.async.should_receive(:redirect_back)
|
|
822
827
|
subject.execute_command command
|
|
823
828
|
command.response(0.1).should be == true
|
|
824
829
|
end
|
|
825
830
|
|
|
826
831
|
it "sends the correct complete event" do
|
|
827
|
-
mock_call.should_receive(:redirect_back
|
|
832
|
+
mock_call.async.should_receive(:redirect_back)
|
|
828
833
|
subject.execute_command command
|
|
829
834
|
original_command.should_not be_complete
|
|
830
835
|
mock_call.process_ami_event ami_event
|
|
@@ -833,7 +838,7 @@ module Punchblock
|
|
|
833
838
|
end
|
|
834
839
|
|
|
835
840
|
it "redirects the call by unjoining it" do
|
|
836
|
-
mock_call.should_receive(:redirect_back
|
|
841
|
+
mock_call.async.should_receive(:redirect_back)
|
|
837
842
|
subject.execute_command command
|
|
838
843
|
end
|
|
839
844
|
end
|
|
@@ -40,7 +40,7 @@ module Punchblock
|
|
|
40
40
|
before { mock_call.stub(:answered?).and_return(true) }
|
|
41
41
|
|
|
42
42
|
it "sets command response to a reference to the component" do
|
|
43
|
-
mock_call.should_receive(:send_ami_action
|
|
43
|
+
mock_call.async.should_receive(:send_ami_action)
|
|
44
44
|
subject.execute
|
|
45
45
|
original_command.response(0.1).should be_a Ref
|
|
46
46
|
original_command.component_id.should be == subject.id
|
|
@@ -48,13 +48,13 @@ module Punchblock
|
|
|
48
48
|
|
|
49
49
|
it "starts a recording via AMI, using the component ID as the filename" do
|
|
50
50
|
filename = "#{Record::RECORDING_BASE_PATH}/#{subject.id}"
|
|
51
|
-
mock_call.should_receive(:send_ami_action
|
|
51
|
+
mock_call.async.should_receive(:send_ami_action).once.with('Monitor', 'Channel' => channel, 'File' => filename, 'Format' => 'wav', 'Mix' => true)
|
|
52
52
|
subject.execute
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
it "sends a success complete event when the recording ends" do
|
|
56
56
|
full_filename = "file://#{Record::RECORDING_BASE_PATH}/#{subject.id}.wav"
|
|
57
|
-
mock_call.should_receive(:send_ami_action
|
|
57
|
+
mock_call.async.should_receive(:send_ami_action)
|
|
58
58
|
subject.execute
|
|
59
59
|
monitor_stop_event = RubyAMI::Event.new('MonitorStop').tap do |e|
|
|
60
60
|
e['Channel'] = channel
|
|
@@ -65,15 +65,15 @@ module Punchblock
|
|
|
65
65
|
original_command.should be_complete
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
it "can be called multiple times on the same call" do
|
|
69
|
-
mock_call.should_receive(:send_ami_action
|
|
68
|
+
it "can be called multiple times on the same call" do
|
|
69
|
+
mock_call.async.should_receive(:send_ami_action).twice
|
|
70
70
|
subject.execute
|
|
71
71
|
|
|
72
72
|
monitor_stop_event = RubyAMI::Event.new('MonitorStop').tap do |e|
|
|
73
73
|
e['Channel'] = channel
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
mock_call.process_ami_event monitor_stop_event
|
|
76
|
+
mock_call.process_ami_event monitor_stop_event
|
|
77
77
|
|
|
78
78
|
(Record.new original_command, mock_call).execute
|
|
79
79
|
(Punchblock::Component::Record.new command_options).request!
|
|
@@ -84,7 +84,7 @@ module Punchblock
|
|
|
84
84
|
context "set to nil" do
|
|
85
85
|
let(:command_options) { { :start_paused => nil } }
|
|
86
86
|
it "should execute normally" do
|
|
87
|
-
mock_call.should_receive(:send_ami_action
|
|
87
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
88
88
|
subject.execute
|
|
89
89
|
original_command.response(0.1).should be_a Ref
|
|
90
90
|
end
|
|
@@ -93,7 +93,7 @@ module Punchblock
|
|
|
93
93
|
context "set to false" do
|
|
94
94
|
let(:command_options) { { :start_paused => false } }
|
|
95
95
|
it "should execute normally" do
|
|
96
|
-
mock_call.should_receive(:send_ami_action
|
|
96
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
97
97
|
subject.execute
|
|
98
98
|
original_command.response(0.1).should be_a Ref
|
|
99
99
|
end
|
|
@@ -102,7 +102,7 @@ module Punchblock
|
|
|
102
102
|
context "set to true" do
|
|
103
103
|
let(:command_options) { { :start_paused => true } }
|
|
104
104
|
it "should return an error and not execute any actions" do
|
|
105
|
-
mock_call.should_receive(:send_agi_action
|
|
105
|
+
mock_call.async.should_receive(:send_agi_action).never
|
|
106
106
|
subject.execute
|
|
107
107
|
error = ProtocolError.new.setup 'option error', 'A start-paused value of true is unsupported.'
|
|
108
108
|
original_command.response(0.1).should be == error
|
|
@@ -114,7 +114,7 @@ module Punchblock
|
|
|
114
114
|
context "set to nil" do
|
|
115
115
|
let(:command_options) { { :initial_timeout => nil } }
|
|
116
116
|
it "should execute normally" do
|
|
117
|
-
mock_call.should_receive(:send_ami_action
|
|
117
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
118
118
|
subject.execute
|
|
119
119
|
original_command.response(0.1).should be_a Ref
|
|
120
120
|
end
|
|
@@ -123,7 +123,7 @@ module Punchblock
|
|
|
123
123
|
context "set to -1" do
|
|
124
124
|
let(:command_options) { { :initial_timeout => -1 } }
|
|
125
125
|
it "should execute normally" do
|
|
126
|
-
mock_call.should_receive(:send_ami_action
|
|
126
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
127
127
|
subject.execute
|
|
128
128
|
original_command.response(0.1).should be_a Ref
|
|
129
129
|
end
|
|
@@ -132,7 +132,7 @@ module Punchblock
|
|
|
132
132
|
context "set to a positive number" do
|
|
133
133
|
let(:command_options) { { :initial_timeout => 10 } }
|
|
134
134
|
it "should return an error and not execute any actions" do
|
|
135
|
-
mock_call.should_receive(:send_agi_action
|
|
135
|
+
mock_call.async.should_receive(:send_agi_action).never
|
|
136
136
|
subject.execute
|
|
137
137
|
error = ProtocolError.new.setup 'option error', 'An initial-timeout value is unsupported.'
|
|
138
138
|
original_command.response(0.1).should be == error
|
|
@@ -144,7 +144,7 @@ module Punchblock
|
|
|
144
144
|
context "set to nil" do
|
|
145
145
|
let(:command_options) { { :final_timeout => nil } }
|
|
146
146
|
it "should execute normally" do
|
|
147
|
-
mock_call.should_receive(:send_ami_action
|
|
147
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
148
148
|
subject.execute
|
|
149
149
|
original_command.response(0.1).should be_a Ref
|
|
150
150
|
end
|
|
@@ -153,7 +153,7 @@ module Punchblock
|
|
|
153
153
|
context "set to -1" do
|
|
154
154
|
let(:command_options) { { :final_timeout => -1 } }
|
|
155
155
|
it "should execute normally" do
|
|
156
|
-
mock_call.should_receive(:send_ami_action
|
|
156
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
157
157
|
subject.execute
|
|
158
158
|
original_command.response(0.1).should be_a Ref
|
|
159
159
|
end
|
|
@@ -162,7 +162,7 @@ module Punchblock
|
|
|
162
162
|
context "set to a positive number" do
|
|
163
163
|
let(:command_options) { { :final_timeout => 10 } }
|
|
164
164
|
it "should return an error and not execute any actions" do
|
|
165
|
-
mock_call.should_receive(:send_agi_action
|
|
165
|
+
mock_call.async.should_receive(:send_agi_action).never
|
|
166
166
|
subject.execute
|
|
167
167
|
error = ProtocolError.new.setup 'option error', 'A final-timeout value is unsupported.'
|
|
168
168
|
original_command.response(0.1).should be == error
|
|
@@ -174,13 +174,13 @@ module Punchblock
|
|
|
174
174
|
context "set to nil" do
|
|
175
175
|
let(:command_options) { { :format => nil } }
|
|
176
176
|
it "should execute as 'wav'" do
|
|
177
|
-
mock_call.should_receive(:send_ami_action
|
|
177
|
+
mock_call.async.should_receive(:send_ami_action).once.with('Monitor', hash_including('Format' => 'wav'))
|
|
178
178
|
subject.execute
|
|
179
179
|
original_command.response(0.1).should be_a Ref
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
it "provides the correct filename in the recording" do
|
|
183
|
-
mock_call.should_receive(:send_ami_action
|
|
183
|
+
mock_call.async.should_receive(:send_ami_action)
|
|
184
184
|
subject.execute
|
|
185
185
|
monitor_stop_event = RubyAMI::Event.new('MonitorStop').tap do |e|
|
|
186
186
|
e['Channel'] = channel
|
|
@@ -193,13 +193,13 @@ module Punchblock
|
|
|
193
193
|
context "set to 'mp3'" do
|
|
194
194
|
let(:command_options) { { :format => 'mp3' } }
|
|
195
195
|
it "should execute as 'mp3'" do
|
|
196
|
-
mock_call.should_receive(:send_ami_action
|
|
196
|
+
mock_call.async.should_receive(:send_ami_action).once.with('Monitor', hash_including('Format' => 'mp3'))
|
|
197
197
|
subject.execute
|
|
198
198
|
original_command.response(0.1).should be_a Ref
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
it "provides the correct filename in the recording" do
|
|
202
|
-
mock_call.should_receive(:send_ami_action
|
|
202
|
+
mock_call.async.should_receive(:send_ami_action)
|
|
203
203
|
subject.execute
|
|
204
204
|
monitor_stop_event = RubyAMI::Event.new('MonitorStop').tap do |e|
|
|
205
205
|
e['Channel'] = channel
|
|
@@ -214,8 +214,8 @@ module Punchblock
|
|
|
214
214
|
context "set to nil" do
|
|
215
215
|
let(:command_options) { { :start_beep => nil } }
|
|
216
216
|
it "should execute normally" do
|
|
217
|
-
mock_call.should_receive(:send_agi_action
|
|
218
|
-
mock_call.should_receive(:send_ami_action
|
|
217
|
+
mock_call.async.should_receive(:send_agi_action).never.with('STREAM FILE', 'beep', '""')
|
|
218
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
219
219
|
subject.execute
|
|
220
220
|
original_command.response(0.1).should be_a Ref
|
|
221
221
|
end
|
|
@@ -224,8 +224,8 @@ module Punchblock
|
|
|
224
224
|
context "set to false" do
|
|
225
225
|
let(:command_options) { { :start_beep => false } }
|
|
226
226
|
it "should execute normally" do
|
|
227
|
-
mock_call.should_receive(:send_agi_action
|
|
228
|
-
mock_call.should_receive(:send_ami_action
|
|
227
|
+
mock_call.async.should_receive(:send_agi_action).never.with('STREAM FILE', 'beep', '""')
|
|
228
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
229
229
|
subject.execute
|
|
230
230
|
original_command.response(0.1).should be_a Ref
|
|
231
231
|
end
|
|
@@ -236,17 +236,18 @@ module Punchblock
|
|
|
236
236
|
|
|
237
237
|
it "should play a beep before recording" do
|
|
238
238
|
subject.wrapped_object.should_receive(:wait).once
|
|
239
|
-
mock_call.should_receive(:send_agi_action
|
|
240
|
-
mock_call.should_receive(:send_ami_action
|
|
239
|
+
mock_call.async.should_receive(:send_agi_action).once.with('STREAM FILE', 'beep', '""').ordered
|
|
240
|
+
mock_call.async.should_receive(:send_ami_action).once.ordered
|
|
241
241
|
subject.execute
|
|
242
242
|
original_command.response(0.1).should be_a Ref
|
|
243
243
|
end
|
|
244
244
|
|
|
245
245
|
it "should wait for the beep to finish before starting recording" do
|
|
246
|
-
|
|
246
|
+
async_proxy = mock_call.async
|
|
247
|
+
def async_proxy.send_agi_action(*args)
|
|
247
248
|
yield
|
|
248
249
|
end
|
|
249
|
-
mock_call.should_receive(:send_ami_action
|
|
250
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
250
251
|
subject.execute
|
|
251
252
|
original_command.response(0.1).should be_a Ref
|
|
252
253
|
end
|
|
@@ -257,7 +258,7 @@ module Punchblock
|
|
|
257
258
|
context "set to nil" do
|
|
258
259
|
let(:command_options) { { :max_duration => nil } }
|
|
259
260
|
it "should execute normally" do
|
|
260
|
-
mock_call.should_receive(:send_ami_action
|
|
261
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
261
262
|
subject.execute
|
|
262
263
|
original_command.response(0.1).should be_a Ref
|
|
263
264
|
end
|
|
@@ -266,7 +267,7 @@ module Punchblock
|
|
|
266
267
|
context "set to -1" do
|
|
267
268
|
let(:command_options) { { :max_duration => -1 } }
|
|
268
269
|
it "should execute normally" do
|
|
269
|
-
mock_call.should_receive(:send_ami_action
|
|
270
|
+
mock_call.async.should_receive(:send_ami_action).once
|
|
270
271
|
subject.execute
|
|
271
272
|
original_command.response(0.1).should be_a Ref
|
|
272
273
|
end
|
|
@@ -288,14 +289,15 @@ module Punchblock
|
|
|
288
289
|
let(:command_options) { { :max_duration => 1000 } }
|
|
289
290
|
|
|
290
291
|
it "executes a StopMonitor action" do
|
|
291
|
-
mock_call.should_receive :send_ami_action
|
|
292
|
-
mock_call.should_receive(:send_ami_action
|
|
292
|
+
mock_call.async.should_receive :send_ami_action
|
|
293
|
+
mock_call.async.should_receive(:send_ami_action).once.with('StopMonitor', 'Channel' => channel)
|
|
293
294
|
subject.execute
|
|
294
295
|
sleep 1.2
|
|
295
296
|
end
|
|
296
297
|
|
|
297
298
|
it "sends the correct complete event" do
|
|
298
|
-
|
|
299
|
+
async_proxy = mock_call.async
|
|
300
|
+
def async_proxy.send_ami_action(*args, &block)
|
|
299
301
|
block.call Punchblock::Component::Asterisk::AMI::Action::Complete::Success.new if block
|
|
300
302
|
end
|
|
301
303
|
full_filename = "file://#{Record::RECORDING_BASE_PATH}/#{subject.id}.wav"
|
|
@@ -333,7 +335,7 @@ module Punchblock
|
|
|
333
335
|
let(:command) { Punchblock::Component::Stop.new }
|
|
334
336
|
|
|
335
337
|
before do
|
|
336
|
-
mock_call.should_receive :send_ami_action
|
|
338
|
+
mock_call.async.should_receive :send_ami_action
|
|
337
339
|
mock_call.should_receive(:answered?).and_return(true)
|
|
338
340
|
command.request!
|
|
339
341
|
original_command.request!
|
|
@@ -348,25 +350,25 @@ module Punchblock
|
|
|
348
350
|
end
|
|
349
351
|
|
|
350
352
|
it "sets the command response to true" do
|
|
351
|
-
mock_call.should_receive :send_ami_action
|
|
353
|
+
mock_call.async.should_receive :send_ami_action
|
|
352
354
|
subject.execute_command command
|
|
353
355
|
send_stop_event
|
|
354
356
|
command.response(0.1).should be == true
|
|
355
357
|
end
|
|
356
358
|
|
|
357
359
|
it "executes a StopMonitor action" do
|
|
358
|
-
mock_call.should_receive(:send_ami_action
|
|
360
|
+
mock_call.async.should_receive(:send_ami_action).once.with('StopMonitor', 'Channel' => channel)
|
|
359
361
|
subject.execute_command command
|
|
360
362
|
end
|
|
361
363
|
|
|
362
364
|
it "sends the correct complete event" do
|
|
363
|
-
mock_call.instance_exec do
|
|
365
|
+
mock_call.async.instance_exec do
|
|
364
366
|
class << self
|
|
365
|
-
undef :send_ami_action
|
|
367
|
+
undef :send_ami_action # This is here because mocha has already defined #send_ami_action above. We need to undef it to prevent a warning on redefinition.
|
|
366
368
|
end
|
|
367
369
|
|
|
368
|
-
def send_ami_action
|
|
369
|
-
block.call Punchblock::Component::Asterisk::AMI::Action::Complete::Success.new if block
|
|
370
|
+
def send_ami_action(*args, &block)
|
|
371
|
+
block.call ::Punchblock::Component::Asterisk::AMI::Action::Complete::Success.new if block
|
|
370
372
|
end
|
|
371
373
|
end
|
|
372
374
|
|
|
@@ -389,7 +391,8 @@ module Punchblock
|
|
|
389
391
|
end
|
|
390
392
|
|
|
391
393
|
it "sets the command response to true" do
|
|
392
|
-
|
|
394
|
+
async_proxy = mock_call.async
|
|
395
|
+
def async_proxy.send_ami_action(*args, &block)
|
|
393
396
|
block.call Punchblock::Component::Asterisk::AMI::Action::Complete::Success.new if block
|
|
394
397
|
end
|
|
395
398
|
subject.execute_command command
|
|
@@ -397,7 +400,7 @@ module Punchblock
|
|
|
397
400
|
end
|
|
398
401
|
|
|
399
402
|
it "pauses the recording via AMI" do
|
|
400
|
-
mock_call.should_receive(:send_ami_action
|
|
403
|
+
mock_call.async.should_receive(:send_ami_action).once.with('PauseMonitor', 'Channel' => channel)
|
|
401
404
|
subject.execute_command command
|
|
402
405
|
end
|
|
403
406
|
end
|
|
@@ -412,7 +415,8 @@ module Punchblock
|
|
|
412
415
|
end
|
|
413
416
|
|
|
414
417
|
it "sets the command response to true" do
|
|
415
|
-
|
|
418
|
+
async_proxy = mock_call.async
|
|
419
|
+
def async_proxy.send_ami_action(*args, &block)
|
|
416
420
|
block.call Punchblock::Component::Asterisk::AMI::Action::Complete::Success.new if block
|
|
417
421
|
end
|
|
418
422
|
subject.execute_command command
|
|
@@ -420,7 +424,7 @@ module Punchblock
|
|
|
420
424
|
end
|
|
421
425
|
|
|
422
426
|
it "resumes the recording via AMI" do
|
|
423
|
-
mock_call.should_receive(:send_ami_action
|
|
427
|
+
mock_call.async.should_receive(:send_ami_action).once.with('ResumeMonitor', 'Channel' => channel)
|
|
424
428
|
subject.execute_command command
|
|
425
429
|
end
|
|
426
430
|
end
|