Welcome to Auroran Runner Tuesday, November 21 2017 @ 05:44 PM EST

Asterisk GTalks

  • Contributed by:
  • Views: 38,868
General News While upgrading my Asterisk from 1.2.x to 1.4.x I noticed that long waited support for Jabber and Jingle is finally available to use. This means, that I am not only able connect through Asterisk to any Jabber server, but I am able to route calls from SIP phones to GTalk accounts and vice versa. Basically I am able to make and receive calls from my Nokia E70 to and from GTalk accounts with no additional S60 software. If I am using WLAN, calls utilize the WLAN connection. If there is no WLAN available, I am still able to receive GTalk calls through GSM network and make them through 3G.

Why?

Why bother, we already have Fring and similar software solutions you might say. Well yes, we have, but how many actually runs Fring or other solutions 24x7? I have my phone with me 24x7, but I certainly do not run any other software constantly except the native phone software to make and receive calls. This ensures best battery life as well as stability. I use native SIP based VoIP capabilities on my Nokia E70 daily. With proper codec SIP works well on 3G and when there is WLAN available, there is absolutely no reason not to utilize SIP. It doesn't cost anything for me and it is one of the top reasons why I bought my Nokia E70 in the first place. Nokia E-Series phones are not the cheapest ones, but you are able VoIP all over the world. I for instance spent six weeks in California last year. During the trip I called daily about hour lasting calls to my family here in Finland. After six weeks my phone bill was 0 cents. I was also able to receive calls from my family, and it didn't cost a penny. To made it cost absolutely nothing and still provide maximum flexibility, I have set up my own Asterisk server. This helps me to communicate with my family and closest friends, but I am not able to provide my Asterisk server to be used by the whole world. Google serves the world and they have GTalk. I want to GTalk and change nothing on my phone.

How it works?

You need to tweak Asterisk just a bit but not much. Since configuring Asterisk can be a bit cumbersome, lets rather go through what you can do with Asterisk connected to GTalk first. I'll explain how to configure Asterisk to be able to GTalk a bit later. I have a GTalk account, but actually I do not use it almost at all. Instead I use my own Jabber server to chat with few Google Talk friends I have. My Jabber ID (JID) is tav@voip.ampiainen.net. If a Google Talker want to chat with me, she adds this JID as one of her friends. This works fine. I am not using GTalk client either. I use Jabber instant messaging (IM) client called Spark, which connects to my Openfire server. Spark is nice Jabber client and Openfire is nice Jabber server. I also have Asterisk-IM plugin on my Openfire server, so I actually already have some VoIP capabilities on my IM client. If another Spark user wants to call me through VoIP, she just hits the phone button on her Spark client. This fires Asterisk server to first call her, and when she answers the call, it will be transfered to my SIP phone. Both users will need to have SIP phones, since VoIP calls are handled through them rather than through IM client. This is a nice feature, but very few people have Jabber account on Openfire server connected and configured to communicate with Asterisk server.

So it really really would be nice to be able to handle the VoIP part also with Google Talkers, since quite a few people are using GTalk, and GTalk can VoIP using Jingle protocol, which is an open protocol. Unlike Skype (Skype uses closed proprietary protocol which makes Skype evil), GTalk uses open standards (open standards are good). Google does not use SIP, but Jabber for IM and Jingle for VoIP. To be able to to GTalk with SIP client we need some sort of media gateway. Asterisk can act as a media gateway. My Nokia E70 knows how to SIP, but it does not GTalk. Now, starting from asterisk 1.4.x Asterisk is able GTalk. SIP it has been able to talk from the very early days. It can also act as a media gateway. I have everything I need. I have SIP capable phone and SIP account on my Asterisk server. I have media gateway, my Asterisk server. I have one buddy using GTalk. This is enough. I tell Asterisk about my buddy and where she can be reached. I create an extension for her. This will be 111. So when I make a VoIP call to extension 111, it will be connected to my GTalk buddy.

My GTalk buddy on the other hand can see me through my Asterisk server. When I do not have my IM client running, my GTalk buddy will see my presence status set to "I'm only able to receive calls but not to chat". That is so she knows, that she can call me, but at the moment I am not able to receive chat messages.


Picture 2: Google Talk client

As you can see from picture above, my only GTalking friend is actually not she and he has same name as I do. Well, actually I do have other friends as well, but the screenshot was taken only while testing the setup, and during the tests, I used my own GTalk account. Really! Ok, now that this is cleared, lets continue. What happens if I hit the call button:


Picture 3: Making a call with GTalk client

Happens that GTalk client calls to my Nokia E70 through my Asterisk server. I configured Asterisk the way, that all calls from Google talk seems to come "From Google Talk" as you can see from illustration below:


Picture 4: Receiving a call from GTalk client

Cool, it actually works! I am able to talk with no additional software installations for my Nokia with GTalk accounts. I am able to receive and make calls from and to GTalk users. When I want to make a call for the one and only buddy using GTalk, which was revealed to be myself, I just choose extension 111, hit "Options" and choose "Call" --> "Internet call". I do not need any additional software to eat my battery empty before I have time to say cat and to make E70 even more unstable than it was when delivered from factory. Like this:


Picture 5: Making a GTalk call with Nokia E70

The Google Talk user now sees call coming from my JID.


Picture 6: Receiving a call from Nokia E70 with GTalk client

Calling works, what about chatting?

