Skip to content

Voice

Currently only WebRTC connections are supported. UDP connections will be dropped

Voice support is left as an optional dependency in Harmony, which means that it is disabled by default unless you decide to install additional dependencies. Harmony is designed so that anyone can develop a voice package compatible with the project as long as the implementation adheres to the WebRTC types. Currently there is one implementation that can be used:

  • (Recommended) Pion Implementation - Golang SFU which is bridged via IPC to communicate with your voice gateway
    • ✅ Video
    • ✅ Audio
    • ✅ Guild + DM voice
    • ✅ Go Live streams

Configuring Voice Gateway

By default the Voice Gateway is set to run on port 3004. You can change this default configuration by setting your desired port it in your .env:

WRTC_WS_PORT=3004

You also have to configure the Voice Gateway endpoint in your database. In table config you can set the default region endpoint to your Voice Gateway domain. It is set to localhost:3004 by default:

"regions_available_0_endpoint":   "voice.example.com"

or with the JSON config

{
    "regions": {
        "default": "example",
        "useDefaultAsOptimal": true,
        "available": [
            {
                "id": "example",
                "name": "example",
                "endpoint": "voice.example.com",
                "vip": false,
                "custom": false,
                "deprecated": false
            }
        ]
    }
}

Nginx reverse proxy for Voice Gateway

You will likely want to set your voice gateway behind a reverse proxy. Here's a sample Nginx configuration:

server {
 # Change server_name
    server_name voice.example.com;
    listen 80;

    location / {
   # Only change this if Nginx and Harmony are not on the same machine.
            proxy_pass http://127.0.0.1:3004;
            proxy_set_header Host $host;
            proxy_pass_request_headers      on;
            add_header Last-Modified $date_gmt;
            add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-Proto https;
            proxy_set_header  X-Forwarded-For $remote_addr;
            proxy_set_header  X-Forwarded-Host $remote_addr;
            proxy_no_cache 1;
            proxy_cache_bypass 1;

   # This is important. It allows Websocket connections through NGINX.
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    }
}

Configuring Voice Library

You can install the provided implementation or you can choose to install another third-party one. Installation process will be the same regardless:

Pion implementation installation

  1. First install the package in your Harmony server:

    npm install harmony-pion-webrtc --no-save
    
  2. Configure the package name in your Harmony server .env:

    WRTC_LIBRARY=harmony-pion-webrtc
    

Run the Pion SFU

This is only required if you're not on linux, or otherwise do not wish to use the bundled version, otherwise the SFU is bundled with the npm package

  1. Download the Golang SFU from Pion Repository

  2. Running the SFU:

Make sure you have Golang installed then follow the instructions for your needs:

Production Environment

If you're trying to run this in production you'll need to:

cd pion-sfu
go build
then on the server set the PION_SFU_BIN environment variable to the path to the resulting binary

Development Environment

For a development environment you may wish to instead run it with go directly like this:

cd pion-sfu
go run . -port <udp port>

Authenticating WebRTC server

The WebRTC server does not support the deprecated database configuration option, so you must use the json configuration file instead.

The WebRTC server does not have access to the database or IPC, so it can be ran on a completely separate machine, though this means you'll need to get it an internal token.

  1. In the directory of the main server run the following npm command
    npm run makeWebRTCToken
    
    this will spit out the token into the terminal, copy it, and remove all enters from the token, they should not be there but are often added by your terminal due to line wrapping.
  2. Set up the config of the WebRTC server In the WebRTC server you should see in the JSON config a property that looks like this:
    {
        "webrtc": {
            "authtoken": ""
        }
    }
    
    go ahead and add the token you just generated into the config.

You'll also need to make sure the private API endpoint is also correctly set before you start the WebRTC server.