In order to limit the number of simultaneous calls in Asterisk PJSIP, use the GROUP and GROUP_COUNT functions. Below is an example of Asterisk dialplan, where the quantity of simultaneous calls is limited to 1.
- The number 810XXXXXXX is dialed, the message is displayed in the console: dialing 810XXXXXXX
- the GROUP() function assigns calls to the group “long”
- The following message is displayed in the console: the number of simultaneous calls – $ {GROUP_COUNT (long)}, where $ {GROUP_COUNT (long) = the sequence number of the call.
- The condition is checked, if the number of simultaneous calls is more than 1, the call is sent to extension “over” and gets disconnected with the output to the console:
the limit is exceeded for – […] lines.
If the call is the first, the number is dialed through the provider’s SIP trunk.
1 2 3 4 5 6 7 |
exten => _810.,1,Verbose(*** dialing - ${EXTEN} ***) same => n,Set(GROUP()=long) same => n,Verbose(*** the number of simultaneous calls - ${GROUP_COUNT(long)} ***) same => n,GotoIf($[${GROUP_COUNT(long)} > 1]?over) same => n,Dial(PJSIP/${EXTEN}@siptrunk,,) same => n(over),Verbose(*** the limit is exceeded - ${MATH(${GROUP_COUNT(long)}-1)} lines***) same => n,Set(DIALSTATUS=CHANUNAVAIL) |
Good luck!