September 15, 2020
Using STUN & TURN server with Tigase XMPP Server with XEP-0215 (External Service Discovery)
Communication with your family and friends is not only about instant chats. Audio and Video calls are quite important and sometimes, under unfavourable network configurations establishing a call may prove difficult. Luckily, with the help of STUN (Session Traversal Utilities for NAT) and TURN (Traversal Using Relays around NAT ) servers it’s no longer a problem
In the following guide we will show how to setup TURN and STUN servers with Tigase XMPP Server, so that compatible XMPP clients will be able to use them. Our xmpp.cloud installation supports not only them, but also XMPP MIX
Assumptions
We are assuming that you have installed your preferred TURN server and created an account on the TURN server for use by your XMPP server users and that you have installed and configured Tigase XMPP Server.
At the end of the article there is a short guide hot to quickly setup CoTURN server.
Enabling external service discovery (required only for Tigase XMPP Server 8.1.0 and earlier)
First you need to edit etc/config.tdsl
file and:
-
Add following line in the main section of the file:
'ext-disco' () {}
-
Add following line in the
sess-man
section of the file:'urn:xmpp:extdisco:2' () {}
so that your config file would look like this:
'ext-disco' () {}
'sess-man' () {
'urn:xmpp:extdisco:2' () {}
…
}
…
Start Tigase XMPP Server
After applying changes mentioned above, you need to start Tigase XMPP Server or, in case if it was running, restart it.
Open Admin UI
Open web browser and head to http://<your-xmpp-server-and-port>/admin/
(for example: https://localhost:8080). When promped, log in by providing admin user credentials: bare JID (i.e.: user@domain
) as the user and related password. Afterwards you’ll see main Web AdminUI screen:
and on that screen open Configuration group on the left by clicking on it.
Add external TURN service
After opening Configuration group (1
) click on Add New Item (2
) position which has ext-disco@… in its subtitle.
In the opened form you need to provide following detail:
- Service - ID of the service which will be used for identification by Tigase XMPP Server (ie.
turn@example.com
) - Service name - name of the service which may be presented to the user (ie.
TURN server
) - Host - fully qualified domain name of the TURN server or its IP address (ie.
turn.example.com
) - Port - port at which TURN server listens (ie.
3478
) - Type - type of the server, enter
turn
- Transport - type of transport used for communication with the server
udp
ortcp
(usuallyudp
) - Requires username and password - for notifying XMPP client that this service requires its username and password for XMPP service (leave unchecked)
- Username - username required for authentication for TURN server (ie.
turn-user
) - Password - password required for authentication for TURN server (ie.
turn-password
)
After filling out the form, press Submit
button (3
) to send form and add a TURN server to external services for your server. Admin UI will confirm that service was added with the following result
Add external STUN service
While adding a TURN server is usually all what you need, in some cases you may want to allow your users to use also STUN. Steps are quite similar like on TURN server - after opening Configuration group (1
) click on Add New Item (2
) position which has ext-disco@… in its subtitle and in the opened form you need to provide following detail:
- Service - ID of the service which will be used for identification by Tigase XMPP Server (ie.
stun@example.com
) - Service name - name of the service which may be presented to the user (ie.
STUN server
) - Host - fully qualified domain name of the STUN server or its IP address (ie.
stun.example.com
) - Port - port at which TURN server listens (ie.
3478
) - Type - type of the server, enter
stun
- Transport - type of transport used for communication with the server
udp
ortcp
(usuallyudp
) - Requires username and password - for notifying XMPP client that this service requires its username and password for XMPP service (leave unchecked)
- Username - username required for authentication for STUN server (if required)
- Password - password required for authentication for STUN server (if required)
Note
If you are using the same server for STUN and TURN (you usually will as TURN servers usually contain STUN functionality) you will fill the following form with almost the same details *(only use different Service field value, Type will be stun
and most likely you will skip passing Username and Password - leaving them empty, the rest of the field values will be the same).
After filling out the form, press Submit
button (3
) to send form and add a STUN server to external services for your server. Admin UI will confirm that service was added with the following result
And now what?
Now you have fully configured your STUN/TURN server for usage with Tigase XMPP Server allowing XMPP clients connected to your server and compatible with XEP-0215: External Service Discovery to take full advantage of your STUN/TURN server ie. by providing better VoIP experience.
CoTURN installation
You can quickly setup CoTURN server using Docker. Please follow Docker installation on your operating system and then install CoTURN using Docker Hub (instrumentisto/coturn). The bare minimum required to run it looks like that (please update realm
with your domain and external-ip
with IP on which server should be accessible):
sudo docker run --name coturn -d --network=host --restart always instrumentisto/coturn -n --log-file=stdout --min-port=49160 --max-port=49200 --realm=awesomexmpp.net --external-ip=<external_ip> -a'
Subsequently, add user to CoTURN with password and domain:
sudo docker exec -i -t coturn turnadmin -a -u tigase -r awesomexmpp.net -p Ajbk7Ck38nIobLVl
Related Articles:
Publishing and Subscribing with Halcyon
September 24, 2020