From telnyx-webrtc-client
Integrates Telnyx WebRTC SDK into iOS apps for VoIP calls with Swift. Covers auth (SIP/JWT), CallKit, PushKit/APNS, metrics, AI agents, and setup.
npx claudepluginhub team-telnyx/skillsThis skill uses the workspace's default tool permissions.
Build real-time voice communication into iOS applications using Telnyx WebRTC.
Integrates Telnyx WebRTC SDK into iOS apps for VoIP calls with Swift. Covers auth (SIP/JWT), CallKit, PushKit/APNS, metrics, AI agents, and setup.
Implements iOS VoIP calling with CallKit and PushKit for incoming/outgoing flows, VoIP push registration, CXProvider/CXCallController config, audio sessions, and call directory extensions.
Prevents silent decimal mismatch bugs in EVM ERC-20 tokens via runtime decimals lookup, chain-aware caching, bridged-token handling, and normalization. For DeFi bots, dashboards using Python/Web3, TypeScript/ethers, Solidity.
Share bugs, ideas, or general feedback.
Build real-time voice communication into iOS applications using Telnyx WebRTC.
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).
pod 'TelnyxRTC', '~> 0.1.0'
Then run:
pod install --repo-update
https://github.com/team-telnyx/telnyx-webrtc-ios.gitmain branchDisable Bitcode: Build Settings → "Bitcode" → Set to "NO"
Enable Background Modes: Signing & Capabilities → +Capability → Background Modes:
Microphone Permission: Add to Info.plist:
<key>NSMicrophoneUsageDescription</key>
<string>Microphone access required for VoIP calls</string>
import TelnyxRTC
let telnyxClient = TxClient()
telnyxClient.delegate = self
let txConfig = TxConfig(
sipUser: "your_sip_username",
password: "your_sip_password",
pushDeviceToken: "DEVICE_APNS_TOKEN",
ringtone: "incoming_call.mp3",
ringBackTone: "ringback_tone.mp3",
logLevel: .all
)
do {
try telnyxClient.connect(txConfig: txConfig)
} catch {
print("Connection error: \(error)")
}
let txConfig = TxConfig(
token: "your_jwt_token",
pushDeviceToken: "DEVICE_APNS_TOKEN",
ringtone: "incoming_call.mp3",
ringBackTone: "ringback_tone.mp3",
logLevel: .all
)
try telnyxClient.connect(txConfig: txConfig)
| Parameter | Type | Description |
|---|---|---|
sipUser / token | String | Credentials from Telnyx Portal |
password | String | SIP password (credential auth) |
pushDeviceToken | String? | APNS VoIP push token |
ringtone | String? | Audio file for incoming calls |
ringBackTone | String? | Audio file for ringback |
logLevel | LogLevel | .none, .error, .warning, .debug, .info, .all |
forceRelayCandidate | Bool | Force TURN relay (avoid local network) |
let serverConfig = TxServerConfiguration(
environment: .production,
region: .usEast // .auto, .usEast, .usCentral, .usWest, .caCentral, .eu, .apac
)
try telnyxClient.connect(txConfig: txConfig, serverConfiguration: serverConfig)
Implement TxClientDelegate to receive events:
extension ViewController: TxClientDelegate {
func onSocketConnected() {
// Connected to Telnyx backend
}
func onSocketDisconnected() {
// Disconnected from backend
}
func onClientReady() {
// Ready to make/receive calls
}
func onClientError(error: Error) {
// Handle error
}
func onIncomingCall(call: Call) {
// Incoming call while app is in foreground
self.currentCall = call
}
func onPushCall(call: Call) {
// Incoming call from push notification
self.currentCall = call
}
func onCallStateUpdated(callState: CallState, callId: UUID) {
switch callState {
case .CONNECTING:
break
case .RINGING:
break
case .ACTIVE:
break
case .HELD:
break
case .DONE(let reason):
if let reason = reason {
print("Call ended: \(reason.cause ?? "Unknown")")
print("SIP: \(reason.sipCode ?? 0) \(reason.sipReason ?? "")")
}
case .RECONNECTING(let reason):
print("Reconnecting: \(reason.rawValue)")
case .DROPPED(let reason):
print("Dropped: \(reason.rawValue)")
}
}
}
let call = try telnyxClient.newCall(
callerName: "John Doe",
callerNumber: "+15551234567",
destinationNumber: "+18004377950",
callId: UUID()
)
func onIncomingCall(call: Call) {
// Store reference and show UI
self.currentCall = call
// Answer the call
call.answer()
}
// End call
call.hangup()
// Mute/Unmute
call.muteAudio()
call.unmuteAudio()
// Hold/Unhold
call.hold()
call.unhold()
// Send DTMF
call.dtmf(digit: "1")
// Toggle speaker
// (Use AVAudioSession for speaker routing)
import PushKit
class AppDelegate: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate {
private var pushRegistry = PKPushRegistry(queue: .main)
func initPushKit() {
pushRegistry.delegate = self
pushRegistry.desiredPushTypes = [.voIP]
}
func pushRegistry(_ registry: PKPushRegistry,
didUpdate credentials: PKPushCredentials,
for type: PKPushType) {
if type == .voIP {
let token = credentials.token.map { String(format: "%02X", $0) }.joined()
// Save token for use in TxConfig
}
}
func pushRegistry(_ registry: PKPushRegistry,
didReceiveIncomingPushWith payload: PKPushPayload,
for type: PKPushType,
completion: @escaping () -> Void) {
if type == .voIP {
handleVoIPPush(payload: payload)
}
completion()
}
}
func handleVoIPPush(payload: PKPushPayload) {
guard let metadata = payload.dictionaryPayload["metadata"] as? [String: Any] else { return }
let callId = metadata["call_id"] as? String ?? UUID().uuidString
let callerName = (metadata["caller_name"] as? String) ?? ""
let callerNumber = (metadata["caller_number"] as? String) ?? ""
// Reconnect client and process push
let txConfig = TxConfig(sipUser: sipUser, password: password, pushDeviceToken: token)
try? telnyxClient.processVoIPNotification(
txConfig: txConfig,
serverConfiguration: serverConfig,
pushMetaData: metadata
)
// Report to CallKit (REQUIRED on iOS 13+)
let callHandle = CXHandle(type: .generic, value: callerNumber)
let callUpdate = CXCallUpdate()
callUpdate.remoteHandle = callHandle
provider.reportNewIncomingCall(with: UUID(uuidString: callId)!, update: callUpdate) { error in
if let error = error {
print("Failed to report call: \(error)")
}
}
}
import CallKit
class AppDelegate: CXProviderDelegate {
var callKitProvider: CXProvider!
func initCallKit() {
let config = CXProviderConfiguration(localizedName: "TelnyxRTC")
config.maximumCallGroups = 1
config.maximumCallsPerCallGroup = 1
callKitProvider = CXProvider(configuration: config)
callKitProvider.setDelegate(self, queue: nil)
}
// CRITICAL: Audio session handling for WebRTC + CallKit
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
telnyxClient.enableAudioSession(audioSession: audioSession)
}
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
telnyxClient.disableAudioSession(audioSession: audioSession)
}
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
// Use SDK method to handle race conditions
telnyxClient.answerFromCallkit(answerAction: action)
}
func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
telnyxClient.endCallFromCallkit(endAction: action)
}
}
Enable with debug: true:
let call = try telnyxClient.newCall(
callerName: "John",
callerNumber: "+15551234567",
destinationNumber: "+18004377950",
callId: UUID(),
debug: true
)
call.onCallQualityChange = { metrics in
print("MOS: \(metrics.mos)")
print("Jitter: \(metrics.jitter * 1000) ms")
print("RTT: \(metrics.rtt * 1000) ms")
print("Quality: \(metrics.quality.rawValue)")
switch metrics.quality {
case .excellent, .good:
// Green indicator
case .fair:
// Yellow indicator
case .poor, .bad:
// Red indicator
case .unknown:
// Gray indicator
}
}
| Quality Level | MOS Range |
|---|---|
| .excellent | > 4.2 |
| .good | 4.1 - 4.2 |
| .fair | 3.7 - 4.0 |
| .poor | 3.1 - 3.6 |
| .bad | ≤ 3.0 |
client.anonymousLogin(
targetId: "your-ai-assistant-id",
targetType: "ai_assistant"
)
// After anonymous login, destination is ignored
let call = client.newInvite(
callerName: "User",
callerNumber: "user",
destinationNumber: "ai-assistant", // Ignored
callId: UUID()
)
let cancellable = client.aiAssistantManager.subscribeToTranscriptUpdates { transcripts in
for item in transcripts {
print("\(item.role): \(item.content)")
// role: "user" or "assistant"
}
}
let success = client.sendAIAssistantMessage("Hello, can you help me?")
class MyLogger: TxLogger {
func log(level: LogLevel, message: String) {
// Send to your logging service
MyAnalytics.log(level: level, message: message)
}
}
let txConfig = TxConfig(
sipUser: sipUser,
password: password,
logLevel: .all,
customLogger: MyLogger()
)
| Issue | Solution |
|---|---|
| No audio | Ensure microphone permission granted |
| Push not working | Verify APNS certificate in Telnyx Portal |
| CallKit crash on iOS 13+ | Must report incoming call to CallKit |
| Audio routing issues | Use enableAudioSession/disableAudioSession in CXProviderDelegate |
| Login fails | Verify SIP credentials in Telnyx Portal |
references/webrtc-server-api.md has the server-side WebRTC API — credential creation, token generation, and push notification setup. You MUST read it when setting up authentication or push notifications.
CLASS
TxClientpublic class TxClient
The TelnyxRTC client connects your application to the Telnyx backend,
enabling you to make outgoing calls and handle incoming calls.
// Initialize the client
extension ViewController: TxClientDelegate {
enableAudioSession(audioSession:)public func enableAudioSession(audioSession: AVAudioSession)
Enables and configures the audio session for a call. This method sets up the appropriate audio configuration and activates the session.
provider(_:didActivate:) callback
to properly handle audio routing when using CallKit integration.Example usage:
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
print("provider:didActivateAudioSession:")
self.telnyxClient.enableAudioSession(audioSession: audioSession)
}
Parameters
| Name | Description |
|---|---|
| audioSession | The AVAudioSession instance to configure |
disableAudioSession(audioSession:)public func disableAudioSession(audioSession: AVAudioSession)
Disables and resets the audio session. This method cleans up the audio configuration and deactivates the session.
provider(_:didDeactivate:) callback
to properly clean up audio resources when using CallKit integration.Example usage:
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
print("provider:didDeactivateAudioSession:")
self.telnyxClient.disableAudioSession(audioSession: audioSession)
}
Parameters
| Name | Description |
|---|---|
| audioSession | The AVAudioSession instance to reset |
init()public init()
TxClient has to be instantiated.
deinitdeinit
Deinitializer to ensure proper cleanup of resources
connect(txConfig:serverConfiguration:)public func connect(txConfig: TxConfig,
serverConfiguration: TxServerConfiguration = TxServerConfiguration()) throws
Connects to the iOS cloglient to the Telnyx signaling server using the desired login credentials.
signaling server and TURN/ STUN servers. As default we use the internal Telnyx Production servers.Parameters
| Name | Description |
|---|---|
| txConfig | The desired login credentials. See TxConfig docummentation for more information. |
| serverConfiguration | (Optional) To define a custom signaling server and TURN/ STUN servers. As default we use the internal Telnyx Production servers. |
disconnect()public func disconnect()
Disconnects the TxClient from the Telnyx signaling server.
isConnected()public func isConnected() -> Bool
To check if TxClient is connected to Telnyx server.
true if TxClient socket is connected, false otherwise.answerFromCallkit(answerAction:customHeaders:debug:)public func answerFromCallkit(answerAction: CXAnswerCallAction,
customHeaders: [String:String] = [:],
debug: Bool = false)
Answers an incoming call from CallKit and manages the active call flow.
This method should be called from the CXProviderDelegate's provider(_:perform:) method
when handling a CXAnswerCallAction. It properly integrates with CallKit to answer incoming calls.
extension CallKitProvider: CXProviderDelegate {
endCallFromCallkit(endAction:callId:)public func endCallFromCallkit(endAction: CXEndCallAction,
callId: UUID? = nil)
To end and control callKit active and conn
disablePushNotifications()public func disablePushNotifications()
To disable push notifications for the current user
getSessionId()public func getSessionId() -> String
Get the current session ID after logging into Telnyx Backend.
anonymousLogin(targetId:targetType:targetVersionId:userVariables:reconnection:serverConfiguration:)public func anonymousLogin(
targetId: String,
targetType: String = "ai_assistant",
targetVersionId: String? = nil,
userVariables: [String: Any] = [:],
reconnection: Bool = false,
serverConfiguration: TxServerConfiguration = TxServerConfiguration()
)
Performs an anonymous login to the Telnyx backend for AI assistant connections. This method allows connecting to AI assistants without traditional authentication.
If the socket is already connected, the anonymous login message is sent immediately. If not connected, the socket connection process is started, and the anonymous login message is sent once the connection is established.
Parameters
| Name | Description |
|---|---|
| targetId | The target ID for the AI assistant |
| targetType | The target type (defaults to “ai_assistant”) |
| targetVersionId | Optional target version ID |
| userVariables | Optional user variables to include in the login |
| reconnection | Whether this is a reconnection attempt (defaults to false) |
| serverConfiguration | Server configuration to use for connection (defaults to TxServerConfiguration()) |
sendRingingAck(callId:)public func sendRingingAck(callId: String)
Send a ringing acknowledgment message for a specific call
Parameters
| Name | Description |
|---|---|
| callId | The call ID to acknowledge |
sendAIAssistantMessage(_:)public func sendAIAssistantMessage(_ message: String) -> Bool
Send a text message to AI Assistant during active call (mixed-mode communication)
Parameters
| Name | Description |
|---|---|
| message | The text message to send to AI assistant |
sendAIAssistantMessage(_:base64Images:imageFormat:)public func sendAIAssistantMessage(_ message: String, base64Images: [String]?, imageFormat: String = "jpeg") -> Bool
Send a text message with multiple Base64 encoded images to AI Assistant during active call
Parameters
| Name | Description |
|---|---|
| message | The text message to send to AI assistant |
| base64Images | Optional array of Base64 encoded image data (without data URL prefix) |
| imageFormat | Image format (jpeg, png, etc.). Defaults to “jpeg” |
CLASS
Callpublic class Call
A Call represents an audio or video communication session between two endpoints: WebRTC Clients, SIP clients, or phone numbers. The Call object manages the entire lifecycle of a call, from initiation to termination, handling both outbound and inbound calls.
A Call object is created in two scenarios:
// Initialize the client
class CallHandler: TxClientDelegate {
// Access local audio tracks for visualization
if let localStream = call.localStream {
let audioTracks = localStream.audioTracks
// Use audio tracks for waveform visualization
}
remoteStreampublic var remoteStream: RTCMediaStream?
The remote media stream containing audio and/or video tracks received from the remote party. This stream represents the media being received from the other participant in the call. Can be used for audio visualization, remote video display, or other media processing.
// Access remote audio tracks for visualization
if let remoteStream = call.remoteStream {
let audioTracks = remoteStream.audioTracks
// Use audio tracks for waveform visualization
}
STRUCT
TxConfigpublic struct TxConfig
This structure is intended to used for Telnyx SDK configurations.
init(sipUser:password:pushDeviceToken:ringtone:ringBackTone:pushEnvironment:logLevel:customLogger:reconnectClient:debug:forceRelayCandidate:enableQualityMetrics:sendWebRTCStatsViaSocket:reconnectTimeOut:useTrickleIce:enableCallReports:callReportInterval:callReportLogLevel:callReportMaxLogEntries:)public init(sipUser: String, password: String,
pushDeviceToken: String? = nil,
ringtone: String? = nil,
ringBackTone: String? = nil,
pushEnvironment: PushEnvironment? = nil,
logLevel: LogLevel = .none,
customLogger: TxLogger? = nil,
reconnectClient: Bool = true,
debug: Bool = false,
forceRelayCandidate: Bool = false,
enableQualityMetrics: Bool = false,
sendWebRTCStatsViaSocket: Bool = false,
reconnectTimeOut: Double = DEFAULT_TIMEOUT,
useTrickleIce: Bool = false,
enableCallReports: Bool = true,
callReportInterval: TimeInterval = 5.0,
callReportLogLevel: String = "debug",
callReportMaxLogEntries: Int = 1000
)
Constructor for the Telnyx SDK configuration using SIP credentials.
.none)Parameters
| Name | Description |
|---|---|
| sipUser | The SIP username for authentication |
| password | The password associated with the SIP user |
| pushDeviceToken | (Optional) The device’s push notification token, required for receiving inbound call notifications |
| ringtone | (Optional) The audio file name to play for incoming calls (e.g., “my-ringtone.mp3”) |
| ringBackTone | (Optional) The audio file name to play while making outbound calls (e.g., “my-ringbacktone.mp3”) |
| pushEnvironment | (Optional) The push notification environment (production or debug) |
| logLevel | (Optional) The verbosity level for SDK logs (defaults to .none) |
| customLogger | (Optional) Custom logger implementation for handling SDK logs. If not provided, the default logger will be used |
| reconnectClient | (Optional) Whether the client should attempt to reconnect automatically. Default is true. |
| debug | (Optional) Enables WebRTC communication statistics reporting to Telnyx servers. Default is false. |
| forceRelayCandidate | (Optional) Controls whether the SDK should force TURN relay for peer connections. Default is false. |
| enableQualityMetrics | (Optional) Controls whether the SDK should deliver call quality metrics. Default is false. |
| sendWebRTCStatsViaSocket | (Optional) Whether to send WebRTC statistics via socket to Telnyx servers. Default is false. |
| reconnectTimeOut | (Optional) Maximum time in seconds the SDK will attempt to reconnect a call after network disruption. Default is 60 seconds. |
| useTrickleIce | (Optional) Controls whether the SDK should use trickle ICE for WebRTC signaling. Default is false. |
| enableCallReports | (Optional) Enable automatic call quality reporting to voice-sdk-proxy. Default is true. |
| callReportInterval | (Optional) Interval in seconds for collecting call statistics. Default is 5.0. |
| callReportLogLevel | (Optional) Minimum log level to capture for call reports. Default is “debug”. |
| callReportMaxLogEntries | (Optional) Maximum number of log entries to buffer per call. Default is 1000. |
init(token:pushDeviceToken:ringtone:ringBackTone:pushEnvironment:logLevel:customLogger:reconnectClient:debug:forceRelayCandidate:enableQualityMetrics:sendWebRTCStatsViaSocket:reconnectTimeOut:useTrickleIce:enableCallReports:callReportInterval:callReportLogLevel:callReportMaxLogEntries:)public init(token: String,
pushDeviceToken: String? = nil,
ringtone: String? = nil,
ringBackTone: String? = nil,
pushEnvironment: PushEnvironment? = nil,
logLevel: LogLevel = .none,
customLogger: TxLogger? = nil,
reconnectClient: Bool = true,
debug: Bool = false,
forceRelayCandidate: Bool = false,
enableQualityMetrics: Bool = false,
sendWebRTCStatsViaSocket: Bool = false,
reconnectTimeOut: Double = DEFAULT_TIMEOUT,
useTrickleIce: Bool = false,
enableCallReports: Bool = true,
callReportInterval: TimeInterval = 5.0,
callReportLogLevel: String = "debug",
callReportMaxLogEntries: Int = 1000
)
Constructor for the Telnyx SDK configuration using JWT token authentication.
.none)Parameters
| Name | Description |
|---|---|
| token | JWT token generated from https://developers.telnyx.com/docs/v2/webrtc/quickstart |
| pushDeviceToken | (Optional) The device’s push notification token, required for receiving inbound call notifications |
| ringtone | (Optional) The audio file name to play for incoming calls (e.g., “my-ringtone.mp3”) |
| ringBackTone | (Optional) The audio file name to play while making outbound calls (e.g., “my-ringbacktone.mp3”) |
| pushEnvironment | (Optional) The push notification environment (production or debug) |
| logLevel | (Optional) The verbosity level for SDK logs (defaults to .none) |
| customLogger | (Optional) Custom logger implementation for handling SDK logs. If not provided, the default logger will be used |
| reconnectClient | (Optional) Whether the client should attempt to reconnect automatically. Default is true. |
| debug | (Optional) Enables WebRTC communication statistics reporting to Telnyx servers. Default is false. |
| forceRelayCandidate | (Optional) Controls whether the SDK should force TURN relay for peer connections. Default is false. |
| enableQualityMetrics | (Optional) Controls whether the SDK should deliver call quality metrics. Default is false. |
| sendWebRTCStatsViaSocket | (Optional) Whether to send WebRTC statistics via socket to Telnyx servers. Default is false. |
| reconnectTimeOut | (Optional) Maximum time in seconds the SDK will attempt to reconnect a call after network disruption. Default is 60 seconds. |
| useTrickleIce | (Optional) Controls whether the SDK should use trickle ICE for WebRTC signaling. Default is false. |
| enableCallReports | (Optional) Enable automatic call quality reporting to voice-sdk-proxy. Default is true. |
| callReportInterval | (Optional) Interval in seconds for collecting call statistics. Default is 5.0. |
| callReportLogLevel | (Optional) Minimum log level to capture for call reports. Default is “debug”. |
| callReportMaxLogEntries | (Optional) Maximum number of log entries to buffer per call. Default is 1000. |
validateParams()public func validateParams() throws
Validate if TxConfig parameters are valid