Lightweight JavaScript SDK for requesting TURN/STUN credentials from the Turnix API.
To use it goto http://turnix.io and register account. You can start for free.
npm install turnix-js
import { TurnixIO } from 'turnix-js';
const turnix = new TurnixIO({
bearerToken: 'your-bearer-token'
});
const iceServers = await turnix.requestCredentials({
initiatorClient: 'alice',
receiverClient: 'bob',
room: 'demo-room',
ttl: 60
});
const pc = new RTCPeerConnection({ iceServers });
All parameters are optional. Pass only those you need:
Parameter | Type | Description |
---|---|---|
initiatorClient |
String |
An identifier for the call initiator. |
receiverClient |
String |
An identifier for the call receiver. |
room |
String |
A room identifier to group clients |
ttl |
int |
Time-to-live in seconds for the credentials. |
fixedRegion |
String |
Strict region: forces allocation in the specified region (e.g., eu-central ); if unavailable, the request will fail. |
preferredRegion |
String |
Preferred region: hints allocation in a region (e.g., eu-central ); if unavailable, the server will fall back to another region. |
clientIp |
String |
Client IP for geofencing, sent as X-TURN-CLIENT-IP header. Defaults to the requester's IP address if unset, used to determine region when neither fixedRegion nor preferredRegion is specified. |
See https://github.com/turnixio/turnix-js-demo project for the demo usage.