Provides an interface to Twilio's Programmable Voice SDK to allow voice-over-IP (VoIP) calling into your Flutter applications. This plugin was taken from the original flutter_twilio_voice, as it seems that plugin is no longer maitained, this one is.
- Receive and place calls from iOS devices, uses callkit to receive calls.
- Receive and place calls from Android devices, uses custom UI to receive calls.
As iOS has CallKit, an Apple provided UI for answering calls, there is no default UI for android to receive calls, for this reason a default UI was made. To increase customization, the UI will use a splash_icon.png registered on your res/drawable folder. I havent found a way to customize colors, if you find one, please submit a pull request.
The plugin was separated into two classes, the
TwilioVoice.instance.call, the first one is in charge of general configuration and the second one is in charge of managing calls.
Register iOS capabilities
- Add Audio and Voice over IP in background modes
Setting the tokens
TwilioVoice.instance.setTokens as soon as your app starts.
accessTokenprovided from your server, you can see an example cloud function here.
deviceTokenis automatically handled on iOS, for android you need to pass a FCM token.
TwilioVoice.instance.unregister to unregister from Twilio, if no access token is passed, it will use the token provided in
setTokens at the same session.
As incomming call UI is shown in background and the App can even be closed when receiving the calls, you can map call identifiers such as
firebaseAuth userIds to real names, this operation must be done before actially receiving the call. So if you have a chat app, and know the members names, register them so when they call, the call UI can display their names and not their userIds.
Registering a client
TwilioVoice.instance.registerClient(String clientId, String clientName)
Unegistering a client
You can also set a dafault caller, such as "unknown number" or "chat friend" in case a call comes in from an unregistered client.
TwilioVoice.instance.callEventsListener to receive events from the TwilioSDK such as call events and logs, it is a broadcast so you can listen to it on different parts of your app.
The events sent are the following
Make a Call
from your own identifier
to the id you want to call
extraOptions to pass additional variables to your server callback function.
await TwilioVoice.instance.calls.place(from:myId, to: clientId, extraOptions) ;
Mute a Call
To receive and place calls you need Microphone permisisons, register the micropohone permission in your info.plist for iOS.
You can use
TwilioVoice.instance.requestMicAccess to check and request the permission. Permissions is also automatically requested when receiving a call.
Background calls (Android only on some devices)
Xiami devices, and maybe others, need a spetial permission to receive background calls. use
TwilioVoice.instance.requiresBackgroundPermissions to check if your device requires a special permission, if it does, show a rationale explaining the user why you need the permisison. Finally call
TwilioVoice.instance.requestBackgroundPermissions which will take the user to the App Settings page to enable the permission.