Skip to content

Commit 0f3a84e

Browse files
Update documentation adding the new mobile sdk (#217)
## Description Update documentation adding the new mobile sdk. Since the new mobile sdk is based on the web sdk, How-to-guides for mobile and web were joined together. --------- Co-authored-by: Milosz Filimowski <milosz.filimowski@swmansion.com>
1 parent af7d644 commit 0f3a84e

56 files changed

Lines changed: 1860 additions & 1873 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"addWords": true
1010
}
1111
],
12+
"useGitignore": true,
1213
"ignorePaths": [
1314
"node_modules/**",
1415
"packages/**",

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
[submodule "packages/web-client-sdk"]
22
path = packages/web-client-sdk
33
url = https://github.com/fishjam-cloud/web-client-sdk.git
4-
[submodule "packages/mobile-client-sdk"]
5-
path = packages/mobile-client-sdk
6-
url = https://github.com/fishjam-cloud/mobile-client-sdk.git
74
[submodule "packages/js-server-sdk"]
85
path = packages/js-server-sdk
96
url = https://github.com/fishjam-cloud/js-server-sdk.git

docs/explanation/public-livestreams.mdx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,17 @@ Once you've created a viewer token, you can connect to a room using the Fishjam
139139
const viewerToken = '';
140140

141141
// ---cut---
142-
import {
143-
LivestreamViewer,
144-
useLivestreamViewer,
145-
} from '@fishjam-cloud/react-native-client/livestream';
142+
import { useLivestreamViewer, RTCView } from '@fishjam-cloud/mobile-client';
146143

147-
// ...
148-
149-
const { connect, whepClientRef } = useLivestreamViewer();
144+
// Inside your component:
145+
const { connect, stream } = useLivestreamViewer();
150146

151147
// ...
152148

153149
await connect({ token: viewerToken });
154150

155-
// Use `LivestreamViewer` to render the stream
156-
<LivestreamViewer ref={whepClientRef} />
151+
// Render the stream
152+
{stream && <RTCView mediaStream={stream} style={{ flex: 1 }} />}
157153
```
158154

159155
</TabItem>
@@ -203,21 +199,17 @@ Once you've created a room of type `livestream` with the `public` flag enabled,
203199
const roomId = '';
204200

205201
// ---cut---
206-
import {
207-
LivestreamViewer,
208-
useLivestreamViewer,
209-
} from '@fishjam-cloud/react-native-client/livestream';
202+
import { useLivestreamViewer, RTCView } from '@fishjam-cloud/mobile-client';
210203

211-
// ...
212-
213-
const { connect, whepClientRef } = useLivestreamViewer();
204+
// Inside your component:
205+
const { connect, stream } = useLivestreamViewer();
214206

215207
// ...
216208

217209
await connect({ streamId: roomId });
218210

219-
// Use `LivestreamViewer` to render the stream
220-
<LivestreamViewer ref={whepClientRef} />
211+
// Render the stream
212+
{stream && <RTCView mediaStream={stream} style={{ flex: 1 }} />}
221213
```
222214

223215
</TabItem>

docs/how-to/backend/server-setup.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ At any time you can terminate user's access by deleting the peer.
164164

165165
#### Metadata
166166

167-
When creating a peer, you can also assign metadata to that peer, which can be read later with the [mobile SDK](../../how-to/react-native/metadata)
168-
or [web SDK](../../how-to/react/metadata). This metadata can be only set when creating the peer and can't be updated later.
167+
When creating a peer, you can also assign metadata to that peer, which can be read later with the [client SDK](../../how-to/client/metadata). This metadata can be only set when creating the peer and can't be updated later.
169168

170169
<Tabs groupId="language">
171170
<TabItem value="ts" label="Typescript">

docs/how-to/client/_category_.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Web & Mobile",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Learn how to integrate Fishjam into your web and mobile applications."
7+
}
8+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
sidebar_position: 13
3+
sidebar_label: "Background calls 📱"
4+
---
5+
6+
import Tabs from "@theme/Tabs";
7+
import TabItem from "@theme/TabItem";
8+
9+
# Background calls <span className="badge badge--mobile">Mobile</span>
10+
11+
:::note
12+
This guide is exclusively for **Mobile** (React Native) applications.
13+
:::
14+
15+
Both Android and iOS support calls running in the background, but they use different approaches:
16+
17+
- **Android**: Uses foreground services to keep the app active in the background
18+
- **iOS**: Uses CallKit integration to maintain VoIP calls in the background
19+
20+
Below is configuration required to make it work:
21+
22+
<Tabs groupId="app-type">
23+
24+
<TabItem value="expo" label="Expo">
25+
26+
You need to modify `app.json` file and add our plugin:
27+
28+
```json
29+
{
30+
"expo": {
31+
...
32+
"plugins": {
33+
...
34+
[
35+
"@fishjam-cloud/mobile-client",
36+
{
37+
"android": {
38+
"enableForegroundService": true
39+
},
40+
"ios": {
41+
"enableVoIPBackgroundMode": true
42+
}
43+
}
44+
],
45+
...
46+
}
47+
}
48+
}
49+
```
50+
51+
</TabItem>
52+
<TabItem value="rn" label="Bare workflow">
53+
54+
**Android Configuration**
55+
56+
You need to add the following service to `AndroidManifest.xml`:
57+
58+
```xml title='AndroidManifest.xml'
59+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
60+
...
61+
<application ...>
62+
...
63+
<service android:name="io.fishjam.reactnative.FishjamForegroundService" android:foregroundServiceType="camera|microphone|mediaProjection"/>
64+
</application>
65+
</manifest>
66+
```
67+
68+
**iOS Configuration**
69+
70+
You need to add VoIP background mode in `Info.plist`:
71+
72+
```xml title='Info.plist'
73+
<key>UIBackgroundModes</key>
74+
<array>
75+
<string>voip</string>
76+
</array>
77+
```
78+
79+
</TabItem>
80+
</Tabs>
81+
82+
## Usage
83+
84+
<Tabs groupId="platform">
85+
86+
<TabItem value="android" label="Android">
87+
88+
You can use [`useForegroundService`](../../api/mobile/variables/useForegroundService) hook to handle how foreground service behaves on Android.
89+
90+
:::important[Permissions]
91+
92+
If you want to use [`enableCamera`](../../api/mobile/type-aliases/ForegroundServiceConfig#enablecamera) or [`enableMicrophone`](../../api/mobile/type-aliases/ForegroundServiceConfig#enablemicrophone),
93+
user must first grant permission for this resource. [`useForegroundService`](../../api/mobile/variables/useForegroundService) will check if permission is
94+
granted and only then allow to start a service.
95+
96+
:::
97+
98+
```tsx
99+
import { useCamera, useMicrophone } from "@fishjam-cloud/mobile-client";
100+
101+
const { isCameraOn } = useCamera();
102+
const { isMicrophoneOn } = useMicrophone();
103+
```
104+
105+
</TabItem>
106+
<TabItem value="ios" label="iOS">
107+
108+
On iOS, background calls are achieved through CallKit integration. To enable background streaming on iOS:
109+
110+
1. Enable VoIP background mode by setting `enableVoIPBackgroundMode: true` in the plugin configuration or adding the VoIP background mode to your `Info.plist`
111+
2. The SDK will automatically handle CallKit integration for maintaining background audio/video sessions
112+
113+
:::note
114+
CallKit integration is handled automatically by the SDK when VoIP background mode is enabled. The call will appear in the iOS call history and can be managed through the native phone interface.
115+
:::
116+
117+
</TabItem>
118+
</Tabs>
119+
120+
## See Also
121+
122+
For an enhanced user experience when your app is in the background, consider enabling [Picture in Picture](./picture-in-picture), which allows users to see video content in a floating window while using other apps.

docs/how-to/client/connecting.mdx

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
sidebar_position: 3
3+
---
4+
5+
import Tabs from "@theme/Tabs";
6+
import TabItem from "@theme/TabItem";
7+
8+
# Connecting
9+
10+
This article will guide you through the process of connecting to a Fishjam room.
11+
12+
## Getting URL and token
13+
14+
In order to connect, you need to obtain a **Peer Token** (the token that will authenticate the peer in
15+
your Room).
16+
17+
<Tabs groupId="app-type">
18+
19+
<TabItem value="sandbox" label="Sandbox App">
20+
21+
Once you create your account on [Fishjam](https://fishjam.io), you will have access to the Sandbox environment as part of the Mini Jar plan.
22+
While using the Sandbox environment, [you can use the Sandbox API](../features/sandbox-api-testing) to generate peer tokens for testing or development purposes.
23+
This is basically a service that will create a Room, add your app as
24+
the Room's Peer, and return the token required to use that Room.
25+
26+
<Tabs groupId="platform">
27+
<TabItem value="web" label="React (Web)">
28+
29+
```ts
30+
import { useSandbox } from "@fishjam-cloud/react-client";
31+
const roomName = "room";
32+
const peerName = "user";
33+
// ---cut---
34+
35+
// The `useSandbox` hook gets the fishjamId from FishjamProvider
36+
// It will work ONLY with the FISHJAM_ID of the Sandbox environment
37+
const { getSandboxPeerToken } = useSandbox();
38+
const peerToken = await getSandboxPeerToken(roomName, peerName);
39+
```
40+
41+
</TabItem>
42+
<TabItem value="mobile" label="React Native (Mobile)">
43+
44+
```ts
45+
import { useSandbox } from "@fishjam-cloud/mobile-client";
46+
const roomName = "room";
47+
const peerName = "user";
48+
// ---cut---
49+
50+
// The `useSandbox` hook gets the fishjamId from FishjamProvider
51+
// It will work ONLY with the FISHJAM_ID of the Sandbox environment
52+
const { getSandboxPeerToken } = useSandbox();
53+
const peerToken = await getSandboxPeerToken(roomName, peerName);
54+
```
55+
56+
</TabItem>
57+
</Tabs>
58+
59+
</TabItem>
60+
<TabItem value="production" label="Production App">
61+
62+
For the production app, you need to implement your own backend service that will provide the user with a **Peer Token**. To do that,
63+
follow our [server setup instructions](../backend/server-setup).
64+
65+
</TabItem>
66+
</Tabs>
67+
68+
## Connecting
69+
70+
Use the [`useConnection`](../../api/web/functions/useConnection) hook to get
71+
the [`joinRoom`](../../api/web/functions/useConnection#joinroom) function.
72+
73+
<Tabs groupId="platform">
74+
<TabItem value="web" label="React (Web)">
75+
76+
```tsx
77+
const PEER_TOKEN = "some-peer-token";
78+
// ---cut-before---
79+
import { useConnection, useSandbox } from "@fishjam-cloud/react-client";
80+
import React, { useCallback } from "react";
81+
82+
export function JoinRoomButton() {
83+
const { joinRoom } = useConnection(); // [!code highlight]
84+
// get the peer token from sandbox or your backend
85+
const { getSandboxPeerToken } = useSandbox();
86+
87+
const onJoinRoomPress = useCallback(async () => {
88+
// [!code highlight:5]
89+
const peerToken = await getSandboxPeerToken("Room", "User");
90+
await joinRoom({ peerToken });
91+
}, [joinRoom]);
92+
93+
return <button onClick={onJoinRoomPress}>Join room</button>;
94+
}
95+
```
96+
97+
</TabItem>
98+
<TabItem value="mobile" label="React Native (Mobile)">
99+
100+
```tsx
101+
import React, { useCallback } from "react";
102+
import { Button } from "react-native";
103+
import { useConnection, useSandbox } from "@fishjam-cloud/mobile-client";
104+
105+
export function JoinRoomButton() {
106+
const { joinRoom } = useConnection(); // [!code highlight]
107+
// fishjamId is provided through FishjamProvider
108+
const { getSandboxPeerToken } = useSandbox();
109+
110+
const onPressJoin = useCallback(async () => {
111+
// in production environment, get the peerToken from your backend
112+
const peerToken = await getSandboxPeerToken("Room", "User");
113+
114+
await joinRoom({ peerToken }); // [!code highlight]
115+
}, [joinRoom, getSandboxPeerToken]);
116+
117+
return <Button onPress={onPressJoin} title="Join Room" />;
118+
}
119+
```
120+
121+
</TabItem>
122+
</Tabs>
123+
124+
## Disconnecting
125+
126+
In order to close connection, use the [`leaveRoom`](../../api/web/functions/useConnection#leaveroom) method
127+
from [`useConnection`](../../api/web/functions/useConnection) hook.
128+
129+
<Tabs groupId="platform">
130+
<TabItem value="web" label="React (Web)">
131+
132+
```tsx
133+
import { useConnection } from "@fishjam-cloud/react-client";
134+
import React, { useCallback } from "react";
135+
136+
export function LeaveRoomButton() {
137+
const { leaveRoom } = useConnection(); // [!code highlight]
138+
139+
return <button onClick={leaveRoom}>Leave room</button>;
140+
}
141+
```
142+
143+
</TabItem>
144+
<TabItem value="mobile" label="React Native (Mobile)">
145+
146+
```tsx
147+
import React, { useCallback } from "react";
148+
import { Button } from "react-native";
149+
import { useConnection } from "@fishjam-cloud/mobile-client";
150+
151+
export function LeaveRoomButton() {
152+
const { leaveRoom } = useConnection(); // [!code highlight]
153+
154+
const onPressLeave = useCallback(async () => {
155+
await leaveRoom(); // [!code highlight]
156+
}, [leaveRoom]);
157+
158+
return <Button onPress={onPressLeave} title="Leave Room" />;
159+
}
160+
```
161+
162+
</TabItem>
163+
</Tabs>
164+
165+
## Next Steps
166+
167+
Now that you're connected to a room, you can explore additional features:
168+
169+
- [Start Streaming](./start-streaming) - Enable your camera and microphone
170+
- [List Other Peers](./list-other-peers) - Display video from other participants
171+
- [Picture in Picture](./picture-in-picture) - Allow users to watch video in a floating window (Mobile)
172+
- [Background Streaming](./background-streaming) - Keep calls active when the app is backgrounded (Mobile)

0 commit comments

Comments
 (0)