Class: Adhearsion::Calls

Inherits:
Object show all
Defined in:
lib/adhearsion/voip/call.rb

Overview

This manages the list of calls the Adhearsion service receives

Instance Method Summary collapse

Constructor Details

#initializeCalls

Returns a new instance of Calls.



27
28
29
30
# File 'lib/adhearsion/voip/call.rb', line 27

def initialize
  @semaphore = Monitor.new
  @calls     = {}
end

Instance Method Details

#<<(call) ⇒ Object



32
33
34
35
36
# File 'lib/adhearsion/voip/call.rb', line 32

def <<(call)
  atomically do
    calls[call.unique_identifier] = call
  end
end

#any?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/adhearsion/voip/call.rb', line 38

def any?
  atomically do
    !calls.empty?
  end
end

#clear!Object



64
65
66
67
68
# File 'lib/adhearsion/voip/call.rb', line 64

def clear!
  atomically do
    calls.clear
  end
end

#find(id) ⇒ Object

Searches all active calls by their unique_identifier. See Call#unique_identifier. Is this actually by channel?



58
59
60
61
62
# File 'lib/adhearsion/voip/call.rb', line 58

def find(id)
  atomically do
    return calls[id]
  end
end

#remove_inactive_call(call) ⇒ Object



50
51
52
53
54
# File 'lib/adhearsion/voip/call.rb', line 50

def remove_inactive_call(call)
  atomically do
    calls.delete call.unique_identifier
  end
end

#sizeObject



44
45
46
47
48
# File 'lib/adhearsion/voip/call.rb', line 44

def size
  atomically do
    calls.size
  end
end

#to_aObject



78
79
80
# File 'lib/adhearsion/voip/call.rb', line 78

def to_a
  calls.values
end

#with_tag(tag) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/adhearsion/voip/call.rb', line 70

def with_tag(tag)
  atomically do
    calls.inject(Array.new) do |calls_with_tag,(key,call)|
      call.tagged_with?(tag) ? calls_with_tag << call : calls_with_tag
    end
  end
end