Page 2 of 2

Re: sys.CallsInProgress

Posted: Fri Jul 16, 2010 8:19 am
by MikeTelis
Here is a little chunk of code you may find useful:

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
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:

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
You can also use this format:

Code: Select all

calls = countCalls  :PCTel => 'name@sip.pctel.ru',
                    :F9 => 'xxxxx@sip.future-nine.com'

Re: sys.CallsInProgress

Posted: Tue Jul 27, 2010 7:39 pm
by MikeTelis
Updated the code published in my previous post, latest version is available on github.

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.

Re: sys.CallsInProgress

Posted: Mon Oct 03, 2016 3:52 am
by Flip
URL Not Valid
We’re sorry, but the query string of the URL is not valid. If you continue to experience issues or would like to send us more information about this error, please contact us.

Return to the CodePlex Home Page.
Sorry to bring back such an old topic...
Is there a way to get all of these modules you've created and integrate them into our own scripts? Or do we have to use your large dial plan script?
I find using these old snippets of code are out of date, hence my query.
Thanks Mike!

Cheers,
.
MikeTelis wrote:Updated the code published in my previous post, latest version is available on github.

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.

Re: sys.CallsInProgress

Posted: Tue Oct 04, 2016 8:58 am
by Aaron
You can use this gem in your sipsorcery dialplan https://gist.github.com/mtelis/490501/7 ... 1d301ca524 with a require line:

Code: Select all

require 'mikesgem'
Note that it's a special case and that gem has been copied to a specific directory on the sipsorcery application server.