@fishjam-cloud/react-native-client 0.2.3 → 0.2.4

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.
Files changed (43) hide show
  1. package/README.md +9 -397
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/io/fishjam/reactnative/EmitableEvents.kt +1 -1
  4. package/android/src/main/java/io/fishjam/reactnative/Errors.kt +3 -2
  5. package/android/src/main/java/io/fishjam/reactnative/RNFishjamClient.kt +73 -73
  6. package/android/src/main/java/io/fishjam/reactnative/RNFishjamClientModule.kt +18 -18
  7. package/build/RNFishjamClientModule.d.ts +8 -8
  8. package/build/RNFishjamClientModule.d.ts.map +1 -1
  9. package/build/RNFishjamClientModule.js.map +1 -1
  10. package/build/common/client.d.ts +4 -4
  11. package/build/common/client.d.ts.map +1 -1
  12. package/build/common/client.js +5 -5
  13. package/build/common/client.js.map +1 -1
  14. package/build/common/metadata.d.ts +3 -3
  15. package/build/common/metadata.d.ts.map +1 -1
  16. package/build/common/metadata.js +4 -4
  17. package/build/common/metadata.js.map +1 -1
  18. package/build/hooks/useCamera.d.ts +17 -0
  19. package/build/hooks/useCamera.d.ts.map +1 -1
  20. package/build/hooks/useCamera.js +1 -1
  21. package/build/hooks/useCamera.js.map +1 -1
  22. package/build/hooks/useFishjamEvent.d.ts +1 -1
  23. package/build/hooks/useFishjamEvent.js +1 -1
  24. package/build/hooks/useFishjamEvent.js.map +1 -1
  25. package/build/hooks/useScreenShare.d.ts +57 -0
  26. package/build/hooks/useScreenShare.d.ts.map +1 -0
  27. package/build/hooks/useScreenShare.js +85 -0
  28. package/build/hooks/useScreenShare.js.map +1 -0
  29. package/build/index.d.ts +3 -2
  30. package/build/index.d.ts.map +1 -1
  31. package/build/index.js +1 -1
  32. package/build/index.js.map +1 -1
  33. package/ios/Events.swift +1 -1
  34. package/ios/RNFishjamClient.podspec +1 -1
  35. package/ios/RNFishjamClient.swift +62 -62
  36. package/ios/RNFishjamClientModule.swift +18 -17
  37. package/package.json +11 -9
  38. package/plugin/broadcastExtensionFiles/FishjamBroadcastSampleHandler.swift +1 -1
  39. package/plugin/build/withFishjamIos.js +1 -1
  40. package/build/hooks/useScreencast.d.ts +0 -57
  41. package/build/hooks/useScreencast.d.ts.map +0 -1
  42. package/build/hooks/useScreencast.js +0 -85
  43. package/build/hooks/useScreencast.js.map +0 -1
