Created
July 18, 2010 05:29
-
-
Save mtelis/480161 to your computer and use it in GitHub Desktop.
Calls in progress counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ************************** 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 |
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
calls = countCalls :myVSP1 => 'name@sip.future-nine.com', :myVSP2 => 'name1@pbxes.com'
puts "There are #{calls[:myVSP1]} calls in progress via myVSP1"