-
- All Implemented Interfaces:
-
com.twilio.voice.EventPublisher.EventPublisherListener
public class Call extends InternalCallThe Call class represents a signaling and media session between the host device and Twilio infrastructure. Calls can represent an outbound call initiated from the SDK via
{@code * Voice.connect(...)}or an incoming call accepted via a CallInvite. Devices that initiate an outbound call represent the caller and devices that receive a CallInvite represent the callee.The lifecycle of a call differs for the caller and the callee. Making or accepting a call requires a Call.Listener which provides Call state changes defined in . The Call.State can be obtained at any time by calling .
A subset of Android devices provide an OpenSLES implementation. Although more efficient, the use of OpenSLES occasionally results in echo. As a result, the Voice SDK disables OpenSLES by default for both incoming and outgoing Calls unless explicitly enabled. To enable OpenSLES execute the following before invoking connect or accept:
{@code tvo.webrtc.voiceengine.WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(false)}The following table provides expected call sequences for common scenarios from the caller perspective. The caller scenario sequences are affected by the
{@code answerOnBridge}flag provided in the{@code Dial}verb of your TwiML application associated with the client. If the{@code answerOnBridge}flag is{@code false}, which is the default, the callback will be emitted immediately after . If the{@code answerOnBridge}flag is{@code true}this will cause the call to emit the onConnected callback only until the call is answered by the callee. See the Answer on Bridge documentation for more details on how to use it with the{@code Dial}TwiML verb.The following table provides expected call sequences for common scenarios from the callee perspective:
It is important to call the disconnect method to terminate the call. Not calling disconnect results in leaked native resources and may lead to an out-of-memory crash. If the call is disconnected by the caller, callee, or Twilio, the SDK will automatically free native resources. However, disconnect is an idempotent operation so it is best to call this method when you are certain your application no longer needs the object.
It is strongly recommended that Call instances are created and accessed from a single application thread. Accessing an instance from multiple threads may cause synchronization problems. Listeners are called on the thread that created the Call instance, unless the thread that created the Call instance does not have a Looper. In that case, the listener will be called on the application's main thread.
An ongoing call will automatically switch to a more preferred network type if one becomes available. The following are the network types listed in preferred order: ETHERNET, LOOPBACK, WIFI, VPN, and CELLULAR. For example, if a WIFI network becomes available whilst in a call that is using CELLULAR data, the call will automatically switch to using the WIFI network.
Media and signaling reconnections are handled independently. As a result, it is possible that a single network change event produces consecutive `onReconnecting()` and `onReconnected()` callbacks. For example, a network change may result in the following callback sequence.
- onReconnecting() with `CallException` with `EXCEPTION_SIGNALING_CONNECTION_DISCONNECTED` error code
- onReconnected()
- onReconnecting() with `CallException` with `EXCEPTION_MEDIA_CONNECTION_FAILED` error code
- onReconnected()
Note SDK will always raise a `onReconnecting()` callback followed by a `onReconnected()` callback when reconnection is successful. During the reconnecting state operations such as , mute, or sendDigits will result in undefined behavior. When building applications, the recommended practice is to show a UI update when the Call enters reconnecting regardless of the cause, and then clear the UI update once the call has reconnected or disconnected.
Insights :
The following connection events are reported to Insights during a Call
The following ICE candidate event is reported to Insights during a Call
The following ICE connection state events are reported to Insights during a Call
The following ICE gathering state events are reported to Insights during a Call
The following signaling state events are reported to Insights during a Call
The following peer connection state events are reported to Insights during a Call
The following network quality warning and network quality warning cleared events are reported to Insights during a Call
The following audio level warning and audio level warning cleared events are reported to Insights during a Call
The following feedback events are reported to Insights during a Call
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumCall.ScoreAn enum representing call quality score.
public enumCall.IssueAn enum representing issue type associated with a call.
public enumCall.CallQualityWarningpublic enumCall.StateAn enum describing the possible states of a Call.
public interfaceCall.ListenerCall.Listener interface defines a set of callbacks for events related to call.
public interfaceCall.CallMessageListenerCall.CallMessageListener interface defines a set of callbacks when CallMessage isreceived or when the result of outbound CallMessage request is available.
-
Method Summary
Modifier and Type Method Description StringgetFrom()Returns the caller information when available. StringgetTo()Returns the callee information when available. StringgetSid()Returns the call sid. Call.StategetState()Returns the current state of the call. synchronized voidgetStats(@NonNull() StatsListener statsListener)Retrieve stats for all media tracks and notify StatsListener via calling thread. Set<Call.CallQualityWarning>getCallQualityWarnings()Get current set of Call quality warnings. voidpostFeedback(@NonNull() Call.Score score, @NonNull() Call.Issue issue)Posts the feedback collected for this call to Twilio. synchronized voidmute(boolean mute)Mutes or unmutes the audio input. synchronized voidsendDigits(@NonNull() String digits)Sends a string of DTMF digits. synchronized voidhold(boolean hold)Holds or un-holds the audio. booleanisMuted()Reports whether the audio input is muted. booleanisOnHold()Reports whether the call is on hold. synchronized voiddisconnect()Disconnects the Call. StringsendMessage(CallMessage message)Sends a call message to endpoints that have subscribed for call messages. synchronized voidrelease()-
-
Method Detail
-
getFrom
@Nullable() String getFrom()
Returns the caller information when available. The from field is
{@code null}for an outgoingcall and may be{@code null}if it was not provided in the CallInvite for an incomingcall.
-
getTo
@Nullable() String getTo()
Returns the callee information when available. Returns null for an outgoing call.
-
getSid
@Nullable() String getSid()
Returns the call sid. The call sid is null until the call is in RINGING state.
-
getState
@NonNull() Call.State getState()
Returns the current state of the call.
Call is in CONNECTING state when it is made or accepted.
Call is in RINGING state when it is ringing.
Call transitions to CONNECTED state when connected to Twilio.
Call transitions to DISCONNECTED state when disconnected.
-
getStats
synchronized void getStats(@NonNull() StatsListener statsListener)
Retrieve stats for all media tracks and notify StatsListener via calling thread. Thecall needs to be in CONNECTED state for reports to be delivered.
- Parameters:
statsListener- listener that receives stats reports for all media tracks.
-
getCallQualityWarnings
Set<Call.CallQualityWarning> getCallQualityWarnings()
Get current set of Call quality warnings.
-
postFeedback
void postFeedback(@NonNull() Call.Score score, @NonNull() Call.Issue issue)
Posts the feedback collected for this call to Twilio. If `0` `Score` and `not-reported``Issue` are passed, Twilio will report feedback was not available for this call.
- Parameters:
score- - the call quality score.issue- - the issue type associated with the call.
-
mute
synchronized void mute(boolean mute)
Mutes or unmutes the audio input.
-
sendDigits
synchronized void sendDigits(@NonNull() String digits)
Sends a string of DTMF digits.
- Parameters:
digits- A string of digits to be sent.
-
hold
synchronized void hold(boolean hold)
Holds or un-holds the audio.
-
isMuted
boolean isMuted()
Reports whether the audio input is muted.
-
isOnHold
boolean isOnHold()
Reports whether the call is on hold.
-
disconnect
synchronized void disconnect()
Disconnects the Call.
Invoking disconnect will result in a subsequent onDisconnected being raised unless any of the following conditions are true:
- Disconnect was already called on the call object. In this case, only one will be raised
- The call is already DISCONNECTED
- The call has been cancelled. In this case, the application has already received aonCancelledCallInvite witha CancelledCallInvite with the same call SID of the call object
-
sendMessage
String sendMessage(CallMessage message)
Sends a call message to endpoints that have subscribed for call messages. The result will beraised to the Call.CallMessageListener provided as a connect option at the time ofconnection construction. Calling the `sendMessage` method without subscribing first willresult in an error in your Twilio developer console. Sending a call message with content sizethat exceeds 10 KB or sending more than 10 call messages within one minute will result in the onMessageFailure callback.When attempting to send a message larger than 10k, the error will not show in the developerconsole. A call message with content that does not match the content type will not result inthe onMessageFailure callback but will generate an error in your Twilio developer console. For example, a callmessage with content type "application/json" but with the content "Hello World", which is nota valid JSON object, will result in such error.
- Parameters:
message- The call message to send.
-
release
synchronized void release()
-
-
-
-