Skip to content

Commit 1652b56

Browse files
FCE-2111: Document background calls API (#192)
## Description Docs for background calls on iOS --------- Co-authored-by: Tomasz Mazur <[email protected]>
1 parent f6dcbe8 commit 1652b56

File tree

4 files changed

+136
-10
lines changed

4 files changed

+136
-10
lines changed

docs/how-to/react-native/background-streaming.mdx

Lines changed: 110 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ sidebar_position: 6
55
import Tabs from "@theme/Tabs";
66
import TabItem from "@theme/TabItem";
77

8-
# Streaming from background
8+
# Background calls
99

10-
On Android, it is possible to continue streaming when app is in background. Unfortunately this functionality is not available on iOS (due to Apple limitations)
10+
Both Android and iOS support calls running in the background, but they use different approaches:
11+
12+
- **Android**: Uses foreground services to keep the app active in the background
13+
- **iOS**: Uses CallKit integration to maintain VoIP calls in the background
1114

1215
Below is configuration required to make it work:
1316

@@ -28,6 +31,9 @@ You need to modify `app.json` file and add our plugin:
2831
{
2932
"android": {
3033
"enableForegroundService": true
34+
},
35+
"ios": {
36+
"enableVoIPBackgroundMode": true
3137
}
3238
}
3339
],
@@ -40,7 +46,9 @@ You need to modify `app.json` file and add our plugin:
4046
</TabItem>
4147
<TabItem value="rn" label="Bare workflow">
4248

43-
You need to modify `AndroidManifest.xml` file and add below service:
49+
**Android Configuration**
50+
51+
You need to add the following service to `AndroidManifest.xml`:
4452

4553
```xml title='AndroidManifest.xml'
4654
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
@@ -50,14 +58,25 @@ You need to modify `AndroidManifest.xml` file and add below service:
5058
<service android:name="io.fishjam.reactnative.FishjamForegroundService" android:foregroundServiceType="camera|microphone|mediaProjection"/>
5159
</application>
5260
</manifest>
61+
```
62+
63+
**iOS Configuration**
64+
65+
You need to add VoIP background mode in `Info.plist`:
66+
67+
```xml title='Info.plist'
68+
<key>UIBackgroundModes</key>
69+
<array>
70+
<string>voip</string>
71+
</array>
5372
```
5473

5574
</TabItem>
5675
</Tabs>
5776

5877
## Usage
5978

60-
<Tabs groupId="app-type">
79+
<Tabs groupId="platform">
6180

6281
<TabItem value="android" label="Android">
6382