Can I also chat through my phone? Oh yes I can, but for that I need the additional software. I use IM+, which understands Jabber protocol and few others as well (including GTalk, but like said, I am happy with my own Jabber server). I am able to fire the IM+ up and still be able to make and receive calls to and from GTalk accounts. Now I am also able to chat with them. Since the GTalk part is pretty much done, lets look a bit closer how everything works normally just by using Spark IM client and Openfire connected to Asterisk. If my Spark buddy, which is my wife this time, wants to chat with me, she checks my presence status first.


Picture 7: Spark IM client

Now that she sees my status after I fired up IM+ switched to "Mobile" from "I'm only able to receive calls but not to chat", she knows she can chat with me. To ask if she can call for me of course :) I'll receive her message as show below:


Picture 8: Receiving a chat message with Nokia E70 from Spark IM client

I answer go ahead, since although I have my IM fired up, I am of course still able to receive VoIP calls. My wife needs now only to hit phone button on her Spark client on right upper corner:


Picture 9: Launch a VoIP call with Spark IM client

Now the call is actually coming from my wifes SIP phone, not from IM client. I will see the call coming from the extension and user info which is configured to my Asterisk server. So this differs slightly from GTalk calls, where I see call coming from generic Google Talk account. Also, both of the clients are pure SIP clients, not IM clients. But the call is still fired from IM client instead of SIP phone. Spark has some other nice features as well. When some one is calling to me while I have my Spark client turned on, I see where the call is coming from on the pop up displayed on my laptop's right bottom corner. My presence will be changed to "on the phone" automatically by Asterisk. This will of course happen with my current configuration also when talking with GTalk accounts, because that is how my Jabber server and Asterisk server are configured. So how to make this all work? With Asterisk and Openfire it is very simple. You just need to enable and configure Asterisk-IM to your Openfire server. But how to make Asterisk to GTalk?

Configuring Asterisk

First of all, you need to enable GTalk channel support. Currently this is experimental feature, so it is not enabled by default. To be able to enable the GTalk channel support, you need iksemel. This is easy to compile and install from source:

$ wget http://iksemel.googlecode.com/files/iksemel-1.3.tar.gz
$ tar xfz iksemel-1.3.tar.gz
$ cd iksemel-1.3
$ ./configure --prefix=/usr
$ make
$ sudo make install

Thats it for iksemel. If you already have Asterisk 1.4.x installed from source and you have the source directory available, all you need to do now, is to perform a) "./configure", b) "make menuconfig" ---> "3. Channel Drivers" ---> c) "[*] 4. chan_gtalk", d) "make" and e) "make install". That's it. Just restart your Asterisk and you should be able to use command "gtalk show channels" as shown below:

sever*CLI> gtalk show channels 
Channel    Jabber ID      Resource         Read  Write 
0 active gtalk channels

Now couple of new configurations files and couple of changes to existing extensions.conf, and we are able to GTalk. We need jabber.conf and gtalk.conf. Let's start with jabber.conf

[general]
debug=no
autoprune=no
autoregister=no

[ampiainen_net]
type=client
serverhost=voip.ampiainen.net
username=tav@voip.ampiainen.net/Talk
secret=password
port=5222
usetls=yes
usesasl=yes
buddy=yourbuddy@gmail.com
statusmessage="I'm only able to receive calls but not to chat"
timeout=100

For experienced Asterisk users above is self explanatory. For others first thing to notice is that I am not using my GTalk account as my own Jabber account. I am using my own Jabber server voip.ampiainen.net. I have configured for this account section [ampiainen_net]. This could be replaced by what ever Jabber server including GTalk itself of course. The buddy line will define the one and only buddy I want to currently to be able to GTalk with. Next let's look at gtalk.conf

[general]
context=google-in
allowguest=yes
                                               
[guest]
disallow=all
allow=alaw
context=google-in

[buddy]
username=yourbuddy@gmail.com
disallow=all
allow=alaw
context=google-in
connection=ampiainen_net 

Above yourbuddy is again the one and only GTalk buddy I want to be able to GTalk with at the moment. I reach this buddy through my ampiainen_net account, which I have set as a connection above. Now couple of changes to existing extensions.conf and we are done.

[google-in]
exten => s,1,NoOp( Call from Gtalk )
exten => s,n,Set(CALLERID(name)="From Google Talk")
exten => s,n,Dial(SIP/tav)
exten => s,n,Dial(SIP/040xxxxxxx@yourgsmprovider_out,60,Tr)

[google-out]
exten => 111,1,Dial(gtalk/buddy/yourbuddy@gmail.com)

You should change "tav" to your own SIP device. As you can see, I use context "yourgsmprovider_out", to transfer the call trough GSM network when SIP fails. This should also be changed to your own GSM provider. Mine offers free calls from VoIP accounts to providers GSM network. If you don't have such a deal, you might want to consider not to use this sort of approach in the first place. Or just wait for the next phone bill and decide what do after that. Be sure to include both google-in and google-out to context your phone is hooked into. That is pretty much it. You should check nice and helpful articles found from voip-info.org. Use google to find them with keywords "gtalk" and "Asterisk". I also found a blog writing which encouraged to use speex as a codec for GTalk, but could not get this to working properly. My experiences has proved that alaw is fine codec. I use g729 as a default codec for all of my SIP devices. g729 is commercial codec and works really great with devices like Nokia E70 and ZyXEL Prestige 2000W. I have also alaw enabled for all devices, so no additional changes were needed for them.

Summary

Summarizing everything above, I would say, that these new Asterisk features, which enables integration with GTalk, are very nice and useful for many people. It never hurt to be able to talk with GTalk users. GTalk is nice VoIP software. Because Google embraces open standards, interoperation with other software solutions is made possible.