TxClientDelegate
public protocol TxClientDelegate : AnyObject
The TxClientDelegate protocol defines methods for receiving events and updates from a TxClient instance. Implement this protocol to handle various states and events in your WebRTC-enabled application, including connection status, call state changes, and push notifications.
Usage Example:
class CallHandler: TxClientDelegate {
func onSocketConnected() {
print("Connected to Telnyx backend")
}
func onIncomingCall(call: Call) {
// Handle incoming call
call.answer()
}
// Implement other required methods...
}
-
Called when the WebSocket connection to Telnyx’s backend is established. This indicates a successful network connection, but the client may not be fully ready yet. Wait for
onClientReadybefore initiating calls.Declaration
Swift
func onSocketConnected() -
Called when the WebSocket connection to Telnyx’s backend is lost or closed. The client will automatically attempt to reconnect unless explicitly disconnected.
Declaration
Swift
func onSocketDisconnected() -
Called when an error occurs in the TxClient.
Declaration
Swift
func onClientError(error: Error)Parameters
errorThe error that occurred. Check the error type and message for details. Common errors include authentication failures and network connectivity issues.
-
Called when the client has successfully connected AND authenticated. The client is now ready to make and receive calls. This is the appropriate time to enable UI elements for calling functionality.
Declaration
Swift
func onClientReady() -
Called when push notification status changes for the current user.
Declaration
Swift
func onPushDisabled(success: Bool, message: String)Parameters
successWhether the push notification operation succeeded
messageDescriptive message about the operation result
-
Called when the client’s session is updated, typically after a reconnection.
Declaration
Swift
func onSessionUpdated(sessionId: String)Parameters
sessionIdThe new session identifier for the connection. Store this ID if you need to track or debug connection issues.
-
Called whenever a call’s state changes (e.g., ringing, answered, ended).
Declaration
Swift
func onCallStateUpdated(callState: CallState, callId: UUID)Parameters
callStateThe new state of the call (NEW, CONNECTING, RINGING, ACTIVE, HELD, DONE)
callIdThe unique identifier of the affected call Use this to update your UI to reflect the current call state.
-
Called when a new incoming call is received.
Declaration
Swift
func onIncomingCall(call: Call)Parameters
callThe Call object representing the incoming call. You can use this object to answer or reject the call.
-
Called when a remote party ends the call.
Declaration
Swift
func onRemoteCallEnded(callId: UUID, reason: CallTerminationReason?)Parameters
callIdThe unique identifier of the ended call.
reasonOptional termination reason containing details about why the call ended. Use this to clean up any call-related UI elements or state and potentially display error messages.
-
Called when a push notification triggers an incoming call.
Declaration
Swift
func onPushCall(call: Call)Parameters
callThe Call object created from the push notification data. This is specifically for handling calls that arrive via push notifications when the app is in the background.