PubNub Integration

Xirsys Access Token API

In-app chat

In-app chat

Last Updated:

2018/09/12

Author:

Adam Bavosa

Implement Video Chat with Xirsys, WebRTC, and ChatEngine

A serverless API endpoint for securely providing TURN access to WebRTC clients.

Xirsys is one of the few original pioneers of WebRTC infrastructure with their TURN Server offerings. Today, they've extended their services to custom installation and hosting of practically all the possible WebRTC servers in the world including Jitsi video bridge, Janus video room, Medooze, LiveSwitch, and Kurento media server. With a footprint in 11 data centers across the world, they are the most versatile and reliable WebRTC hosting solution on the market.

Xirsys is built upon patented technology providing a distributed deployment architecture for advanced reliability, scalability and extendability. This creates superior uptime and allows for arbitrary 3rd party software to quickly become part of the Xirsys service and accessible through the API.

Xirsys Access Token API

How It Works

The Xirsys function endpoint substitutes a web server for providing WebRTC clients with tokens for TURN provider access. Conventionally, a website's server will be the secure granter of access, by providing temporary access tokens to clients. This way, malicious app developers cannot hijack your company's Xirsys account, racking up video streaming bandwidth on your Xirsys bill.

PubNub Functions takes the web server hosting component out of the equation for the equation for the developer, by making the service serverless. Think of this custom API as a microservice, hosted in the cloud, that can be deployed instantly with the click of a button.

The Xirsys endpoint you deploy with PubNub Functions provides two REST actions:

- A GET route that returns a temporary token (60 minute TTL). A client can request Xirsys credentials for up to 1 hour after they retrieve a token.

- A PUT route that returns a list of ICE servers and temporary credentials from Xirsys. The client must provide a valid token to this route. The token distribution and TTL is handled entirely by the PubNub Functions KV Store.

Before deploying, you must:

  • Sign up for a Xirsys account

  • Get your Xirsys channel, ident, and secret from the Xirsys dashboard

  • Add the values you get from Xirsys as "ident:secret" to the PubNub Functions Vault with the key "xirsys".

  • Replace the channel variable at the top of the code with your Xirsys channel

  • Replace the origin URL with your app's URL

  • Make sure the event handler type is "On Request"

  • Click the copy URL button and paste the URL into your client application code

  • Read this WebRTC with Xirsys tutorial for a more in-depth walkthrough.

GET Request

The GET and PUT HTTP requests can be made to the Function endpoint URL. The get request returns a 1-hour life token, which can be used to make a PUT request to the same API. The PUT request will return WebRTC TURN server access credentials for Xirsys.

// Get a 1 hour token from your PubNub Functions API
let turnToken;
request(url, 'GET').then((response) => {
    // Response is a unique base64 encoded string
    turnToken = response
});

PUT Request

The PUT request will return WebRTC TURN server access credentials for Xirsys. For more on web development with these credentials, take a look at the MDN website documentation on WebRTC and TURN.

// Get new TURN server credentials from Xirsys
request(url, 'PUT', {
    'headers': {
        'tok': turnToken
    }
}).then((response) => {
    rtcConfig.iceServers = [response];

    // Response object looks like this:
    // {
    //     "urls": [
    //         "stun:w2.xirsys.com",
    //         "turn:w2.xirsys.com:80?transport=udp",
    //         "turn:w2.xirsys.com:3478?transport=udp",
    //         "turn:w2.xirsys.com:80?transport=tcp",
    //         "turn:w2.xirsys.com:3478?transport=tcp",
    //         "turns:w2.xirsys.com:443?transport=tcp",
    //         "turns:w2.xirsys.com:5349?transport=tcp"
    //     ],
    //     "username": "dc878d7e-e3b0-11e8-be12-f55daaa747ad",
    //     "credential": "dc849e01-e3a0-11e8-acd1-7d1bbed496e7"
    // }
});

Feedback & Support

Need help? Contact PubNub Support.


Talk to an expert

Contact Sales