--- name: telnyx-webrtc-client-js description: >- Build browser-based VoIP calling apps using Telnyx WebRTC JavaScript SDK. Covers authentication, voice calls, events, debugging, call quality metrics, and AI Agent integration. Use for web-based real-time communication. metadata: author: telnyx product: webrtc language: javascript platform: browser --- # Telnyx WebRTC - JavaScript SDK Build real-time voice communication into browser applications. > **Prerequisites**: Create WebRTC credentials and generate a login token using the Telnyx server-side SDK. See the `telnyx-webrtc-*` skill in your server language plugin (e.g., `telnyx-python`, `telnyx-javascript`). ## Installation ```bash npm install @telnyx/webrtc --save ``` Import the client: ```js import { TelnyxRTC } from '@telnyx/webrtc'; ``` --- ## Authentication ### Option 1: Token-Based (Recommended) ```js const client = new TelnyxRTC({ login_token: 'your_jwt_token', }); client.connect(); ``` ### Option 2: Credential-Based ```js const client = new TelnyxRTC({ login: 'sip_username', password: 'sip_password', }); client.connect(); ``` > **Important**: Never hardcode credentials in frontend code. Use environment variables or prompt users. ### Disconnect ```js // When done, disconnect and remove listeners client.disconnect(); client.off('telnyx.ready'); client.off('telnyx.notification'); ``` --- ## Media Elements Specify an HTML element to play remote audio: ```js client.remoteElement = 'remoteMedia'; ``` HTML: ```html