Re: sys.CallsInProgress
Posted: Fri Jul 16, 2010 8:19 am
Here is a little chunk of code you may find useful:
Looping thru sys.GetCurrentCalls maybe costly, CPU-time wise. The countCalls method takes a hash containing name => VSP_URI pairs and returns a new hash containing the same name => counter pairs where counter is the number of calls connected thru this VSP. Then you can use the hash to retrieve the number of calls for individual trunks, for example:
You can also use this format:
Code: Select all
# ************************** C O U N T C A L L S ************************
def countCalls acnts
rexp = acnts.values.map {|x| /<sip\:#{Regexp.escape(x)}>/i}
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}
end
Hash[*acnts.keys.zip(counter).flatten]
end
Code: Select all
My_trunks = {
:PCTel => 'name@sip.pctel.ru',
:F9 => 'xxxxx@sip.future-nine.com',
}
calls = countCalls(My_trunks)
if calls[:PCTel] != 0
# ... PCTel account is busy
Code: Select all
calls = countCalls :PCTel => 'name@sip.pctel.ru',
:F9 => 'xxxxx@sip.future-nine.com'