JavaScript quickstart
The JavaScript SDK can be added to your application in the following ways:- Installing it using npm package: https://www.npmjs.com/package/@telnyx/webrtc.
- As a script in your web application using one of the external CDNs:
Client initialization
CDN example
Node.js example
| Value | Description |
|---|---|
ringbackFile | A URL to a wav/mp3 ringback file that will be used when you disable “Generate Ringback Tone” in your SIP connection. |
ringtoneFile | A URL to a wav/mp3 ringtone file. |
Client authentication
The WebRTC client has two main ways of authentication. You can either use a JSON Web Token (Telnyx access token) or username and password (on-demand credentials).Authenticating with a JSON Web Token
Authenticating with username and password credentials
Client registration
The.on method allows the client to attach the event handler. When the client receives the telnyx.ready event, the client is ready to place phone calls.
Call events
When the client is initiated and in a ready state you can observe call events usingtelnyx.notification.
Call states
You can expect the following call states innotification.call.state attribute:
| Value | Description |
|---|---|
new | New call has been created in the client. |
trying | It’s attempting to call someone. |
requesting | The outbound call is being sent to the server. |
recovering | The previous call is recovering after the page refreshes. If the user refreshes the page during a call, it will automatically join the latest call. |
ringing | Someone is attempting to call you. |
answering | You are attempting to answer this inbound call. |
early | It receives the media before the call has been answered. |
active | Call has become active. |
held | Call has been held. |
hangup | Call has ended. |
destroy | Call has been destroyed. |
purge | Call has been purged. |