package/README.md CHANGED
@@ -1,410 +1,22 @@
1
- # Fishjam Cloud React Native client
2
-
3
- `@fishjam-cloud/react-native-client` is a React Native wrapper for
4
- [android-client](https://github.com/fishjam-dev/android-client-sdk) and
5
- [ios-client](https://github.com/fishjam-dev/ios-client-sdk). It allows you to
6
- quickly and easily create a mobile client app in React Native for a
7
- [Fishjam](https://github.com/fishjam-dev/fishjam) server.
1
+ <img src="../../.github/images/fishjam-card.png" width="100%">
8
2
 
9
- # Documentation
3
+ # Fishjam Cloud React Native client
10
4
 
11
- API documentation is available
12
- [here](https://fishjam-cloud.github.io/mobile-client-sdk/modules/_fishjam_cloud_react_native_client.html)
5
+ `@fishjam-cloud/react-native-client` is an easiest way to add video streaming to your React Native app.
13
6
 
14
7
  # Installation
15
8
 
16
- Firstly install `react-native-client` with `yarn` or `npm`
17
-
18
- ```
19
- yarn add @fishjam-cloud/react-native-client
20
- ```
21
-
22
- or
23
-
24
- ```
25
- npm install @fishjam-cloud/react-native-client
26
- ```
27
-
28
- ### Expo plugin
29
-
30
- If you're using development builds with `eas build` or bare workflow you can try
31
- using expo plugin to do the configuration below for you. Simply run:
32
-
33
- ```
34
- expo install @fishjam-cloud/react-native-client
35
- ```
36
-
37
- Add plugin to your `app.json` if it's not already added:
38
-
39
- ```json
40
- {
41
- "expo": {
42
- "name": "example",
43
- ...
44
- "plugins": [
45
- "@fishjam-cloud/react-native-client"
46
- ]
47
- }
48
- }
49
- ```
50
-
51
- If you want to use screensharing feature, enable the following flags:
52
-
53
- ```json
54
- {
55
- "expo": {
56
- "name": "example",
57
- ...
58
- "plugins": [
59
- [
60
- "@fishjam-cloud/react-native-client",
61
- {
62
- "android": {
63
- "enableForegroundService": true
64
- },
65
- "ios": {
66
- "enableScreensharing": true
67
- }
68
- }
69
- ]
70
- ]
71
- }
72
- }
73
- ```
74
-
75
- On bare workflow run `expo prebuild` to configure the app, then run
76
- `pod install`. On development build `eas build` should take care of it.
77
-
78
- ### Android
79
-
80
- 1. Add camera and microphone permissions to your `AndroidManifest.xml` or you app.json permissions.
81
- 2. Rebuild the app. That's it!
82
-
83
- ### iOS
84
-
85
- > [!NOTE]
86
- > If you're using our plugin with `enableScreensharing` set to `true`. Not further steps are required.
87
-
88
- On iOS installation is a bit more complicated, because you need to setup a
89
- screen broadcast app extension for screensharing.
90
-
91
- 1. Add camera and microphone permissions to your main `Info.plist`.
92
- ```xml
93
- <key>NSCameraUsageDescription</key>
94
- <string>Allow $(PRODUCT_NAME) to use the camera</string>
95
- <key>NSMicrophoneUsageDescription</key>
96
- <string>Allow $(PRODUCT_NAME) to use the microphone</string>
97
- ```
98
- 2. We recommend adding `audio` background mode in `Info.plist` so that the app
99
- doesn't disconnect when it's in background:
100
-
101
- ```xml
102
- <key>UIBackgroundModes</key>
103
- <array>
104
- <string>audio</string>
105
- </array>
106
- ```
107
-
108
- 2. Open your `<your-project>.xcworkspace` in Xcode
109
- 3. Create new Broadcast Upload Extension. Select File → New → Target... →
110
- Broadcast Upload Extension → Next. Choose the name for the new target, select
111
- Swift language and deselect "Include UI Extension".
112
-
113
- ![New target config](https://github.com/fishjam-cloud/mobile-client-sdk/blob/main/.github/images/xcode1.png)
114
-
115
- Press Finish. In the next alert xcode will ask you if you want to activate
116
- the new scheme - press Cancel.
117
-
118
- 4. Configure app group. Go to "Signing & Capabilities" tab, click "+ Capability"
119
- button in upper left corner and select "App Groups".
120
-
121
- ![App groups config](https://github.com/fishjam-cloud/mobile-client-sdk/blob/main/.github/images/xcode2.png)
122
-
123
- Then in the "App Groups" add a new group or select existing. Usually group
124
- name has format `group.<your-bundle-identifier>`. Verify that both app and
125
- extension targets have app group and dev team set correctly.
126
-
127
- 5. A new folder with app extension should appear on the left with contents like
128
- this:
129
-
130
- ![App extension files](https://github.com/fishjam-cloud/mobile-client-sdk/blob/main/.github/images/xcode3.png)
131
-
132
- Replace `SampleHandler.swift` with `MembraneBroadcastSampleHandler.swift` and
133
- this code:
134
-
135
- ```swift
136
- import Foundation
137
- import MembraneRTC
138
- import os.log
139
- import ReplayKit
140
- import WebRTC
141
-
142
-
143
- /// App Group used by the extension to exchange buffers with the target application
144
- let appGroup = "{{GROUP_IDENTIFIER}}"
145
-
146
- let logger = OSLog(subsystem: "{{BUNDLE_IDENTIFIER}}.MembraneBroadcastSampleHandler", category: "Broadcaster")
147
-
148
- /// An example `SampleHandler` utilizing `BroadcastSampleSource` from `MembraneRTC` sending broadcast samples and necessary notification enabling device's screencast.
149
- class MembraneBroadcastSampleHandler: RPBroadcastSampleHandler {
150
- let broadcastSource = BroadcastSampleSource(appGroup: appGroup)
151
- var started: Bool = false
152
-
153
-
154
- override func broadcastStarted(withSetupInfo _: [String: NSObject]?) {
155
- started = broadcastSource.connect()
156
-
157
- guard started else {
158
- os_log("failed to connect with ipc server", log: logger, type: .debug)
159
-
160
- super.finishBroadcastWithError(NSError(domain: "", code: 0, userInfo: nil))
161
-
162
- return
163
- }
164
-
165
- broadcastSource.started()
166
- }
9
+ Check out the [installation](https://fishjam-cloud.github.io/documentation/guide/react-native/installation) section of our docs for the detailed installation instructions.
167
10
 
168
- override func broadcastPaused() {
169
- broadcastSource.paused()
170
- }
171
-
172
- override func broadcastResumed() {
173
- broadcastSource.resumed()
174
- }
175
-
176
- override func broadcastFinished() {
177
- broadcastSource.finished()
178
- }
179
-
180
- override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {
181
- guard started else {
182
- return
183
- }
184
-
185
- broadcastSource.processFrame(sampleBuffer: sampleBuffer, ofType: sampleBufferType)
186
- }
187
- }
188
- ```
189
-
190
- Replace `{{GROUP_IDENTIFIER}}` and `{{BUNDLE_IDENTIFIER}}` with your group
191
- identifier and bundle identifier respectively.
192
-
193
- 6. In project's Podfile add the following code:
194
- ```rb
195
- target 'MembraneScreenBroadcastExtension' do
196
- pod 'MembraneRTC/Broadcast'
197
- end
198
- ```
199
- > This new dependency should be added outside of your application target.
200
- > Example
201
- >
202
- > ```rb
203
- > target 'ReactNativeMembraneExample' do
204
- > ...
205
- > end
206
- >
207
- > target 'MembraneScreenBroadcastExtension' do
208
- > pod 'MembraneRTC/Broadcast'
209
- > end
210
- > ```
211
- 7. Run `pod install` in your `ios/` directory
212
- 8. Add the following constants in your Info.plist:
213
- ```xml
214
- <key>AppGroupName</key>
215
- <string>{{GROUP_IDENTIFIER}}</string>
216
- <key>ScreencastExtensionBundleId</key>
217
- <string>{{BUNDLE_IDENTIFIER}}.MembraneBroadcastSampleHandler</string>
218
- ```
219
- Replace `{{GROUP_IDENTIFIER}}` and `{{BUNDLE_IDENTIFIER}}` with your group
220
- identifier and bundle identifier respectively.
221
- 9. Rebuild the app and enjoy!
222
-
223
- # Example
224
-
225
- We strongly recommend checking out our example app that implements a basic video
226
- room client. To run the app:
227
-
228
- 1. Go to Membrane's server demo repo: https://fishjam.io/app/login Follow
229
- instructions there to setup and run demo server.
230
- 2. Clone the repo
231
- 3. ```
232
- yarn
233
- yarn build
234
- cd `examples/fishjam-chat`
235
- npx expo prebuild --clean
236
- ```
237
- 4. Copy `.env.template` and create `.env` with proper secrets.
238
- 5. `yarn run android` or `yarn run ios` or run project from Android Studio /
239
- Xcode just like every RN project. Note that simulators won't work, you have
240
- to test on real device for camera and screensharing to run.
241
-
242
- # Usage
243
-
244
- > [!CAUTION]
245
- > This part of documentation is out of date. It will be updated soon.
246
-
247
- Connect to the server and join the room using the `connect` function. Use user
248
- metadata to pass things like usernames etc. to the server.
249
-
250
- ```ts
251
- const startServerConnection = () => {
252
- try {
253
- await connect('http://server_address:5002', 'peer_token', {
254
- displayName: 'Annie',
255
- });
256
- } catch (e) {
257
- console.log('error!');
258
- }
259
- };
260
- ```
261
-
262
- Remember to gracefully disconnect from the server using the `leaveRoom()`
263
- function:
264
-
265
- ```ts
266
- const stopServerConnection = () => {
267
- await leaveRoom();
268
- };
269
- ```
270
-
271
- Start the device's camera and microphone using `useCamera()` and
272
- `useMicrophone()` hooks. Use `videoTrackMetadata` and `audioTrackMetadata`
273
- options to send metadata about the tracks (for example whether it's a camera or
274
- screencast track).
275
-
276
- ```ts
277
- const { startCamera } = useCamera();
278
- const { startMicrophone } = useMicrophone();
279
-
280
- await startCamera({
281
- quality: VideoQuality.HD_169,
282
- videoTrackMetadata: { active: true, type: 'camera' },
283
- });
284
- await startMicrophone({ audioTrackMetadata: { active: true, type: 'audio' } });
285
- ```
286
-
287
- For more options and functions to control the camera and microphone see the API
288
- documentation.
289
-
290
- If you have the connection set up, then use `useParticipants()` hook to track
291
- the other participants in the room. One of the participants will be a local
292
- participant (the one who's using the device). When participants is added or
293
- removed because an user joins or leaves the room, the participants will be
294
- updated automatically. Simply call the hook like this:
295
-
296
- ```ts
297
- const participants = useParticipants();
298
- ```
299
-
300
- When you have the participants all that's left is to render their video tracks.
301
- Use `<VideoRendererView />` component like this:
302
-
303
- ```ts
304
- {
305
- endpoint.videoTracks.map((track) => (
306
- <VideoRendererView trackId={track.id} />
307
- ));
308
- }
309
- ```
310
-
311
- You can style the views to lay out them however you'd like, basic animations
312
- should work too.
313
-
314
- There are also some simple hooks for toggling camera, microphone and
315
- screensharing. Use them like this:
316
-
317
- ```ts
318
- const { isCameraOn, toggleCamera } = useCameraState();
319
- const { isMicrophoneOn, toggleMicrophone } = useMicrophoneState();
320
- ```
321
-
322
- For screencasting use `useScreencast()` hook. The local endpoint will have a new
323
- video track which you can render just like an ordinary video track with
324
- <VideoRendererView />:
325
-
326
- ```ts
327
- const { isScreencastOn, toggleScreencast } = useScreencast();
328
- ...
329
- toggleScreencast({screencastMetadata: { displayName: "Annie's desktop" }});
330
- ```
331
-
332
- Use track metadata to differentiate between video and screencast tracks.
333
-
334
- ### Android foreground service
335
-
336
- > [!NOTE]
337
- > If you're using our plugin with `enableForegroundService` set to `true`. Not further steps are required.
338
-
339
- In order for the call to continue running when app is in background, you need to
340
- set up and start a foreground service. You can use a 3rd party library for this,
341
- for example [notifee](https://notifee.app/).
342
-
343
- In `AndroidManifest.xml` specify necessary permissions:
344
-
345
- ```xml
346
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
347
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
348
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
349
- ```
350
-
351
- And add foreground service:
352
-
353
- ```xml
354
- <application
355
- ...
356
- >
357
- ...
358
- <service
359
- android:name="app.notifee.core.ForegroundService"
360
- android:foregroundServiceType="mediaProjection|camera|microphone" />
361
- </application>
362
- ```
363
-
364
- Then to start the foreground service:
365
-
366
- ```ts
367
- import notifee, { AndroidImportance } from '@notifee/react-native';
368
-
369
- const startForegroundService = async () => {
370
- if (Platform.OS === 'android') {
371
- const channelId = await notifee.createChannel({
372
- id: 'video_call',
373
- name: 'Video call',
374
- lights: false,
375
- vibration: false,
376
- importance: AndroidImportance.DEFAULT,
377
- });
378
-
379
- await notifee.displayNotification({
380
- title: 'Your video call is ongoing',
381
- body: 'Tap to return to the call.',
382
- android: {
383
- channelId,
384
- asForegroundService: true,
385
- ongoing: true,
386
- pressAction: {
387
- id: 'default',
388
- },
389
- },
390
- });
391
- }
392
- };
393
- ```
11
+ # Documentation
394
12
 
395
- Don't forget to also stop the service when the call has ended:
13
+ Check out our [documentation](https://fishjam-cloud.github.io/documentation/) on how Fishjam Cloud work and how to integrate our service with your app.
396
14
 
397
- ```ts
398
- notifee.stopForegroundService();
399
- ```
15
+ There is also API documentation available.
400
16
 
401
- Also add this code in your `index.js` to register the service:
17
+ # Examples
402
18
 
403
- ```js
404
- notifee.registerForegroundService((notification) => {
405
- return new Promise(() => {});
406
- });
407
- ```
19
+ There is simple example app, that allows you to test our service. To run it locally, follow [instructions](https://github.com/fishjam-cloud/mobile-client-sdk/tree/main/examples/fishjam-chat#react-native-fishjam-cloud-example).
408
20
 
409
21
  ## Copyright and License
410
22
 
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
2
2
  apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
- def packageVersion = '0.2.3'
5
+ def packageVersion = '0.2.4'
6
6
 
7
7
  group = 'io.fishjam.reactnative'
8
8
  version = "${packageVersion}"
@@ -3,7 +3,7 @@ package io.fishjam.reactnative
3
3
  object EmitableEvents {
4
4
  const val IsCameraOn = "IsCameraOn"
5
5
  const val IsMicrophoneOn = "IsMicrophoneOn"
6
- const val IsScreencastOn = "IsScreencastOn"
6
+ const val IsScreenShareOn = "IsScreenShareOn"
7
7
  const val SimulcastConfigUpdate = "SimulcastConfigUpdate"
8
8
  const val PeersUpdate = "PeersUpdate"
9
9
  const val AudioDeviceUpdate = "AudioDeviceUpdate"
@@ -11,7 +11,8 @@ class ConnectionError(
11
11
  reason: AuthError
12
12
  ) : CodedException(message = "Connection error: ${reason.error}")
13
13
 
14
- class MissingScreencastPermission : CodedException(message = "No permission to start screencast, call handleScreencastPermission first.")
14
+ class MissingScreenSharePermission :
15
+ CodedException(message = "No permission to start screen share, call handleScreenSharePermission first.")
15
16
 
16
17
  class ClientNotConnectedError : CodedException(message = "Client not connected to server yet. Make sure to call connect() first!")
17
18
 
@@ -19,7 +20,7 @@ class NoLocalVideoTrackError : CodedException(message = "No local video track. M
19
20
 
20
21
  class NoLocalAudioTrackError : CodedException(message = "No local audio track. Make sure to call connect() first!")
21
22
 
22
- class NoScreencastTrackError : CodedException(message = "No local screencast track. Make sure to toggle screencast on first!")
23
+ class NoScreenShareTrackError : CodedException(message = "No local screen share track. Make sure to toggle screen share on first!")
23
24
 
24
25
  class SocketClosedError(
25
26
  code: Int,