Skip to content

Commit

Permalink
[FEATURE] Allow passing :join_options parameter to #dial to speci…
Browse files Browse the repository at this point in the history
…fy the kind of join to perform.
  • Loading branch information
benlangfeld committed Dec 18, 2013
1 parent 33b80c1 commit 9dba15a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
* Bugfix: Ensure that `Call#peers` are correctly maintained - this was broken by Rayo moving to full call URIs in joined/unjoined events
* Feature: Add `--empty` switch to app generator for power users. Generates an app with less fluff.
* Feature: Default generated applications with config appropriate for [Telephony Dev Box](http://github.com/mojolingo/Telephony-Dev-Box)
* Feature: Allow passing `:join_options` parameter to `#dial` to specify the kind of join to perform.

# [2.4.0](https://github.com/adhearsion/adhearsion/compare/v2.3.5...v2.4.0) - [2013-08-29](https://rubygems.org/gems/adhearsion/versions/2.4.0)
* Deprecation: Ruby 1.9.2 support is deprecated and will be dropped in a future version of Adhearsion
Expand Down
9 changes: 8 additions & 1 deletion lib/adhearsion/call_controller/dial.rb
Expand Up @@ -35,6 +35,7 @@ module Dial
#
# @option options [CallController] :confirm the controller to execute on the first outbound call to be answered, to give an opportunity to screen the call. The calls will be joined if the outbound call is still active after this controller completes.
# @option options [Hash] :confirm_metadata Metadata to set on the confirmation controller before executing it. This is shared between all calls if dialing multiple endpoints; if you care about it being mutated, you should provide an immutable value (using eg https://github.com/harukizaemon/hamster).
# @option options [Hash] :join_options Options to specify the kind of join operation to perform. See `Call#join` for details.
#
# @example Make a call to the PSTN using my SIP provider for VoIP termination
# dial "SIP/19095551001@my.sip.voip.terminator.us"
Expand Down Expand Up @@ -146,7 +147,11 @@ def prep_calls
pre_join_tasks new_call
@call.answer
join_status.started
new_call.join @call
if @join_options
new_call.join @call, @join_options
else
new_call.join @call
end
status.answer!
elsif status.result == :answer
join_status.lost_confirmation!
Expand Down Expand Up @@ -313,6 +318,8 @@ def set_defaults
@confirmation_controller = @options.delete :confirm
@confirmation_metadata = @options.delete :confirm_metadata

@join_options = @options.delete :join_options

@skip_cleanup = false
end

Expand Down
46 changes: 46 additions & 0 deletions spec/adhearsion/call_controller/dial_spec.rb
Expand Up @@ -208,6 +208,29 @@ def dial_in_thread
joined_status = status.joins[status.calls.first]
joined_status.duration.should == 37.0
end

context "when join options are specified" do
let(:options) { { join_options: {media: :direct} } }

it "joins the calls with those options" do
call.should_receive(:answer).once
other_mock_call.should_receive(:join).once.with(call, media: :direct)
other_mock_call.stub hangup: true

t = dial_in_thread

sleep 0.5

other_mock_call << mock_answered

other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
other_mock_call << mock_end

latch.wait(1).should be_true

t.join
end
end
end

context "when a dial is split" do
Expand Down Expand Up @@ -1398,6 +1421,29 @@ def dial_in_thread
joined_status = status.joins[status.calls.first]
joined_status.duration.should == 37.0
end

context "when join options are specified" do
let(:options) { { join_options: {media: :direct} } }

it "joins the calls with those options" do
call.should_receive(:answer).once
other_mock_call.should_receive(:join).once.with(call, media: :direct)
other_mock_call.stub hangup: true

t = dial_in_thread

sleep 0.5

other_mock_call << mock_answered

other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
other_mock_call << mock_end

latch.wait(1).should be_true

t.join
end
end
end

context "when a dial is split" do
Expand Down

0 comments on commit 9dba15a

Please sign in to comment.