@telnyx/react-native-voice-sdk
v0.3.0
Published
Telnyx React Native Voice SDK - A complete WebRTC voice calling solution
Readme
@telnyx/react-native-voice-sdk
A comprehensive React Native SDK for Telnyx WebRTC voice calling.
Features
- 🎯 WebRTC Voice Calls: High-quality voice calls using Telnyx infrastructure
- 📞 Call Management: Full call lifecycle management (incoming, outgoing, hold, transfer)
- 🔐 Secure Authentication: JWT-based authentication with SIP credentials support
- 🌐 Network Resilience: Automatic network change detection and reconnection
- 📊 Event-Driven: Comprehensive event system for real-time call state updates
- 📱 Push Notification Ready: Built-in support for VoIP push notifications
- 🤖 Auto-Answer Support: Built-in auto-answer functionality for automated workflows
Installation
npm install @telnyx/react-native-voice-sdkQuick Start
import { TelnyxRTC, ClientOptions } from '@telnyx/react-native-voice-sdk';
// Initialize the client
const clientOptions: ClientOptions = {
login_token: 'your-jwt-token', // Recommended
// OR use login/password
// login: 'your-sip-username',
// password: 'your-sip-password',
};
const client = new TelnyxRTC(clientOptions);
// Connect to Telnyx
await client.connect();
// Make a call
const call = await client.newCall({
destinationNumber: '+1234567890',
callerIdName: 'John Doe'
});
// Listen for call events
call.on('telnyx.call.state', (call, state) => {
console.log(\`Call state: \${state}\`);
});
// Listen for client events
client.on('telnyx.client.ready', () => console.log('Ready!'));
client.on('telnyx.call.incoming', (call) => {
call.answer(); // or call.hangup()
});API Reference
TelnyxRTC
The main client class for managing WebRTC connections and calls.
Constructor
new TelnyxRTC(options: ClientOptions)Methods
connect(): Connect to Telnyx infrastructuredisconnect(): Disconnect and cleanupnewCall(options: CallOptions): Create a new outgoing callprocessVoIPNotification(payload): Process VoIP push notificationqueueAnswerFromCallKit(): Queue answer action for push callsqueueEndFromCallKit(): Queue end action for push calls
Events
telnyx.client.ready: Client is connected and readytelnyx.client.error: Connection or authentication errortelnyx.call.incoming: Incoming call received
Call
Represents an individual voice call.
Methods
answer(): Answer an incoming callhangup(): End the callhold(): Put call on holdunhold(): Resume call from holddtmf(digits): Send DTMF tones
Events
telnyx.call.state: Call state changed ('new', 'ringing', 'active', 'ended', 'held')
Advanced Features
Push Notifications & Auto-Answer
// Process push notification
client.processVoIPNotification(pushPayload);
// Enable auto-answer for next call (Android example)
import AsyncStorage from '@react-native-async-storage/async-storage';
await AsyncStorage.setItem('@auto_answer_next_call', 'true');
// Queue CallKit actions (iOS)
client.queueAnswerFromCallKit();Network Resilience
The SDK automatically handles network changes and reconnections.
// The client will automatically reconnect on network changes
client.on('telnyx.client.ready', () => {
console.log('Connected/Reconnected to Telnyx');
});TypeScript Support
The SDK is written in TypeScript and includes full type definitions.
import {
TelnyxRTC,
ClientOptions,
CallOptions,
CallState,
Call,
} from '@telnyx/react-native-voice-sdk';Example Usage
import React, { useEffect, useState } from 'react';
import { TelnyxRTC, Call } from '@telnyx/react-native-voice-sdk';
export const VoiceApp = () => {
const [client, setClient] = useState<TelnyxRTC | null>(null);
const [call, setCall] = useState<Call | null>(null);
useEffect(() => {
const telnyxClient = new TelnyxRTC({
login_token: 'your-jwt-token'
});
telnyxClient.on('telnyx.client.ready', () => {
console.log('Ready for calls!');
});
telnyxClient.on('telnyx.call.incoming', (incomingCall) => {
setCall(incomingCall);
// Auto-answer or show incoming call UI
incomingCall.answer();
});
telnyxClient.connect();
setClient(telnyxClient);
return () => telnyxClient.disconnect();
}, []);
const makeCall = async () => {
if (client) {
const newCall = await client.newCall({
destinationNumber: '+1234567890'
});
setCall(newCall);
}
};
return (
// Your call UI here
<></>
);
};Requirements
- React Native 0.60+
- React 16.8+
- iOS 11.0+ / Android API 21+
Dependencies
This package requires:
@react-native-community/netinfo- Network state monitoringreact-native-webrtc- WebRTC functionalityeventemitter3- Event handlingloglevel- Logginguuid-random- UUID generation
License
MIT License
