adhearsion 2.5.0 → 2.5.2
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 +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +15 -0
- data/adhearsion.gemspec +2 -2
- data/lib/adhearsion.rb +2 -3
- data/lib/adhearsion/call.rb +8 -4
- data/lib/adhearsion/call_controller/dial.rb +4 -4
- data/lib/adhearsion/call_controller/record.rb +2 -2
- data/lib/adhearsion/calls.rb +44 -17
- data/lib/adhearsion/generators/app/templates/Gemfile.erb +4 -3
- data/lib/adhearsion/generators/app/templates/README.md +3 -2
- data/lib/adhearsion/generators/app/templates/routes.erb +6 -7
- data/lib/adhearsion/generators/app/templates/simon_game_spec.rb +1 -0
- data/lib/adhearsion/initializer.rb +11 -2
- data/lib/adhearsion/logging.rb +8 -5
- data/lib/adhearsion/outbound_call.rb +37 -7
- data/lib/adhearsion/plugin.rb +24 -6
- data/lib/adhearsion/punchblock_plugin/initializer.rb +2 -1
- data/lib/adhearsion/router/route.rb +2 -2
- data/lib/adhearsion/rspec.rb +3 -0
- data/lib/adhearsion/tasks.rb +10 -0
- data/lib/adhearsion/tasks/environment.rb +1 -0
- data/lib/adhearsion/version.rb +1 -1
- data/spec/adhearsion/call_controller/dial_spec.rb +114 -114
- data/spec/adhearsion/call_spec.rb +12 -10
- data/spec/adhearsion/calls_spec.rb +2 -0
- data/spec/adhearsion/outbound_call_spec.rb +86 -17
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +13 -1
- data/spec/adhearsion_spec.rb +0 -12
- data/spec/spec_helper.rb +1 -0
- metadata +7 -7
@@ -18,13 +18,15 @@ module Adhearsion
|
|
18
18
|
let(:to) { 'sip:you@there.com' }
|
19
19
|
let(:from) { 'sip:me@here.com' }
|
20
20
|
let(:transport) { 'footransport' }
|
21
|
+
let(:base_time) { Time.local(2008, 9, 1, 12, 0, 0) }
|
21
22
|
let :offer do
|
22
23
|
Punchblock::Event::Offer.new target_call_id: call_id,
|
23
24
|
domain: domain,
|
24
25
|
transport: transport,
|
25
26
|
to: to,
|
26
27
|
from: from,
|
27
|
-
headers: headers
|
28
|
+
headers: headers,
|
29
|
+
timestamp: base_time
|
28
30
|
end
|
29
31
|
|
30
32
|
subject { Adhearsion::Call.new offer }
|
@@ -85,8 +87,6 @@ module Adhearsion
|
|
85
87
|
end
|
86
88
|
|
87
89
|
it "should mark its start time" do
|
88
|
-
base_time = Time.local(2008, 9, 1, 12, 0, 0)
|
89
|
-
Timecop.freeze base_time
|
90
90
|
subject.start_time.should == base_time
|
91
91
|
end
|
92
92
|
|
@@ -650,12 +650,12 @@ module Adhearsion
|
|
650
650
|
end
|
651
651
|
|
652
652
|
describe "#write_command" do
|
653
|
-
let(:
|
653
|
+
let(:command) { Punchblock::Command::Answer.new }
|
654
654
|
|
655
|
-
it "should
|
655
|
+
it "should write the command to the Punchblock connection" do
|
656
656
|
subject.wrapped_object.should_receive(:client).once.and_return mock_client
|
657
|
-
mock_client.should_receive(:execute_command).once.with(
|
658
|
-
subject.write_command
|
657
|
+
mock_client.should_receive(:execute_command).once.with(Punchblock::Command::Answer.new(target_call_id: call_id, domain: domain)).and_return true
|
658
|
+
subject.write_command command
|
659
659
|
end
|
660
660
|
|
661
661
|
describe "with a hungup call" do
|
@@ -664,14 +664,14 @@ module Adhearsion
|
|
664
664
|
end
|
665
665
|
|
666
666
|
it "should raise a Hangup exception" do
|
667
|
-
lambda { subject.write_command
|
667
|
+
lambda { subject.write_command command }.should raise_error(Call::Hangup)
|
668
668
|
end
|
669
669
|
|
670
670
|
describe "if the command is a Hangup" do
|
671
|
-
let(:
|
671
|
+
let(:command) { Punchblock::Command::Hangup.new }
|
672
672
|
|
673
673
|
it "should not raise a Hangup exception" do
|
674
|
-
lambda { subject.write_command
|
674
|
+
lambda { subject.write_command command }.should_not raise_error
|
675
675
|
end
|
676
676
|
end
|
677
677
|
end
|
@@ -755,6 +755,8 @@ module Adhearsion
|
|
755
755
|
|
756
756
|
describe "when the response times out" do
|
757
757
|
before do
|
758
|
+
message.target_call_id = call_id
|
759
|
+
message.domain = domain
|
758
760
|
message.should_receive(:response).and_raise Timeout::Error
|
759
761
|
end
|
760
762
|
|
@@ -9,15 +9,23 @@ module Adhearsion
|
|
9
9
|
its(:id) { should be_nil }
|
10
10
|
its(:variables) { should be == {} }
|
11
11
|
|
12
|
-
let(:mock_client) { double 'Punchblock Client' }
|
12
|
+
let(:mock_client) { double 'Punchblock Client', execute_command: true, new_call_uri: call_uri }
|
13
13
|
|
14
14
|
before do
|
15
15
|
PunchblockPlugin::Initializer.client = mock_client
|
16
|
+
Adhearsion.active_calls.clear
|
16
17
|
end
|
17
18
|
|
18
19
|
its(:client) { should be mock_client }
|
19
20
|
its(:start_time) { should be nil }
|
20
21
|
|
22
|
+
let(:transport) { 'xmpp' }
|
23
|
+
let(:call_id) { SecureRandom.uuid }
|
24
|
+
let(:domain) { 'rayo.net' }
|
25
|
+
let(:call_uri) { "xmpp:#{call_id}@rayo.net" }
|
26
|
+
let(:to) { '+1800 555-0199' }
|
27
|
+
let(:from) { '+1800 555-0122' }
|
28
|
+
|
21
29
|
it "should allow timers to be registered from outside" do
|
22
30
|
foo = :bar
|
23
31
|
subject.after(1) { foo = :baz }
|
@@ -98,6 +106,10 @@ module Adhearsion
|
|
98
106
|
Punchblock::Command::Dial.any_instance.should_receive(:response).and_return StandardError.new("User not registered")
|
99
107
|
end
|
100
108
|
|
109
|
+
after do
|
110
|
+
Adhearsion.active_calls.restart_supervisor
|
111
|
+
end
|
112
|
+
|
101
113
|
it "should raise the exception in the caller" do
|
102
114
|
expect { subject.dial to }.to raise_error("User not registered")
|
103
115
|
end
|
@@ -144,26 +156,49 @@ module Adhearsion
|
|
144
156
|
end
|
145
157
|
|
146
158
|
describe "#dial" do
|
147
|
-
def expect_message_waiting_for_response(message)
|
148
|
-
subject.wrapped_object.should_receive(:write_and_await_response).once.with(message, 60, true).and_return do
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
message
|
159
|
+
def expect_message_waiting_for_response(message, uri = call_uri)
|
160
|
+
subject.wrapped_object.should_receive(:write_and_await_response).once.with(message, 60, true).and_return do |real_message|
|
161
|
+
real_message.request!
|
162
|
+
real_message.response = Punchblock::Ref.new(uri: uri)
|
163
|
+
real_message
|
153
164
|
end
|
154
165
|
end
|
155
166
|
|
156
|
-
let(:
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
167
|
+
let(:expected_dial_command) { Punchblock::Command::Dial.new(:to => to, :from => from, :uri => call_uri) }
|
168
|
+
|
169
|
+
context "while waiting for a response" do
|
170
|
+
before do
|
171
|
+
mock_client.should_receive(:execute_command).once.with(expected_dial_command).and_return true
|
172
|
+
subject.async.dial to, from: from
|
173
|
+
sleep 1
|
174
|
+
end
|
161
175
|
|
162
|
-
|
176
|
+
it "should set the dial command" do
|
177
|
+
subject.dial_command.should be == expected_dial_command
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should know its requested URI" do
|
181
|
+
subject.uri.should be == call_uri
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should know its requested ID" do
|
185
|
+
subject.id.should be == call_id
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should know its domain" do
|
189
|
+
subject.domain.should be == domain
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should be entered in the active calls registry" do
|
193
|
+
Adhearsion.active_calls[call_id].should be subject
|
194
|
+
end
|
195
|
+
end
|
163
196
|
|
164
197
|
context "with a successful response" do
|
198
|
+
let(:returned_uri) { call_uri }
|
199
|
+
|
165
200
|
before do
|
166
|
-
expect_message_waiting_for_response expected_dial_command
|
201
|
+
expect_message_waiting_for_response expected_dial_command, returned_uri
|
167
202
|
end
|
168
203
|
|
169
204
|
it "should send a dial stanza, wait for the response" do
|
@@ -172,12 +207,12 @@ module Adhearsion
|
|
172
207
|
|
173
208
|
it "should set the dial command" do
|
174
209
|
subject.dial to, :from => from
|
175
|
-
subject.dial_command.should be ==
|
210
|
+
subject.dial_command.should be == Punchblock::Command::Dial.new(:to => to, :from => from, :uri => call_uri, target_call_id: call_id, domain: domain, transport: transport)
|
176
211
|
end
|
177
212
|
|
178
213
|
it "should set the URI from the reference" do
|
179
214
|
subject.dial to, :from => from
|
180
|
-
subject.uri.should be ==
|
215
|
+
subject.uri.should be == call_uri
|
181
216
|
end
|
182
217
|
|
183
218
|
it "should set the call ID from the reference" do
|
@@ -201,11 +236,35 @@ module Adhearsion
|
|
201
236
|
end
|
202
237
|
|
203
238
|
it "should add the call to the active calls registry" do
|
204
|
-
Adhearsion.active_calls.clear
|
205
239
|
subject.dial to, :from => from
|
206
240
|
Adhearsion.active_calls[call_id].should be subject
|
207
241
|
end
|
208
242
|
|
243
|
+
context "when a different ref is returned than the one expected" do
|
244
|
+
let(:returned_uri) { 'xmpp:otherid@wonderland.lit' }
|
245
|
+
|
246
|
+
before do
|
247
|
+
subject.dial to, :from => from
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should set the URI from the reference" do
|
251
|
+
subject.uri.should be == returned_uri
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should set the call ID from the reference" do
|
255
|
+
subject.id.should be == 'otherid'
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should set the call domain from the reference" do
|
259
|
+
subject.domain.should be == 'wonderland.lit'
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should make the call addressible in the active calls registry by the new ID" do
|
263
|
+
Adhearsion.active_calls[call_id].should be_nil
|
264
|
+
Adhearsion.active_calls['otherid'].should be subject
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
209
268
|
it "should immediately fire the :call_dialed event giving the call" do
|
210
269
|
Adhearsion::Events.should_receive(:trigger_immediately).once.with(:call_dialed, subject)
|
211
270
|
subject.dial to, :from => from
|
@@ -226,6 +285,10 @@ module Adhearsion
|
|
226
285
|
Punchblock::Command::Dial.any_instance.should_receive(:response).and_return StandardError.new("User not registered")
|
227
286
|
end
|
228
287
|
|
288
|
+
after do
|
289
|
+
Adhearsion.active_calls.restart_supervisor
|
290
|
+
end
|
291
|
+
|
229
292
|
it "should raise the exception in the caller" do
|
230
293
|
expect { subject.dial to }.to raise_error("User not registered")
|
231
294
|
end
|
@@ -235,6 +298,12 @@ module Adhearsion
|
|
235
298
|
sleep 0.1
|
236
299
|
subject.should_not be_alive
|
237
300
|
end
|
301
|
+
|
302
|
+
it "should remove the call from the active calls hash" do
|
303
|
+
expect { subject.dial to }.to raise_error("User not registered")
|
304
|
+
sleep 0.1
|
305
|
+
Adhearsion.active_calls[call_id].should be_nil
|
306
|
+
end
|
238
307
|
end
|
239
308
|
end
|
240
309
|
|
@@ -276,7 +276,19 @@ module Adhearsion
|
|
276
276
|
end
|
277
277
|
|
278
278
|
describe "with an inactive call" do
|
279
|
-
it "should log
|
279
|
+
it "should log a warning" do
|
280
|
+
Adhearsion::Logging.get_logger(Initializer).should_receive(:warn).once.with("Event received for inactive call #{call_id}: #{mock_event.inspect}")
|
281
|
+
Initializer.dispatch_call_event mock_event
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe "when the registry contains a dead call" do
|
286
|
+
before do
|
287
|
+
mock_call.terminate
|
288
|
+
Adhearsion.active_calls[mock_call.id] = mock_call
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should log a warning" do
|
280
292
|
Adhearsion::Logging.get_logger(Initializer).should_receive(:warn).once.with("Event received for inactive call #{call_id}: #{mock_event.inspect}")
|
281
293
|
Initializer.dispatch_call_event mock_event
|
282
294
|
end
|
data/spec/adhearsion_spec.rb
CHANGED
@@ -80,18 +80,6 @@ describe Adhearsion do
|
|
80
80
|
it "should return the same instance each time" do
|
81
81
|
Adhearsion.active_calls.should be Adhearsion.active_calls
|
82
82
|
end
|
83
|
-
|
84
|
-
it "should create a new collection if the existing one dies" do
|
85
|
-
original = Adhearsion.active_calls
|
86
|
-
original.terminate
|
87
|
-
original.should_not be_alive
|
88
|
-
|
89
|
-
sleep 0.25
|
90
|
-
|
91
|
-
current = Adhearsion.active_calls
|
92
|
-
current.should be_alive
|
93
|
-
current.should_not be original
|
94
|
-
end
|
95
83
|
end
|
96
84
|
|
97
85
|
describe "#statistics" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adhearsion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Phillips
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-
|
14
|
+
date: 2014-04-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -179,14 +179,14 @@ dependencies:
|
|
179
179
|
requirements:
|
180
180
|
- - "~>"
|
181
181
|
- !ruby/object:Gem::Version
|
182
|
-
version: '2.
|
182
|
+
version: '2.4'
|
183
183
|
type: :runtime
|
184
184
|
prerelease: false
|
185
185
|
version_requirements: !ruby/object:Gem::Requirement
|
186
186
|
requirements:
|
187
187
|
- - "~>"
|
188
188
|
- !ruby/object:Gem::Version
|
189
|
-
version: '2.
|
189
|
+
version: '2.4'
|
190
190
|
- !ruby/object:Gem::Dependency
|
191
191
|
name: rake
|
192
192
|
requirement: !ruby/object:Gem::Requirement
|
@@ -305,14 +305,14 @@ dependencies:
|
|
305
305
|
requirements:
|
306
306
|
- - "~>"
|
307
307
|
- !ruby/object:Gem::Version
|
308
|
-
version: '2.
|
308
|
+
version: '2.13'
|
309
309
|
type: :development
|
310
310
|
prerelease: false
|
311
311
|
version_requirements: !ruby/object:Gem::Requirement
|
312
312
|
requirements:
|
313
313
|
- - "~>"
|
314
314
|
- !ruby/object:Gem::Version
|
315
|
-
version: '2.
|
315
|
+
version: '2.13'
|
316
316
|
- !ruby/object:Gem::Dependency
|
317
317
|
name: simplecov
|
318
318
|
requirement: !ruby/object:Gem::Requirement
|
@@ -592,7 +592,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
592
592
|
version: '0'
|
593
593
|
requirements: []
|
594
594
|
rubyforge_project:
|
595
|
-
rubygems_version: 2.2.
|
595
|
+
rubygems_version: 2.2.2
|
596
596
|
signing_key:
|
597
597
|
specification_version: 4
|
598
598
|
summary: Adhearsion, open-source telephony development framework
|