flutter_voip_kit_osato07 0.1.5
flutter_voip_kit_osato07: ^0.1.5 copied to clipboard
A comprehensive VoIP kit for Flutter enabling iOS CallKit/PushKit and Android ConnectionService/FCM.
Flutter VoIP Kit Template #
This project provides a "ready-to-use" implementation for cross-platform VoIP calls (Audio/Video) using Flutter, Firebase, and CallKit/ConnectionService.
🌟 Features #
- Library-based Architecture: Core logic is encapsulated in
packages/flutter_voip_kit_osato07. - iOS: Native
PKPushRegistryintegration for standard-compliant VoIP handling. - Android: High-priority FCM Data Message handling with full-screen intent support.
🛠 Prerequisites #
- Firebase Project: Create one at console.firebase.google.com.
- Apple Developer Account: Required for VoIP Certificates.
🍎 iOS Setup (Critical) #
VoIP on iOS requires precise configuration. One missed step will cause silent failures.
1. Xcode Capabilities #
Open ios/Runner.xcworkspace in Xcode. Select your target (Runner) -> Signing & Capabilities.
- + Capability -> Background Modes -> Check:
- ✅ Audio, AirPlay, and Picture in Picture
- ✅ Voice over IP
- ✅ Remote notifications
- + Capability -> Push Notifications (if not already added).
2. APNs Authentication Key (.p8) #
- Go to Apple Developer Console -> Keys.
- Create a new Key (+ button).
- Name it (e.g., "VoIP and Push Key") and check Apple Push Notifications service (APNs).
- Download the
.p8file. Keep it safe (you can only download it once). - Get your Key ID and Team ID from the console.
3. Connection to Backend (Two Options) #
You need to send VoIP pushes to APNs (Apple Push Notification service).
Option A: Using Firebase Cloud Messaging (Recommended)
If you rely on admin.messaging().send() in your Cloud Functions:
- Go to Firebase Console -> Project Settings -> Cloud Messaging -> Apple app configuration.
- Upload the APNs Authentication Key (.p8) you created in Step 2.
- You will need the Key ID and Team ID.
Option B: Direct APNs in Cloud Functions (Advanced)
If you want to read certificates directly in index.ts:
- Place your
voip_cert.p12(or key) insidefunctions/certs/. - Use a library like
node-apninstead offirebase-adminfor the iOS part.
The provided template currently uses Option A (Firebase Admin).// In functions/index.ts (Pseudocode) import * as apn from 'apn'; const apnProvider = new apn.Provider({ pfx: "certs/voip_cert.p12", production: true // true for TestFlight/AppStore }); // Send using apnProvider...
🤖 Android Setup #
1. Firebase Config #
- Download
google-services.jsonfrom Firebase Console. - Place it in:
android/app/google-services.json.
2. Permissions (Automated) #
The library flutter_voip_kit_osato07 automatically injects required permissions:
FOREGROUND_SERVICEWAKE_LOCKPOST_NOTIFICATIONSREAD_PHONE_STATE
You do NOT need to edit AndroidManifest.xml manually for these.
☁️ Backend (Cloud Functions) #
The functions/index.ts determines how calls are routed.
1. Key Logic (Simulating VoIP) #
We rely on Push Types to tell the OS this is a call.
- Android: We send a
datamessage with"callType": "voip_incoming". - iOS: We send an APNs payload with headers:
(Note:"headers": { "apns-push-type": "voip", "apns-priority": "10", "apns-topic": "com.your.bundle.id.voip" }.voipsuffix is often required depending on how you send it).
2. Deployment #
firebase deploy --only functions
🚀 Usage in Flutter #
1. Add Dependency #
In pubspec.yaml:
dependencies:
flutter_voip_kit_osato07:
path: ./packages/flutter_voip_kit_osato07
2. Initialize #
In lib/main.dart:
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MainApp());
}
// Inside your State class
@override
void initState() {
super.initState();
FlutterVoipKit().initialize(
onEvent: (event) {
if (event.event == Event.actionCallAccept) {
// User answered! Navigate to Screen.
}
}
);
// Submit this token to your backend!
FlutterVoipKit().getFcmToken().then((token) {
// Save FCM token (Android/iOS Standard)
});
// iOS only: Save VoIP Token
FlutterVoipKit().getVoIPToken().then((token) {
if (token != null) {
// Save VoIP token to Firestore
}
});
// Listen for VoIP token updates (iOS only)
FlutterVoipKit().onTokenRaw.listen((token) {
// Update token in backend
});
}