Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[FEATURE] Track peer calls when joining

  • Loading branch information...
commit 31955588dc900729cc9eda39cb8e4d0e8cf60e4f 1 parent 0700aba
@benlangfeld benlangfeld authored
View
1  CHANGELOG.md
@@ -1,4 +1,5 @@
# [develop](https://github.com/adhearsion/adhearsion)
+ * Feature: Track peer calls when joining
# [2.1.3](https://github.com/adhearsion/adhearsion/compare/v2.1.2...v2.1.3) - [2012-10-11](https://rubygems.org/gems/adhearsion/versions/2.1.3)
* Bugfix: Originating call is now answered before joining calls using `CallController#dial`
View
11 lib/adhearsion/call.rb
@@ -39,6 +39,7 @@ def initialize(offer = nil)
@variables = {}
@controllers = []
@end_reason = nil
+ @peers = {}
self << offer if offer
end
@@ -85,6 +86,14 @@ def tagged_with?(label)
@tags.include? label
end
+ #
+ # Hash of joined peers
+ # @return [Hash<String => Adhearsion::Call>]
+ #
+ def peers
+ @peers.clone
+ end
+
def register_event_handler(*guards, &block)
register_handler :event, *guards, &block
end
@@ -110,11 +119,13 @@ def register_initial_handlers
on_joined do |event|
target = event.call_id || event.mixer_name
+ @peers[target] = Adhearsion.active_calls[target]
signal :joined, target
end
on_unjoined do |event|
target = event.call_id || event.mixer_name
+ @peers.delete target
signal :unjoined, target
end
View
43 spec/adhearsion/call_spec.rb
@@ -271,6 +271,49 @@ module Adhearsion
end
end
+ context "peer registry" do
+ let(:other_call_id) { 'foobar' }
+ let(:other_call) { flexmock Call.new, :id => other_call_id }
+
+ let :joined_event do
+ Punchblock::Event::Joined.new :call_id => other_call_id
+ end
+
+ let :unjoined_event do
+ Punchblock::Event::Unjoined.new :call_id => other_call_id
+ end
+
+ context "when we know about the joined call" do
+ before { Adhearsion.active_calls << other_call }
+
+ it "should add the peer to its registry" do
+ subject << joined_event
+ subject.peers.should == {'foobar' => other_call}
+ end
+ end
+
+ context "when we don't know about the joined call" do
+ it "should add a nil entry to its registry" do
+ subject << joined_event
+ subject.peers.should == {'foobar' => nil}
+ end
+ end
+
+ it "should not return the same registry every call" do
+ subject.peers.should_not be subject.peers
+ end
+
+ context "when being unjoined from a previously joined call" do
+ before { subject << joined_event }
+
+ it "should remove the peer from its registry" do
+ subject.peers.should_not == {}
+ subject << unjoined_event
+ subject.peers.should == {}
+ end
+ end
+ end
+
describe "#<<" do
describe "with a Punchblock End" do
let :end_event do
Please sign in to comment.
Something went wrong with that request. Please try again.