Saturday, October 15, 2016

how to integrate ejabberd with asterisk

by default ejabberd, xmpp, provide only instant messaging, if you want to make audio you have integrate with the asterisk.

Below will show you how to setup both ejabberd and asterisk and make audio call possible from pidgin client.

1- follow the following link to setup asterisk server
http://www.atechnote.com/2014/11/how-to-setup-voip-server-asterisk.html

- after you complete it, you will get a working asterisk server with two sip account
user1 and user2 with extension 6001 and 6002 respectively


2- follow the following link to setup ejabberd server
http://www.atechnote.com/2016/09/configure-jabberxmpp-server-ejabberd.html

- after you complete it, you will get a working xmpp server with two account
user1@test.qq and user2@test.qq


*** integration
- step 1, on asterisk authentication xmpp account sessions.
- step 2, on asterisk map xmpp account with sip account


 *** on asterisk
 1- add xmpp accounts to asterisk, by update file /etc/asterisk/xmpp.conf to the following content
 [general]
        autoregister=yes
        autoprune=no
[user1]
        type=client
        serverhost=test.qq
        username=user1@test.qq
        secret=me
        priority=1
        port=5222
        usetls=no
        usesasl=yes
        status=available
        timeout=5
[user2]
        type=client
        serverhost=test.qq
        username=user2@test.qq
        secret=me
        priority=1
        port=5222
        usetls=no
        usesasl=yes
        status=available



2-  map xmpp accounts to asterisk account, by update file                   /etc/asterisk/xmpp.conf to the following content

[inside-context]
exten=>6001,1,Dial(SIP/user1,20)
exten=>6002,1,Dial(SIP/user2,20)

exten=>2001,1,Set(JSTATUS=${JABBER_STATUS(user1,user1@test.qq)})
                same => n, GotoIf($[0${JSTATUS} = 1]?available:unavailable)
                same => n(available), JabberSend(user1,user1@test.qq,Incoming call from ${CALLERID(num)})
                same => n, Dial(SIP/user1)
                same => n, Hangup()
                same => n(unavailable), JabberSend(user1,user1@test.qq,"Missed call from ${CALLERID(num)}")
                same => n, Goto(TonyUnavail,s,1)
exten=>2002,1,Set(JSTATUS=${JABBER_STATUS(user2,user2@test.qq)})
                same => n, GotoIf($[0${JSTATUS} = 1]?available:unavailable)
                same => n(available), JabberSend(user2,user2@test.qq,Incoming call from ${CALLERID(num)})
                same => n, Dial(SIP/user2)
                same => n, Hangup()
                same => n(unavailable), JabberSend(user2,user2@test.qq,"Missed call from ${CALLERID(num)}")

                same => n, Goto(TonyUnavail,s,1)

3- restart asterisk service and list xmpp account status
$ sudo /etc/init.d/asterisk restart

- list xmpp accounts status and extensions
ulvm*CLI> xmpp show connections
Jabber Users and their status:
       [user1] user1@test.qq     - Connected
       [user2] user2@test.qq     - Connected
----
   Number of clients: 2
ulvm*CLI> dialplan show inside-context
[ Context 'inside-context' created by 'pbx_config' ]
  '2001' =>         1. Set(JSTATUS=${JABBER_STATUS(user1,user1@test.qq)}) [pbx_config]
                    2. GotoIf($[0${JSTATUS} = 1]?available:unavailable) [pbx_config]
     [available]    3. JabberSend(user1,user1@test.qq,Incoming call from ${CALLERID(num)}) [pbx_config]
                    4. Dial(SIP/user1)                            [pbx_config]
                    5. Hangup()                                   [pbx_config]
     [unavailable]  6. JabberSend(user1,user1@test.qq,"Missed call from ${CALLERID(num)}") [pbx_config]
                    7. Goto(TonyUnavail,s,1)                      [pbx_config]
  '2002' =>         1. Set(JSTATUS=${JABBER_STATUS(user2,user2@test.qq)}) [pbx_config]
                    2. GotoIf($[0${JSTATUS} = 1]?available:unavailable) [pbx_config]
     [available]    3. JabberSend(user2,user2@test.qq,Incoming call from ${CALLERID(num)}) [pbx_config]
                    4. Dial(SIP/user2)                            [pbx_config]
                    5. Hangup()                                   [pbx_config]
     [unavailable]  6. JabberSend(user2,user2@test.qq,"Missed call from ${CALLERID(num)}") [pbx_config]
                    7. Goto(TonyUnavail,s,1)                      [pbx_config]
  '6001' =>         1. Dial(SIP/user1,20)                         [pbx_config]
  '6002' =>         1. Dial(SIP/user2,20)                         [pbx_config]

-= 4 extensions (16 priorities) in 1 context. =-




4- now everything is ready, so user1@test.qq and user2@test.qq, will able to call echo other after they login and add each other into their buddy list

- snapshot of user1 choose resource to call

- snapshot an initial call from user1 on user2 pc


- snapshot of call in progress, so both you can talk to each other on this stage

No comments:

Post a Comment