@capgo/capacitor-stream-call 0.0.41 → 0.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +158 -101
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,61 +6,39 @@
|
|
|
6
6
|
<h2><a href="https://capgo.app/consulting/?ref=plugin"> Fix your annoying bug now, Hire a Capacitor expert 💪</a></h2>
|
|
7
7
|
</div>
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
A Capacitor plugin that uses the [Stream Video SDK](https://getstream.io/) to enable video calling functionality in your app.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
npm install @capgo/capacitor-stream-call
|
|
15
15
|
npx cap sync
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
##
|
|
19
|
-
1. Add your apikey to the Android project:
|
|
20
|
-
```
|
|
21
|
-
your_app/android/app/src/main/res/values/strings.xml
|
|
22
|
-
```
|
|
18
|
+
## Configuration
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
```xml
|
|
26
|
-
<string name="CAPACITOR_STREAM_VIDEO_APIKEY">your_api_key</string>
|
|
27
|
-
```
|
|
20
|
+
### iOS Setup
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
your_app/ios/App/App/Info.plist
|
|
33
|
-
```
|
|
22
|
+
#### 1. API Key Configuration
|
|
23
|
+
Add your Stream Video API key to `ios/App/App/Info.plist`:
|
|
34
24
|
|
|
35
|
-
Add the following to the Info.plist file:
|
|
36
25
|
```xml
|
|
37
26
|
<dict>
|
|
38
27
|
<key>CAPACITOR_STREAM_VIDEO_APIKEY</key>
|
|
39
|
-
<string>
|
|
28
|
+
<string>your_api_key_here</string>
|
|
40
29
|
<!-- other keys -->
|
|
41
30
|
</dict>
|
|
42
31
|
```
|
|
43
32
|
|
|
44
|
-
|
|
33
|
+
#### 2. Localization (Optional)
|
|
34
|
+
To support multiple languages:
|
|
45
35
|
|
|
46
|
-
|
|
36
|
+
1. Add localization files to your Xcode project:
|
|
37
|
+
- `/App/App/en.lproj/Localizable.strings`
|
|
38
|
+
- `/App/App/en.lproj/Localizable.stringsdict`
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
/App/App/en.lproj/Localizable.strings
|
|
51
|
-
/App/App/en.lproj/Localizable.stringsdict
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
2. Add new languages to your project in Xcode:
|
|
55
|
-
- Open project settings
|
|
56
|
-
- Select your project
|
|
57
|
-
- Click "Info" tab
|
|
58
|
-
- Under "Localizations" click "+"
|
|
59
|
-
- Select the languages you want to add
|
|
60
|
-
|
|
61
|
-
3. Add the translations in your `Localizable.strings`:
|
|
62
|
-
```
|
|
63
|
-
// en.lproj/Localizable.strings
|
|
40
|
+
2. Add translations in `Localizable.strings`:
|
|
41
|
+
```swift
|
|
64
42
|
"stream.video.call.incoming" = "Incoming call from %@";
|
|
65
43
|
"stream.video.call.accept" = "Accept";
|
|
66
44
|
"stream.video.call.reject" = "Reject";
|
|
@@ -69,14 +47,13 @@ Add the following to the Info.plist file:
|
|
|
69
47
|
"stream.video.call.reconnecting" = "Reconnecting...";
|
|
70
48
|
```
|
|
71
49
|
|
|
72
|
-
|
|
50
|
+
3. Configure localization in your `AppDelegate.swift`:
|
|
73
51
|
```swift
|
|
74
52
|
import StreamVideo
|
|
75
53
|
|
|
76
54
|
@UIApplicationMain
|
|
77
55
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
78
56
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
79
|
-
// Set localization provider to use your app's bundle
|
|
80
57
|
Appearance.localizationProvider = { key, table in
|
|
81
58
|
Bundle.main.localizedString(forKey: key, value: nil, table: table)
|
|
82
59
|
}
|
|
@@ -85,12 +62,62 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
85
62
|
}
|
|
86
63
|
```
|
|
87
64
|
|
|
88
|
-
|
|
65
|
+
### Android Setup
|
|
66
|
+
|
|
67
|
+
#### 1. API Key Configuration
|
|
68
|
+
Add your Stream Video API key to `android/app/src/main/res/values/strings.xml`:
|
|
89
69
|
|
|
90
|
-
### Android
|
|
91
|
-
1. Create string resources in `/app/src/main/res/values/strings.xml`:
|
|
92
70
|
```xml
|
|
93
|
-
|
|
71
|
+
<string name="CAPACITOR_STREAM_VIDEO_APIKEY">your_api_key_here</string>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### 2. MainActivity Configuration
|
|
75
|
+
Modify your `MainActivity.java` to handle incoming calls:
|
|
76
|
+
|
|
77
|
+
```java
|
|
78
|
+
@Override
|
|
79
|
+
protected void onCreate(Bundle savedInstanceState) {
|
|
80
|
+
super.onCreate(savedInstanceState);
|
|
81
|
+
|
|
82
|
+
// Enable activity to show over lock screen
|
|
83
|
+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O_MR1) {
|
|
84
|
+
setShowWhenLocked(true);
|
|
85
|
+
setTurnScreenOn(true);
|
|
86
|
+
} else {
|
|
87
|
+
getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### 3. Application Class Configuration
|
|
93
|
+
Create or modify your Application class to initialize the plugin:
|
|
94
|
+
|
|
95
|
+
```java
|
|
96
|
+
import ee.forgr.capacitor.streamcall.StreamCallPlugin;
|
|
97
|
+
|
|
98
|
+
@Override
|
|
99
|
+
public void onCreate() {
|
|
100
|
+
super.onCreate();
|
|
101
|
+
|
|
102
|
+
// Initialize Firebase
|
|
103
|
+
com.google.firebase.FirebaseApp.initializeApp(this);
|
|
104
|
+
|
|
105
|
+
// Pre-initialize StreamCall plugin
|
|
106
|
+
try {
|
|
107
|
+
StreamCallPlugin.preLoadInit(this, this);
|
|
108
|
+
} catch (Exception e) {
|
|
109
|
+
Log.e("App", "Failed to pre-initialize StreamVideo Plugin", e);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
> **Note:** If you don't have an Application class, you need to create one and reference it in your `AndroidManifest.xml` with `android:name=".YourApplicationClass"`.
|
|
115
|
+
|
|
116
|
+
#### 4. Localization (Optional)
|
|
117
|
+
Add string resources for different languages:
|
|
118
|
+
|
|
119
|
+
**Default (`values/strings.xml`):**
|
|
120
|
+
```xml
|
|
94
121
|
<resources>
|
|
95
122
|
<string name="stream_video_call_incoming">Incoming call from %1$s</string>
|
|
96
123
|
<string name="stream_video_call_accept">Accept</string>
|
|
@@ -101,9 +128,8 @@ You can find all available localization keys in the [StreamVideo SDK repository]
|
|
|
101
128
|
</resources>
|
|
102
129
|
```
|
|
103
130
|
|
|
104
|
-
|
|
131
|
+
**French (`values-fr/strings.xml`):**
|
|
105
132
|
```xml
|
|
106
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
107
133
|
<resources>
|
|
108
134
|
<string name="stream_video_call_incoming">Appel entrant de %1$s</string>
|
|
109
135
|
<string name="stream_video_call_accept">Accepter</string>
|
|
@@ -114,93 +140,124 @@ You can find all available localization keys in the [StreamVideo SDK repository]
|
|
|
114
140
|
</resources>
|
|
115
141
|
```
|
|
116
142
|
|
|
117
|
-
|
|
143
|
+
## Usage
|
|
118
144
|
|
|
119
|
-
|
|
145
|
+
### Handling Incoming Calls (Android)
|
|
146
|
+
On Android, to handle incoming calls when the device is locked, you need to listen for the `incomingCall` event and manage the call state properly:
|
|
120
147
|
|
|
121
|
-
|
|
148
|
+
```typescript
|
|
149
|
+
import { StreamCall } from '@capgo/capacitor-stream-call';
|
|
122
150
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
This will allow you to display a custom call screen and then enter or reject the call with :
|
|
151
|
+
export class CallService {
|
|
152
|
+
private incomingCallId: string | null = null;
|
|
153
|
+
private isLockscreenIncoming = false;
|
|
154
|
+
|
|
155
|
+
constructor() {
|
|
156
|
+
this.setupIncomingCallListener();
|
|
157
|
+
}
|
|
132
158
|
|
|
133
|
-
|
|
159
|
+
private setupIncomingCallListener() {
|
|
160
|
+
StreamCall.addListener('incomingCall', async (payload) => {
|
|
161
|
+
console.log('Incoming call from lockscreen:', payload);
|
|
162
|
+
|
|
163
|
+
// Store the call ID and show incoming call UI
|
|
164
|
+
this.incomingCallId = payload.cid;
|
|
165
|
+
this.isLockscreenIncoming = true;
|
|
166
|
+
|
|
167
|
+
// Show your custom incoming call screen
|
|
168
|
+
this.showIncomingCallScreen(payload);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Accept the incoming call
|
|
134
173
|
async acceptCall() {
|
|
135
|
-
if (!this.incomingCallId)
|
|
174
|
+
if (!this.incomingCallId) {
|
|
175
|
+
console.warn('No incoming call to accept');
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
136
178
|
|
|
137
179
|
try {
|
|
138
180
|
await StreamCall.acceptCall();
|
|
139
|
-
|
|
181
|
+
this.clearIncomingCall();
|
|
182
|
+
console.log('Call accepted successfully');
|
|
140
183
|
} catch (error) {
|
|
141
184
|
console.error('Failed to accept call:', error);
|
|
142
|
-
await this.presentToast('Failed to accept call', 'danger');
|
|
143
185
|
}
|
|
144
186
|
}
|
|
145
187
|
|
|
188
|
+
// Reject the incoming call
|
|
146
189
|
async rejectCall() {
|
|
147
|
-
if (!this.incomingCallId)
|
|
190
|
+
if (!this.incomingCallId) {
|
|
191
|
+
console.warn('No incoming call to reject');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
148
194
|
|
|
149
195
|
try {
|
|
150
196
|
await StreamCall.rejectCall();
|
|
151
|
-
this.
|
|
152
|
-
|
|
197
|
+
this.clearIncomingCall();
|
|
198
|
+
console.log('Call rejected successfully');
|
|
153
199
|
} catch (error) {
|
|
154
200
|
console.error('Failed to reject call:', error);
|
|
155
|
-
await this.presentToast('Failed to reject call', 'danger');
|
|
156
201
|
}
|
|
157
202
|
}
|
|
158
|
-
```
|
|
159
|
-
This is the only way we found to allow the app to use the same UI when phone is lock for the video call.
|
|
160
|
-
This can be done that way only on Android on IOS this part is handle by the OS.
|
|
161
203
|
|
|
204
|
+
private clearIncomingCall() {
|
|
205
|
+
this.incomingCallId = null;
|
|
206
|
+
this.isLockscreenIncoming = false;
|
|
207
|
+
// Hide your incoming call UI
|
|
208
|
+
this.hideIncomingCallScreen();
|
|
209
|
+
}
|
|
162
210
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
|
211
|
+
private showIncomingCallScreen(payload: any) {
|
|
212
|
+
// Implement your custom incoming call UI
|
|
213
|
+
// This should show accept/reject buttons and caller information
|
|
214
|
+
// Example: navigate to incoming call page or show modal
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private hideIncomingCallScreen() {
|
|
218
|
+
// Hide the incoming call UI
|
|
219
|
+
// Example: navigate away from incoming call page or close modal
|
|
173
220
|
}
|
|
174
221
|
}
|
|
175
222
|
```
|
|
176
223
|
|
|
177
|
-
|
|
178
|
-
```java
|
|
179
|
-
import ee.forgr.capacitor.streamcall.StreamCallPlugin;
|
|
224
|
+
> **Important:** This lock-screen handling is only required on Android. On iOS, the system handles incoming call UI automatically.
|
|
180
225
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
226
|
+
### Basic Call Operations
|
|
227
|
+
```typescript
|
|
228
|
+
import { StreamCall } from '@capgo/capacitor-stream-call';
|
|
229
|
+
|
|
230
|
+
// Login to Stream Video
|
|
231
|
+
await StreamCall.login({
|
|
232
|
+
token: 'your_user_token',
|
|
233
|
+
userId: 'user_id',
|
|
234
|
+
name: 'User Name',
|
|
235
|
+
apiKey: 'your_api_key',
|
|
236
|
+
magicDivId: 'video-container'
|
|
237
|
+
});
|
|
186
238
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
Log.i(TAG, "StreamVideo Plugin preLoadInit invoked successfully");
|
|
194
|
-
} catch (Exception e) {
|
|
195
|
-
Log.e(TAG, "Failed to pre-initialize StreamVideo Plugin", e);
|
|
196
|
-
}
|
|
197
|
-
Log.i(TAG, "Application initialization completed");
|
|
198
|
-
}
|
|
199
|
-
```
|
|
239
|
+
// Make a call
|
|
240
|
+
await StreamCall.call({
|
|
241
|
+
userIds: ['user_to_call'],
|
|
242
|
+
type: 'default',
|
|
243
|
+
ring: true
|
|
244
|
+
});
|
|
200
245
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
246
|
+
// End call
|
|
247
|
+
await StreamCall.endCall();
|
|
248
|
+
|
|
249
|
+
// Toggle microphone
|
|
250
|
+
await StreamCall.setMicrophoneEnabled({ enabled: false });
|
|
251
|
+
|
|
252
|
+
// Toggle camera
|
|
253
|
+
await StreamCall.setCameraEnabled({ enabled: false });
|
|
254
|
+
|
|
255
|
+
// Switch camera
|
|
256
|
+
await StreamCall.switchCamera({ camera: 'front' });
|
|
257
|
+
|
|
258
|
+
// Logout
|
|
259
|
+
await StreamCall.logout();
|
|
260
|
+
```
|
|
204
261
|
|
|
205
262
|
## API
|
|
206
263
|
|
package/package.json
CHANGED