sys.CallsInProgress

New features you'd like see on SIP Sorcery
MikeTelis
Posts: 1581
Joined: Wed Jul 30, 2008 6:48 am

Re: sys.CallsInProgress

Post by MikeTelis » Fri Jul 16, 2010 8:19 am

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'

MikeTelis
Posts: 1581
Joined: Wed Jul 30, 2008 6:48 am

Re: sys.CallsInProgress

Post by MikeTelis » Tue Jul 27, 2010 7:39 pm

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.

User avatar
Flip
Posts: 82
Joined: Sun Aug 19, 2012 3:53 am

Re: sys.CallsInProgress

Post by Flip » Mon Oct 03, 2016 3:52 am

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.
ISP: Exetel ADSL2+ $60 Bundle. 22.4/1.2Mbps, 200/∞ GB [AAPT] + PSTN Bundle [Telstra].
VSP: Telecube¹, SIPTalk², MyNetFone³ via SIPSorcery & Ol' Voxalot. [OMG! Ewww Yuck!! Avoid DIDLogic!!!
H/W: Asus RT-AC66U; Cisco SPA232D, 3 x SPA302's, 2 x SPA901's, SPA3102; Yealink SIP-T46G.

User avatar
Aaron
Site Admin
Posts: 4560
Joined: Thu Jul 12, 2007 12:13 am

Re: sys.CallsInProgress

Post by Aaron » Tue Oct 04, 2016 8:58 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests