This directory contains a sample worker to provide the measurement engine with TURN server credentials.
Warning:
Cloudflare Realtime TURN servers are subject to billing after the free tier limits are reached.
Read the Cloudflare Realtime TURN FAQ for more information on TURN usage billing.
- In the Cloudflare Dashboard, select
Realtimefrom the sidebar, then insideTURN ServerclickCreate. - Select a name for your server, and press
Create - To use these tokens while developing locally, edit the
.dev.varsfile at the root of this directory, setting:REALTIME_TURN_TOKEN_IDto the returned Turn Token IDREALTIME_TURN_TOKEN_SECRETto the returned API Token.
- To add these secrets to your remote worker:
- Run
npm exec wrangler secret put REALTIME_TURN_TOKEN_IDand provide the Turn Token ID - Run
npm exec wrangler secret put REALTIME_TURN_TOKEN_SECRETand provide the API Token
- Run
If you'd like this worker to be available at your own domain, uncomment the routes section in the wrangler.jsonc file, replacing the example configuration with your own domain and zone ID.
Alternatively, you can use the *.workers.dev subdomain provided by default.
Add the URLs your worker will be available at to REALTIME_TURN_ORIGINS in the vars section inside wrangler.jsonc.
Run npm run deploy and follow the instructions.
When instantiating the measurement engine, set the turnServerCredsApiUrl option to https://<your-worker-domain>/turn-credentials.
For local development, run npm run start and set turnServerCredsApiUrl to http://localhost:8787
Read the Cloudflare Workers guide for more information.