Classes
The following classes are available globally.
-
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.
See moreextension 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 } } } }
Declaration
Swift
public class TxClient
-
Undocumented
See moreDeclaration
Swift
public class FileLogger
-
Undocumented
Declaration
Swift
public class StatsMessage
-
A Call is the representation of an audio or video call between two WebRTC Clients, SIP clients or phone numbers. The call object is created whenever a new call is initiated, either by you or the remote caller. You can access and act upon calls initiated by a remote caller by registering to TxClientDelegate of the TxClient
Examples:
Create a call:
// Create a client instance self.telnyxClient = TxClient() // Asign the delegate to get SDK events self.telnyxClient?.delegate = self // Connect the client (Check TxClient class for more info) self.telnyxClient?.connect(....) // Create the call and start calling self.currentCall = try self.telnyxClient?.newCall(callerName: "Caller name", callerNumber: "155531234567", // Destination is required and can be a phone number or SIP URI destinationNumber: "18004377950", callId: UUID.init())
Answer an incoming call:
See more//Init your client func initTelnyxClient() { // self.telnyxClient = TxClient() // Asign the delegate to get SDK events self.telnyxClient?.delegate = self // Connect the client (Check TxClient class for more info) self.telnyxClient?.connect(....) } extension ViewController: TxClientDelegate { //.... func onIncomingCall(call: Call) { //We are automatically answering any incoming call as an example, but //maybe you want to store a reference of the call, and answer the call after a button press. self.myCall = call.answer() } }
Declaration
Swift
public class Call