twilio_voice_flutter
语音 SDK,可让您在 Flutter 应用程序中添加基于互联网的语音通话(VoIP)功能。
语音 SDK,可让您在 Flutter 应用程序中添加基于互联网的语音通话(VoIP)功能。
{"sdk":"flutter"}{"sdk":"flutter"}^1.1.0^2.1.8^2.0.7{"sdk":"flutter"}^5.0.0以下为英文项目原文快照,最新内容请访问 GitHub。
The twilio_voice_flutter package simplifies integration with Twilio's Programmable Voice SDK, enabling VoIP calling within your Flutter apps. It supports both iOS and Android, offering an easy-to-use API for managing calls. Ideal for customer service, communication, or any app needing real-time voice, it leverages Twilio's reliable infrastructure to deliver high-quality VoIP features.
https://raw.githubusercontent.com/DevCodeSpace/twilio_voice_flutter/main/assets/banner1.pngAdd dependency to your pubspec.yaml file & run Pub get
dependencies:
twilio_voice_flutter: ^0.0.6
And import package into your class file
import 'package:twilio_voice_flutter/twilio_voice_flutter.dart';
⚠️ This plugin requires Firebase setup for Twilio voice calls! It uses FCM tokens for handling calls on Android 📲 and VoIP notifications for iOS 📞. Ensure both platforms are properly configured for smooth call functionality. ⚠️
To integrate the Twilio Voice plugin into your Android project, follow these steps:
Open your project's AndroidManifest.xml file.
Add the following service declaration inside the <application> tag:
<application>
...
<service
android:name="com.twilio.voice.flutter.fcm.VoiceFirebaseMessagingService"
android:exported="false"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
...
</application>
To configure your iOS project to support VoIP calls, follow these steps:
Open your project in Xcode.
Select your project from the Project Navigator.
Go to the Signing & Capabilities tab.
Enable the following Background Modes:
Ensure that your Info.plist file includes the required keys:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>voip</string>
</array>
This plugin supports Twilio voice calls for both Android and iOS. To generate the access token and enable Twilio calls, follow the steps in the official Twilio repositories:
These repositories provide detailed instructions for generating access tokens and making voice calls through Twilio on both Android and iOS platforms. ⚡ Make sure to follow the steps outlined to successfully integrate Twilio voice functionality into your application.
The setTwilioToken function is used to register a user's identity with Twilio Voice using the provided access token. This function handles the retrieval of the Firebase Cloud Messaging (FCM) token on Android devices and registers the user with Twilio Voice.
static Future<bool> setTwilioToken(String identity, String accessToken) async {
try{
String accessToken = await _getAccessToken(identity);
if (Platform.isAndroid) {
String? fcmToken = await FirebaseMessaging.instance.getToken() ?? "";
await TwilioVoiceFlutter.register(
identity: identity, accessToken: accessToken, fcmToken: fcmToken);
} else {
await TwilioVoiceFlutter.register(
identity: identity, accessToken: accessToken, fcmToken: "");
}
return true;
}catch(_){
return false;
}
}
🔗 Visit example for more info... 😊
The Twilio Voice Plugin for Flutter enables seamless integration of voice-over-IP (VoIP) calling into your Flutter applications. Below are the key features supported by this plugin:
makeCall method, with the ability to pass custom call data.toggleMute method. Check if the call is currently muted with the isMuted method.toggleSpeaker. Verify the current audio route with isSpeaker.Info.plist accordingly.sendDigits method.UserDefaults on iOS to maintain state across app sessions.With these features, the Twilio Voice Plugin provides a robust foundation for integrating voice communication into your Flutter applications, supporting a wide range of use cases from customer support to in-app communication.
register():
Registers the device with Twilio using the access token and device token for VoIP push notifications.
unregister():
Unregisters the device from Twilio VoIP push notifications, removing the access token and device token.
makeCall(String to):
Initiates a voice call to the specified recipient. If an active call exists, it returns an error.
toggleMute():
Toggles the mute status of the ongoing call. Notifies the Flutter side of the change.
isMuted():
Returns the current mute status of the ongoing call.
toggleSpeaker():
Toggles the speaker mode during an ongoing call. Notifies the Flutter side of the change.
isSpeaker() -> Bool:
Checks if the speaker mode is currently active.
hangUp():
Ends the current call. If no active call exists, it clears the call-related data.
activeCall():
Returns details of the active call if one exists.
sendDigits(String digits):
Sends DTMF digits during an active call.
https://raw.githubusercontent.com/DevCodeSpace/twilio_voice_flutter/main/assets/contributors.png