TelnyxClient class
Represents the main entry point for interacting with the Telnyx RTC SDK.
This class manages the WebSocket connection to the Telnyx backend, handles user authentication, and facilitates call creation and management. It provides methods to connect, disconnect, send and receive calls, and monitor the connection status.
Callbacks like onSocketMessageReceived and onSocketErrorReceived must be implemented to handle events and errors from the socket.
Constructors
- TelnyxClient.new()
- Default constructor for the TelnyxClient
Properties
- call → Call
-
The current instance of Call associated with this client.
no setter
-
calls
↔ Map<
String, Call> -
A map of all current calls, with the call ID as the key and the Call object as the value.
getter/setter pair
- currentWidgetSettings → WidgetSettings?
-
The current widget settings from AI conversation
no setter
- gatewayState ↔ String
-
The current gateway state for the socket connection
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- logger → CustomLogger
-
Get the custom logger for the SDK
no setter
- onSocketErrorReceived ↔ OnSocketErrorReceived
-
Callback for when the socket receives an error
getter/setter pair
- onSocketMessageReceived ↔ OnSocketMessageReceived
-
Callback for when the socket receives a message
getter/setter pair
- onTranscriptUpdate ↔ OnTranscriptUpdate?
-
Callback for when transcript updates occur
Note: this is only relevant for Assistant AI conversations
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sessid ↔ String
-
The current session ID related to this client
getter/setter pair
- storedCredential → CredentialConfig?
-
The stored CredentialConfig for the client - if no stored credential is present, this will be null
no setter
- storedToken → TokenConfig?
-
The stored TokenConfig for the client - if no stored token is present, this will be null
no setter
-
transcript
→ List<
TranscriptItem> -
Gets the current conversation transcript
no setter
- txSocket ↔ TxSocket
-
The current instance of TxSocket associated with this client
getter/setter pair
Methods
-
acceptCall(
IncomingInviteParams invite, String callerName, String callerNumber, String clientState, {bool isAttach = false, Map< String, String> customHeaders = const {}, List<AudioCodec> ? preferredCodecs, bool debug = false}) → Call - Accepts an incoming call.
-
activeCalls(
) → Map< String, Call> - The current active calls being handled by the TelnyxClient instance The Map key is the callId String and the value is the Call instance
-
anonymousLogin(
{required String targetId, String targetType = 'ai_assistant', String? targetVersionId, Map< String, dynamic> ? userVariables, bool reconnection = false, LogLevel logLevel = LogLevel.none}) → Future<void> - Performs an anonymous login to the Telnyx backend for AI assistant connections.
-
clearTranscript(
) → void - Clears the conversation transcript
-
connect(
) → void - Connects to the WebSocket with a previously provided Config
-
connectWithCredential(
CredentialConfig credentialConfig) → void - Connects to the WebSocket using the provided CredentialConfig
-
connectWithToken(
TokenConfig tokenConfig) → void -
Connects to the WebSocket using the provided
tokenConfig
-
credentialLogin(
CredentialConfig config) → void -
Uses the provided
config
to send a credential login message to the Telnyx backend. If successful, the gateway registration process will start. -
disablePushNotifications(
) → void - Disables push notifications for the currently authenticated user.
-
disconnect(
) → void - Closes the socket connection, effectively logging the user out.
-
disconnectWithCallBack(
OnCloseCallback? closeCallback) → void - Closes the socket connection and provides a callback upon completion.
-
getCallOrNull(
String callId) → Call? -
Provides the current Call instance associated with the
callId
otherwise returns null -
getForceRelayCandidate(
) → bool - Returns the forceRelayCandidate setting from the current config
-
getGatewayStatus(
) → String - Returns the current Gateway state for the socket connection
-
getSupportedAudioCodecs(
) → List< AudioCodec> - Gets the list of supported audio codecs available on the client
-
handlePushNotification(
PushMetaData pushMetaData, CredentialConfig? credentialConfig, TokenConfig? tokenConfig) → void - Handles an incoming push notification to initiate a call flow.
-
isConnected(
) → bool - Returns whether or not the client is connected to the socket connection
-
isDebug(
) → bool - Returns whether or not debug is enabled for the client
-
newInvite(
String callerName, String callerNumber, String destinationNumber, String clientState, {Map< String, String> customHeaders = const {}, List<AudioCodec> ? preferredCodecs, bool debug = false}) → Call - Creates and sends a new call invitation.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onCallStateChangedToActive(
String? callId) → void - Called when a call state changes to active This will cancel any reconnection timer for the call
-
setCustomLogger(
CustomLogger logger) → void - Set the custom logger for the SDK
-
setLogLevel(
LogLevel level) → void - Set or adjust the log level for the SDK
-
tokenLogin(
TokenConfig config) → void -
Uses the provided
config
to send a token login message to the Telnyx backend. If successful, the gateway registration process will start. -
toString(
) → String -
A string representation of this object.
inherited
-
updateCall(
Call call) → void -
Update the Call instance associated with the
callId
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
clearPushMetaData(
) → void - Clears the push metadata for the client
-
getPushData(
) → Future< Map< String, dynamic> ?> - Gets the push metadata for the client
-
setPushMetaData(
Map< String, dynamic> pushMetaData, {bool isAnswer = false, bool isDecline = false}) → void -
Sets the push metadata for the client and saves it to the shared preferences
The
isAnswer
flag is used to determine if the push notification indicates that we should answer the pending invite TheisDecline
flag is used to determine if the push notification indicates that we should decline the pending invite