Memulai
Instalasi
Section titled âInstalasiânpm install @capgo/capacitor-stream-callnpx cap syncyarn add @capgo/capacitor-stream-callnpx cap syncpnpm add @capgo/capacitor-stream-callnpx cap syncbun add @capgo/capacitor-stream-callnpx cap syncPrasyarat
Section titled âPrasyaratâAnda memerlukan akun Stream dan kredensial API. Daftar di Stream jika Anda belum memilikinya.
Konfigurasi Platform
Section titled âKonfigurasi PlatformâTambahkan izin yang diperlukan ke Info.plist Anda:
<key>NSCameraUsageDescription</key><string>This app needs camera access for video calls</string><key>NSMicrophoneUsageDescription</key><string>This app needs microphone access for video calls</string>Android
Section titled âAndroidâTambahkan izin yang diperlukan ke AndroidManifest.xml Anda:
<uses-permission android:name="android.permission.CAMERA" /><uses-permission android:name="android.permission.RECORD_AUDIO" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />Contoh Penggunaan
Section titled âContoh Penggunaanâimport { StreamCall } from '@capgo/capacitor-stream-call';
// Initialize Stream SDKawait StreamCall.initialize({ apiKey: 'your-stream-api-key', userId: 'user-123', userToken: 'user-token'});
// Create a callawait StreamCall.createCall({ callId: 'call-123', callType: 'default'});
// Join a callawait StreamCall.joinCall({ callId: 'call-123'});
// Enable/disable cameraawait StreamCall.toggleCamera({ enabled: true});
// Enable/disable microphoneawait StreamCall.toggleMicrophone({ enabled: true});
// Switch camera (front/back)await StreamCall.switchCamera();
// Leave the callawait StreamCall.leaveCall();
// Listen for call eventsStreamCall.addListener('callStarted', (data) => { console.log('Call started:', data);});
StreamCall.addListener('callEnded', (data) => { console.log('Call ended:', data);});
StreamCall.addListener('participantJoined', (data) => { console.log('Participant joined:', data);});
StreamCall.addListener('participantLeft', (data) => { console.log('Participant left:', data);});Referensi API
Section titled âReferensi APIâinitialize(options)
Section titled âinitialize(options)âinitialize(options: InitializeOptions) => Promise<void>Inisialisasi Stream Video SDK.
| Param | Type |
|---|---|
options | InitializeOptions |
createCall(options)
Section titled âcreateCall(options)âcreateCall(options: CreateCallOptions) => Promise<void>Buat panggilan video baru.
| Param | Type |
|---|---|
options | CreateCallOptions |
joinCall(options)
Section titled âjoinCall(options)âjoinCall(options: JoinCallOptions) => Promise<void>Bergabung dengan panggilan video yang ada.
| Param | Type |
|---|---|
options | JoinCallOptions |
leaveCall()
Section titled âleaveCall()âleaveCall() => Promise<void>Keluar dari panggilan saat ini.
toggleCamera(options)
Section titled âtoggleCamera(options)âtoggleCamera(options: { enabled: boolean }) => Promise<void>Aktifkan atau nonaktifkan kamera.
| Param | Type |
|---|---|
options | { enabled: boolean } |
toggleMicrophone(options)
Section titled âtoggleMicrophone(options)âtoggleMicrophone(options: { enabled: boolean }) => Promise<void>Aktifkan atau nonaktifkan mikrofon.
| Param | Type |
|---|---|
options | { enabled: boolean } |
switchCamera()
Section titled âswitchCamera()âswitchCamera() => Promise<void>Beralih antara kamera depan dan belakang.
setSpeakerphone(options)
Section titled âsetSpeakerphone(options)âsetSpeakerphone(options: { enabled: boolean }) => Promise<void>Aktifkan atau nonaktifkan speakerphone.
| Param | Type |
|---|---|
options | { enabled: boolean } |
sendCallInvite(options)
Section titled âsendCallInvite(options)âsendCallInvite(options: InviteOptions) => Promise<void>Kirim undangan panggilan ke pengguna.
| Param | Type |
|---|---|
options | InviteOptions |
acceptCall(options)
Section titled âacceptCall(options)âacceptCall(options: { callId: string }) => Promise<void>Terima panggilan masuk.
| Param | Type |
|---|---|
options | { callId: string } |
rejectCall(options)
Section titled ârejectCall(options)ârejectCall(options: { callId: string }) => Promise<void>Tolak panggilan masuk.
| Param | Type |
|---|---|
options | { callId: string } |
Interfaces
Section titled âInterfacesâInitializeOptions
Section titled âInitializeOptionsâ| Prop | Type | Description |
|---|---|---|
apiKey | string | Stream API key |
userId | string | User ID |
userToken | string | User authentication token |
userName | string | User display name (optional) |
userImage | string | User profile image URL (optional) |
CreateCallOptions
Section titled âCreateCallOptionsâ| Prop | Type | Description |
|---|---|---|
callId | string | Unique call identifier |
callType | string | Call type (e.g., âdefaultâ, âaudio-onlyâ) |
members | string[] | Array of user IDs to invite (optional) |
JoinCallOptions
Section titled âJoinCallOptionsâ| Prop | Type | Description |
|---|---|---|
callId | string | Call ID to join |
InviteOptions
Section titled âInviteOptionsâ| Prop | Type | Description |
|---|---|---|
callId | string | Call ID |
userId | string | User ID to invite |
Event Listeners
Section titled âEvent ListenersâEvent yang Tersedia
Section titled âEvent yang TersediaâcallStarted- Panggilan telah dimulaicallEnded- Panggilan telah berakhirparticipantJoined- Peserta bergabung dengan panggilanparticipantLeft- Peserta meninggalkan panggilanincomingCall- Panggilan masuk diterimacallAccepted- Panggilan telah diterimacallRejected- Panggilan telah ditolakerror- Terjadi kesalahan
Contoh Event
Section titled âContoh Eventâ// Listen for incoming callsStreamCall.addListener('incomingCall', (data) => { console.log('Incoming call from:', data.callerId); console.log('Caller name:', data.callerName);
// Show incoming call UI showIncomingCallScreen({ callerId: data.callerId, callerName: data.callerName, callerImage: data.callerImage, callId: data.callId });});
// Listen for call acceptanceStreamCall.addListener('callAccepted', (data) => { console.log('Call accepted'); // Navigate to call screen});
// Listen for errorsStreamCall.addListener('error', (error) => { console.error('Call error:', error.message); // Handle error appropriately});
// Remove listener when doneconst listener = await StreamCall.addListener('callStarted', (data) => { console.log('Call started');});
// Later...listener.remove();Contoh Lengkap
Section titled âContoh Lengkapâimport { StreamCall } from '@capgo/capacitor-stream-call';
class VideoCallService { async initialize(userId: string, userName: string) { try { await StreamCall.initialize({ apiKey: 'your-stream-api-key', userId: userId, userToken: await this.getUserToken(userId), userName: userName });
this.setupEventListeners(); } catch (error) { console.error('Failed to initialize Stream:', error); } }
setupEventListeners() { // Handle incoming calls StreamCall.addListener('incomingCall', async (data) => { const accepted = await this.showIncomingCallDialog(data);
if (accepted) { await StreamCall.acceptCall({ callId: data.callId }); await StreamCall.joinCall({ callId: data.callId }); } else { await StreamCall.rejectCall({ callId: data.callId }); } });
// Handle call events StreamCall.addListener('callStarted', () => { console.log('Call started'); });
StreamCall.addListener('callEnded', () => { console.log('Call ended'); this.navigateToHome(); });
StreamCall.addListener('participantJoined', (data) => { console.log('Participant joined:', data.participantName); }); }
async startCall(recipientId: string) { try { const callId = `call-${Date.now()}`;
// Create and join call await StreamCall.createCall({ callId: callId, callType: 'default', members: [recipientId] });
await StreamCall.joinCall({ callId: callId });
// Send invitation await StreamCall.sendCallInvite({ callId: callId, userId: recipientId });
console.log('Call started'); } catch (error) { console.error('Failed to start call:', error); } }
async endCall() { try { await StreamCall.leaveCall(); console.log('Call ended'); } catch (error) { console.error('Failed to end call:', error); } }
async toggleVideo(enabled: boolean) { await StreamCall.toggleCamera({ enabled }); }
async toggleAudio(enabled: boolean) { await StreamCall.toggleMicrophone({ enabled }); }
async flipCamera() { await StreamCall.switchCamera(); }
private async getUserToken(userId: string): Promise<string> { // Fetch user token from your backend const response = await fetch(`/api/stream-token?userId=${userId}`); const data = await response.json(); return data.token; }
private async showIncomingCallDialog(data: any): Promise<boolean> { // Show native dialog or custom UI return confirm(`Incoming call from ${data.callerName}`); }
private navigateToHome() { // Navigate to home screen window.location.href = '/'; }}
// Usageconst videoCall = new VideoCallService();await videoCall.initialize('user-123', 'John Doe');
// Start a callawait videoCall.startCall('user-456');
// Toggle controlsawait videoCall.toggleVideo(false); // Disable videoawait videoCall.toggleAudio(false); // Muteawait videoCall.flipCamera(); // Switch camera
// End callawait videoCall.endCall();Praktik Terbaik
Section titled âPraktik Terbaikâ- Inisialisasi SDK lebih awal dalam siklus hidup aplikasi Anda
- Tangani permintaan izin sebelum memulai panggilan
- Implementasikan penanganan error yang tepat untuk masalah jaringan
- Bersihkan listener ketika komponen di-unmount
- Uji pada perangkat nyata (bukan hanya emulator)
- Implementasikan logika reconnection untuk gangguan jaringan
- Berikan umpan balik visual untuk status panggilan
- Tangani transisi background/foreground
Lokalisasi
Section titled âLokalisasiâPlugin mendukung banyak bahasa untuk elemen UI native. Konfigurasi di pengaturan spesifik platform Anda.
Kasus Penggunaan
Section titled âKasus Penggunaanâ- Panggilan video satu-lawan-satu
- Konferensi video grup
- Panggilan audio saja
- Sesi berbagi layar
- Obrolan video dukungan pelanggan
- Konsultasi telemedicine
- Kolaborasi jarak jauh