Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Calls in progress counter
# ************************** C O U N T C A L L S ************************
def countCalls acnts, tmo=20
rexp = acnts.values.map {|x| /<sip\:#{Regexp.escape(x)}>/i}
now = Time.now.getutc
counter = Array.new(rexp.length,0)
sys.GetCurrentCalls.each do |call|
user = call.LocalUserField
rexp.each_with_index {|r,i| counter[i] += 1 if user =~ r and (now - call.Inserted.DateTime.ToLocalTime).to_i < (tmo * 60) }
end
Hash[*acnts.keys.zip(counter).flatten]
end
Owner

mtelis commented Jul 18, 2010

calls = countCalls :myVSP1 => 'name@sip.future-nine.com', :myVSP2 => 'name1@pbxes.com'

puts "There are #{calls[:myVSP1]} calls in progress via myVSP1"

Owner

mtelis commented Jul 27, 2010

Fixed a problem with orphaned calls. If Sipsorcery have not received the BYE due to network problem, the call will remain in the list upto 24 hours. So, I added time-out parameter and will ignore calls that have been inserted more than time-out minutes ago (by default, 20 minutes). Note that Inserted() returns System::DateTimeOffset object and you need to manipulate it with C# methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment