Class: Quaff::Call
- Inherits:
-
Object
- Object
- Quaff::Call
- Defined in:
- lib/call.rb
Instance Attribute Summary collapse
-
#cid ⇒ Object
readonly
Returns the value of attribute cid.
Instance Method Summary collapse
- #change_cid(cid) ⇒ Object
- #clear_tag(str) ⇒ Object
- #clone_details(other_message) ⇒ Object
- #create_dialog(msg) ⇒ Object
- #end_call ⇒ Object
- #get_next_hop(header) ⇒ Object
-
#initialize(cxn, cid, uri = "sip:5557777888@#{Utils::local_ip}", destination = nil, target_uri = nil) ⇒ Call
constructor
A new instance of Call.
- #recv_request(method) ⇒ Object
- #recv_response(code) ⇒ Object
- #send_request(method, body = "", headers = {}) ⇒ Object
- #send_response(code, phrase, body = "", retrans = nil, headers = {}) ⇒ Object
- #set_callee(uri) ⇒ Object
- #setdest(source, options = {}) ⇒ Object
- #update_branch ⇒ Object
Constructor Details
#initialize(cxn, cid, uri = "sip:5557777888@#{Utils::local_ip}", destination = nil, target_uri = nil) ⇒ Call
Returns a new instance of Call.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/call.rb', line 28 def initialize(cxn, cid, uri="sip:5557777888@#{Utils::local_ip}", destination=nil, target_uri=nil) @cxn = cxn @cseq_number = 1 change_cid cid @uri = uri @retrans = nil @t1, @t2 = 0.5, 32 @last_From = "<#{uri}>" update_branch @last_To = "<#{target_uri}>" setdest(destination, recv_from_this: true) if destination set_callee target_uri if target_uri @routeset = [] end |
Instance Attribute Details
#cid ⇒ Object (readonly)
Returns the value of attribute cid.
26 27 28 |
# File 'lib/call.rb', line 26 def cid @cid end |
Instance Method Details
#change_cid(cid) ⇒ Object
47 48 49 50 |
# File 'lib/call.rb', line 47 def change_cid cid @cid = cid @cxn.add_call_id @cid end |
#clear_tag(str) ⇒ Object
121 122 123 |
# File 'lib/call.rb', line 121 def clear_tag str str end |
#clone_details(other_message) ⇒ Object
125 126 127 128 129 |
# File 'lib/call.rb', line 125 def clone_details @headers['To'] = [clear_tag(.header("To"))] @headers['From'] = [clear_tag(.header("From"))] @headers['Route'] = [.header("Route")] end |
#create_dialog(msg) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/call.rb', line 56 def create_dialog msg set_callee msg.first_header("Contact") @routeset = msg.all_headers("Record-Route") if msg.type == :request @routeset = @routeset.reverse end end |
#end_call ⇒ Object
116 117 118 |
# File 'lib/call.rb', line 116 def end_call @cxn.mark_call_dead @cid end |
#get_next_hop(header) ⇒ Object
131 132 133 134 135 |
# File 'lib/call.rb', line 131 def get_next_hop header /<sip:(.+@)?(.+):(\d+);(.*)>/ =~ header sock = TCPSocket.new $2, $3 return TCPSource.new sock end |
#recv_request(method) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/call.rb', line 79 def recv_request(method) begin data = recv_something rescue raise "#{ @uri } timed out waiting for #{ method }" end unless data["message"].type == :request \ and Regexp.new(method) =~ data["message"].method raise((data['message'].to_s || "Message is nil!")) end data end |
#recv_response(code) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/call.rb', line 92 def recv_response(code) begin data = recv_something rescue raise "#{ @uri } timed out waiting for #{ code }" end unless data["message"].type == :response \ and Regexp.new(code) =~ data["message"].status_code raise "Expected #{ code}, got #{data["message"].status_code || data['message']}" end data end |
#send_request(method, body = "", headers = {}) ⇒ Object
111 112 113 114 |
# File 'lib/call.rb', line 111 def send_request(method, body="", headers={}) msg = headers, body, :request, method send_something(msg, nil) end |
#send_response(code, phrase, body = "", retrans = nil, headers = {}) ⇒ Object
105 106 107 108 109 |
# File 'lib/call.rb', line 105 def send_response(code, phrase, body="", retrans=nil, headers={}) method = nil msg = headers, body, :response, method, code, phrase send_something(msg, retrans) end |
#set_callee(uri) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/call.rb', line 64 def set_callee uri if /<(.*)>/ =~ uri uri = $1 end @sip_destination = "#{uri}" end |
#setdest(source, options = {}) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/call.rb', line 72 def setdest source, ={} @src = source if [:recv_from_this] and source.sock @cxn.add_sock source.sock end end |
#update_branch ⇒ Object
52 53 54 |
# File 'lib/call.rb', line 52 def update_branch @last_Via = "SIP/2.0/#{@cxn.transport} #{Quaff::Utils.local_ip}:#{@cxn.local_port};rport;branch=#{Quaff::Utils::new_branch}" end |