@@ -93,6 +112,92 @@ useForegroundService({
93112

94113
</TabItem>
95114
<TabItem value="ios" label="iOS">
96-
This feature is unavailable on iOS.
115+
116+
On iOS, background calls are achieved through CallKit integration. You can use the CallKit hooks to manage VoIP calls that continue running in the background.
117+
118+
### Manual CallKit Management
119+
120+
Use the [`useCallKit`](../../api/mobile/variables/useCallKit) hook for fine-grained control over CallKit sessions:
121+
122+
```tsx
123+
import { useCallKit } from "@fishjam-cloud/react-native-client";
124+
125+
const { startCallKitSession, endCallKitSession } = useCallKit();
126+
127+
// Start CallKit session when joining a room
128+
const handleJoinRoom = async () => {
129+
await startCallKitSession({
130+
displayName: "John Doe",
131+
isVideo: true,
132+
});
133+
// ... join room logic
134+
};
135+
136+
// End CallKit session when leaving
137+
const handleLeaveRoom = async () => {
138+
await endCallKitSession();
139+
// ... leave room logic
140+
};
141+
```
142+
143+
### Automatic CallKit Management
144+
145+
Use the [`useCallKitService`](../../api/mobile/variables/useCallKitService) hook for automatic session lifecycle management:
146+
147+
```tsx
148+
import React from "react";
149+
import { useCallKitService } from "@fishjam-cloud/react-native-client";
150+
import { View } from "react-native";
151+
152+
function CallScreen({ username }: { username: string }) {
153+
// CallKit session automatically starts when component mounts
154+
// and ends when component unmounts
155+
useCallKitService({
156+
displayName: username,
157+
isVideo: true,
158+
});
159+
160+
return <View>...</View>;
161+
}
162+
```
163+
164+
### Listening to CallKit Events
165+
166+
Use the [`useCallKitEvent`](../../api/mobile/variables/useCallKitEvent) hook to respond to user interactions with the native CallKit interface:
167+
168+
```tsx
169+
import {
170+
useCallKitEvent,
171+
useCamera,
172+
useMicrophone,
173+
useConnection,
174+
} from "@fishjam-cloud/react-native-client";
175+
176+
const { toggleCamera } = useCamera();
177+
const { startMicrophone, stopMicrophone } = useMicrophone();
178+
const { leaveRoom } = useConnection();
179+
180+
// Listen for mute toggle from CallKit UI
181+
useCallKitEvent("muted", (isMuted: boolean) => {
182+
if (isMuted) {
183+
stopMicrophone();
184+
} else {
185+
startMicrophone();
186+
}
187+
});
188+
189+
// Listen for hold state changes
190+
useCallKitEvent("held", (isOnHold: boolean) => {
191+
console.log("Call hold state:", isOnHold);
192+
// Handle hold state in your app
193+
});
194+
195+
// Listen for call end from CallKit UI
196+
useCallKitEvent("ended", () => {
197+
// Handle call termination
198+
leaveRoom();
199+
});
200+
```
201+
97202
</TabItem>
98203
</Tabs>

docs/how-to/react-native/metadata-and-broadcasting.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ReadingMetadata from "../_common/metadata/reading.mdx";
1414
<JoiningRoom>
1515

1616
```tsx
17-
const FISHJAM_URL = "some-fishjam-url";
17+
const FISHJAM_ID = "some-fishjam-id";
1818
const PEER_TOKEN = "some-peer-token";
1919
// ---cut---
2020
import React, { useCallback } from "react";
@@ -30,7 +30,7 @@ export function JoinRoomButton() {
3030

3131
const onPressJoin = useCallback(async () => {
3232
await joinRoom<PeerMetadata>({
33-
url: FISHJAM_URL,
33+
fishjamId: FISHJAM_ID,
3434
peerToken: PEER_TOKEN,
3535
peerMetadata: { displayName: "John Wick" }, // [!code highlight]
3636
});

docs/how-to/react-native/screensharing.mdx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ To enable screen sharing on android, you need enable foreground services. Here i
1717

1818
### iOS
1919

20-
To enable screen share feature on iOS, you need to follow below steps
20+
To enable screen sharing on iOS, you need to follow the steps below.
21+
22+
:::tip[Background streaming during screen sharing]
23+
24+
If you want to continue screen sharing when the app goes to the background, you need to:
25+
26+
1. Enable VoIP background mode by setting `enableVoIPBackgroundMode: true` in the plugin configuration or adding the VoIP background mode to your `Info.plist`
27+
2. Use the [`useCallKitService`](../../api/mobile/variables/useCallKitService) hook in your component to manage the CallKit session
28+
29+
See the [background calls documentation](./background-streaming) for detailed instructions and code examples.
30+
31+
:::
2132

2233
<Tabs groupId="app-type">
2334

@@ -34,7 +45,8 @@ You need to modify `app.json` file and add our plugin:
3445
"@fishjam-cloud/react-native-client",
3546
{
3647
"ios": {
37-
"enableScreensharing": true
48+
"enableScreensharing": true,
49+
"enableVoIPBackgroundMode": true
3850
},
3951
"android": {
4052
"enableForegroundService": true
@@ -145,6 +157,15 @@ Configuring screen sharing on iOS is a little complicated.
145157
<string>{{BUNDLE_IDENTIFIER}}.FishjamScreenBroadcastExtension</string>
146158
```
147159

160+
1. If you want to enable background streaming during screen sharing, add VoIP background mode to your `Info.plist`:
161+
162+
```xml title='Info.plist'
163+
<key>UIBackgroundModes</key>
164+
<array>
165+
<string>voip</string>
166+
</array>
167+
```
168+
148169
1. Run `pod install`, rebuild your app and enjoy!
149170

150171
</TabItem>

packages/mobile-client-sdk

Submodule mobile-client-sdk updated 40 files

0 commit comments

Comments
 (0)