Class: Quaff::BaseEndpoint
- Inherits:
-
Object
- Object
- Quaff::BaseEndpoint
show all
- Defined in:
- lib/endpoint.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(uri, username, password, local_port, outbound_proxy = nil, outbound_port = 5060) ⇒ BaseEndpoint
Returns a new instance of BaseEndpoint.
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/endpoint.rb', line 36
def initialize(uri, username, password, local_port, outbound_proxy=nil, outbound_port=5060)
@uri = uri
@resolver = Resolv::DNS.new
@username = username
@password = password
@lport = local_port
initialize_connection @lport
if outbound_proxy
@outbound_connection = new_connection(outbound_proxy, outbound_port)
end
initialize_queues
start
end
|
Instance Attribute Details
#msg_trace ⇒ Object
Returns the value of attribute msg_trace.
12
13
14
|
# File 'lib/endpoint.rb', line 12
def msg_trace
@msg_trace
end
|
#uri ⇒ Object
Returns the value of attribute uri.
12
13
14
|
# File 'lib/endpoint.rb', line 12
def uri
@uri
end
|
Instance Method Details
#add_call_id(cid) ⇒ Object
54
55
56
|
# File 'lib/endpoint.rb', line 54
def add_call_id cid
@messages[cid] ||= Queue.new
end
|
#add_sock(sock) ⇒ Object
21
22
|
# File 'lib/endpoint.rb', line 21
def add_sock sock
end
|
#generate_call_id ⇒ Object
14
15
16
|
# File 'lib/endpoint.rb', line 14
def generate_call_id
digest = Digest::MD5.hexdigest(rand(60000).to_s)
end
|
#get_new_call_id(time_limit = 30) ⇒ Object
58
59
60
|
# File 'lib/endpoint.rb', line 58
def get_new_call_id time_limit=30
Timeout::timeout(time_limit) { @call_ids.deq }
end
|
#get_new_message(cid, time_limit = 30) ⇒ Object
62
63
64
|
# File 'lib/endpoint.rb', line 62
def get_new_message(cid, time_limit=30)
Timeout::timeout(time_limit) { @messages[cid].deq }
end
|
#incoming_call(*args) ⇒ Object
24
25
26
27
28
|
# File 'lib/endpoint.rb', line 24
def incoming_call *args
call_id ||= get_new_call_id
puts "Call-Id for endpoint on #{@lport} is #{call_id}" if @msg_trace
Call.new(self, call_id, *args)
end
|
#local_port ⇒ Object
50
51
52
|
# File 'lib/endpoint.rb', line 50
def local_port
@lport
end
|
#mark_call_dead(cid) ⇒ Object
66
67
68
69
70
71
|
# File 'lib/endpoint.rb', line 66
def mark_call_dead(cid)
@messages.delete cid
now = Time.now
@dead_calls[cid] = now + 30
@dead_calls = @dead_calls.keep_if {|k, v| v > now}
end
|
#outgoing_call(to_uri) ⇒ Object
30
31
32
33
34
|
# File 'lib/endpoint.rb', line 30
def outgoing_call to_uri
call_id = generate_call_id
puts "Call-Id for endpoint on #{@lport} is #{call_id}" if @msg_trace
Call.new(self, call_id, @uri, @outbound_connection, to_uri)
end
|
#register(expires = "3600") ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/endpoint.rb', line 78
def register expires="3600"
call = outgoing_call(@uri)
call.send_request("REGISTER", "", { "Expires" => expires.to_s })
response_data = call.recv_response("401|200")
if response_data['message'].status_code == "401"
call.send_request("ACK")
auth_hdr = Quaff::Auth. response_data['message'].("WWW-Authenticate"), @username, @password, "REGISTER", @uri
call.update_branch
call.send_request("REGISTER", "", {"Authorization" => auth_hdr, "Expires" => expires.to_s, "CSeq" => "2 REGISTER"})
call.recv_response("200")
end
return true
end
|
#send_msg(data, source) ⇒ Object
73
74
75
76
|
# File 'lib/endpoint.rb', line 73
def send_msg(data, source)
puts "Endpoint on #{@lport} sending #{data} to #{source.inspect}" if @msg_trace
source.send_msg(@cxn, data)
end
|
#terminate ⇒ Object
18
19
|
# File 'lib/endpoint.rb', line 18
def terminate
end
|
#unregister ⇒ Object
92
93
94
|
# File 'lib/endpoint.rb', line 92
def unregister
register 0
end
|