Simple example of configuring SIP trunk.
Why do you need SIP trunk
Say, you have click2call application, which should use multiple lines.
Multiple lines means, several people can call simultaneously using the same click2call button.
- Alice clicks "call button" and calls to New York department.
- Bob clicks "call button" and calls to LA department.
They are talking simultaneously.
Yes, you can implement this feature using multiple SIP accounts on Asterisk server.
In this example, we will explain how to do it using one Asterisk SIP account by Flashphoner.
The simplest way to create SIP trunk is creating Asterisk extension: in extensions.conf config
[default]
exten => _X.,1,Dial(SIP/MY_TRUNK_ACCOUNT/${EXTEN})
Here:
| _X. | Means, you can call to any phone number: 0..., 1..., e.t.c. |
| MY_TRUNK_ACCOUNT | Is account of your SIP provider. Configure this account in sip.conf config (see below) |
[general]
bindport=5060
bindaddr=0.0.0.0
context=default
dtmfmode=info
videosupport=yes
autoframing=no
disallow=all
allow=ulaw
allow=alaw
[MY_TRUNK_ACCOUNT]
type=peer
host=my_sip_provider_host
fromuser=my_sip_provider_from_user
secret=my_sip_provider_password
fromdomain=my_sip_provider_from_domain
username=my_sip_provider_username
allow=ulaw
allow=alaw
nat=yes
insecure=very
qualify=yes
[2002]
type=friend
secret=2002
host=dynamic
canreinvite=no
dtmfmode=info
Now, when you call number from Flashphoner, you call goes through Asterisk SIP trunk, via external VoIP provider, using MY_TRUNK_ACCOUNT
You should register Flashphoner on 2002. Then call to your destination to test the call.
| Make sure, your MY_TRUNK_ACCOUNT supports several lines. Please, consult about number of lines with your SIP provider |
Some SIP providers supports 5, 10 and more lines.
So, you can handle 5, 10, and more simultaneous calls using one MY_TRUNK_ACCOUNT.
But some SIP providers supports only one line.
That mean, you can not do more than one simultaneous call using one SIP account of such SIP provider.
What should I do if my SIP provider supports only one line per SIP account
In this case, you need several sip accounts:
- MY_TRUNK_ACCOUNT_1
- MY_TRUNK_ACCOUNT_2
e.t.c.
Please, define these accounts in sip.conf config.
Then your should to setup auto switching between accounts in extensions.conf file:
[default] TRUNKNUM=1 MIN_VALUE=1 MAX_VALUE=3 exten => _X.,1,GotoIf($["${TRUNKNUM}" != "${MAX_VALUE}"]?trunk-plus) exten => _X.,n,Set(TRUNKNUM=${MIN_VALUE}) exten => _X.,n(trunk-plus),Set(TRUNKNUM=$[${TRUNKNUM}+1]) exten => _X.,n,Dial(SIP/MY_TRUNK_ACCOUNT_${TRUNKNUM}/${EXTEN}) exten => _X.,n,Goto(trunk-plus) exten => _X.,n,Hangup
In this example we use MY_TRUNK_ACCOUNT_2 and MY_TRUNK_ACCOUNT_3 for outgoing calls.
[default] TRUNKNUM=0 MIN_VALUE=0 MAX_VALUE=5 exten => _X.,1,GotoIf($["${TRUNKNUM}" != "${MAX_VALUE}"]?trunk-plus) exten => _X.,n,Set(TRUNKNUM=${MIN_VALUE}) exten => _X.,n(trunk-plus),Set(TRUNKNUM=$[${TRUNKNUM}+1]) exten => _X.,n,Dial(SIP/MY_TRUNK_ACCOUNT_${TRUNKNUM}/${EXTEN}) exten => _X.,n,Goto(trunk-plus) exten => _X.,n,Hangup
Here we use MY_TRUNK_ACCOUNT_1, MY_TRUNK_ACCOUNT_2, MY_TRUNK_ACCOUNT_3, MY_TRUNK_ACCOUNT_4, MY_TRUNK_ACCOUNT_5 for outgoing calls.
Testing environment
- Centos 5.4 x86_64
- Wowza Media Server 3
- Flashphoner-server-1.0.5.1057
- Flashphoner-client-1.0.126
- Asterisk 1.8
- Adobe Flash Player 11