Skip to content

Instantly share code, notes, and snippets.

@mtelis
Created July 18, 2010 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtelis/480161 to your computer and use it in GitHub Desktop.
Save mtelis/480161 to your computer and use it in GitHub Desktop.
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
@mtelis
Copy link
Author

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"

@mtelis
Copy link
Author

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