Classes

The following classes are available globally.

  • Manager class for handling AI Assistant functionality This class manages AI assistant connections, message handling, and state management

    See more

    Declaration

    Swift

    public class AIAssistantManager

Custom Publisher Classes (iOS 12.0 Compatibility)

  • Custom publisher for iOS 12.0 compatibility (replaces Combine’s Publisher)

    See more

    Declaration

    Swift

    public class TranscriptPublisher<T>
  • Custom cancellable for iOS 12.0 compatibility (replaces Combine’s AnyCancellable)

    See more

    Declaration

    Swift

    public class TranscriptCancellable
  • The TelnyxRTC client connects your application to the Telnyx backend, enabling you to make outgoing calls and handle incoming calls.

    Examples

    Connect and login:

    // Initialize the client
    let telnyxClient = TxClient()
    
    // Register to get SDK events
    telnyxClient.delegate = self
    
    // Setup yor connection parameters.
    
    // Set the login credentials and the ringtone/ringback configurations if required.
    // Ringtone / ringback tone files are not mandatory.
    // You can user your sipUser and password
    let txConfigUserAndPassowrd = TxConfig(sipUser: sipUser,
                                           password: password,
                                           ringtone: "incoming_call.mp3",
                                           ringBackTone: "ringback_tone.mp3",
                                           //You can choose the appropriate verbosity level of the SDK.
                                           //Logs are disabled by default
                                           logLevel: .all)
    
    // Use a JWT Telnyx Token to authenticate (recommended)
    let txConfigToken = TxConfig(token: "MY_JWT_TELNYX_TOKEN",
                                 ringtone: "incoming_call.mp3",
                                 ringBackTone: "ringback_tone.mp3",
                                 //You can choose the appropriate verbosity level of the SDK. Logs are disabled by default
                                 logLevel: .all)
    
    do {
       // Connect and login
       // Use `txConfigUserAndPassowrd` or `txConfigToken`
       try telnyxClient.connect(txConfig: txConfigToken)
    } catch let error {
       print("ViewController:: connect Error \(error)")
    }
    
    // You can call client.disconnect() when you're done.
    Note: you need to relese the delegate manually when you are done.
    
    // Disconnecting and Removing listeners.
    telnyxClient.disconnect();
    
    // Release the delegate
    telnyxClient.delegate = nil
    
    

    Listen TxClient delegate events.

    extension ViewController: TxClientDelegate {
    
        func onRemoteCallEnded(callId: UUID) {
            // Call has been removed internally.
        }
    
        func onSocketConnected() {
           // When the client has successfully connected to the Telnyx Backend.
        }
    
        func onSocketDisconnected() {
           // When the client from the Telnyx backend
        }
    
        func onClientError(error: Error)  {
            // Something went wrong.
        }
    
        func onClientReady()  {
           // You can start receiving incoming calls or
           // start making calls once the client was fully initialized.
        }
    
        func onSessionUpdated(sessionId: String)  {
           // This function will be executed when a sessionId is received.
        }
    
        func onIncomingCall(call: Call)  {
           // Someone is calling you.
        }
    
        // You can update your UI from here base on the call states.
        // Check that the callId is the same as your current call.
        func onCallStateUpdated(callState: CallState, callId: UUID) {
            DispatchQueue.main.async {
                switch (callState) {
                case .CONNECTING:
                    break
                case .RINGING:
                    break
                case .NEW:
                    break
                case .ACTIVE:
                    break
                case .DONE:
                    break
                case .HELD:
                    break
                }
            }
        }
    }
    
    See more

    Declaration

    Swift

    public class TxClient
  • Undocumented

    See more

    Declaration

    Swift

    public class FileLogger
  • Utility class for calculating Mean Opinion Score (MOS) and call quality metrics

    See more

    Declaration

    Swift

    public class MOSCalculator
  • Default implementation of TxLogger that prints to console

    See more

    Declaration

    Swift

    public class TxDefaultLogger : TxLogger
  • 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:

    1. When you initiate a new outbound call using TxClient’s newCall method
    2. When you receive an inbound call through the TxClientDelegate’s onIncomingCall callback

    Key Features

    • Audio and video call support
    • Call state management (NEW, CONNECTING, RINGING, ACTIVE, HELD, DONE)
    • Mute/unmute functionality
    • DTMF tone sending
    • Custom headers support for both INVITE and ANSWER messages
    • Call statistics reporting when debug mode is enabled

    Examples

    Creating an Outbound Call:

       // Initialize the client
       self.telnyxClient = TxClient()
       self.telnyxClient?.delegate = self
    
       // Connect the client (see TxClient documentation for connection options)
       self.telnyxClient?.connect(....)
    
       // Create and initiate a call
       self.currentCall = try self.telnyxClient?.newCall(
           callerName: "John Doe",           // The name to display for the caller
           callerNumber: "155531234567",     // The caller's phone number
           destinationNumber: "18004377950", // The target phone number or SIP URI
           callId: UUID.init(),              // Unique identifier for the call
           clientState: nil,                 // Optional client state information
           customHeaders: [:]                // Optional custom SIP headers
       )
    

    Handling an Incoming Call:

    class CallHandler: TxClientDelegate {
        var activeCall: Call?
    
        func initTelnyxClient() {
            let client = TxClient()
            client.delegate = self
            client.connect(....)
        }
    
        func onIncomingCall(call: Call) {
            // Store the call reference
            self.activeCall = call
    
            // Option 1: Auto-answer the call
            call.answer()
    
            // Option 2: Answer with custom headers
            call.answer(customHeaders: ["X-Custom-Header": "Value"])
    
            // Option 3: Reject the call
            // call.hangup()
        }
    }
    
    See more

    Declaration

    Swift

    public class Call