@fishjam-cloud/react-native-client 0.1.0
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/.eslintignore +7 -0
- package/.eslintrc +6 -0
- package/.prettierrc +9 -0
- package/.watchmanconfig +1 -0
- package/android/.editorconfig +9 -0
- package/android/build.gradle +89 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/org/membraneframework/reactnative/AudioDeviceKind.kt +34 -0
- package/android/src/main/java/org/membraneframework/reactnative/AudioSwitchManager.kt +61 -0
- package/android/src/main/java/org/membraneframework/reactnative/EmitableEvents.kt +14 -0
- package/android/src/main/java/org/membraneframework/reactnative/Errors.kt +31 -0
- package/android/src/main/java/org/membraneframework/reactnative/RNFishjamClient.kt +866 -0
- package/android/src/main/java/org/membraneframework/reactnative/RNFishjamClientModule.kt +294 -0
- package/android/src/main/java/org/membraneframework/reactnative/Utils.kt +11 -0
- package/android/src/main/java/org/membraneframework/reactnative/VideoPreviewView.kt +40 -0
- package/android/src/main/java/org/membraneframework/reactnative/VideoPreviewViewModule.kt +17 -0
- package/android/src/main/java/org/membraneframework/reactnative/VideoRendererView.kt +58 -0
- package/android/src/main/java/org/membraneframework/reactnative/VideoRendererViewModule.kt +25 -0
- package/android/src/main/java/org/membraneframework/reactnative/VideoView.kt +77 -0
- package/app.plugin.js +1 -0
- package/babel.config.js +2 -0
- package/build/RNFishjamClientModule.d.ts +47 -0
- package/build/RNFishjamClientModule.d.ts.map +1 -0
- package/build/RNFishjamClientModule.js +4 -0
- package/build/RNFishjamClientModule.js.map +1 -0
- package/build/common/client.d.ts +19 -0
- package/build/common/client.d.ts.map +1 -0
- package/build/common/client.js +8 -0
- package/build/common/client.js.map +1 -0
- package/build/common/eventEmitter.d.ts +16 -0
- package/build/common/eventEmitter.d.ts.map +1 -0
- package/build/common/eventEmitter.js +17 -0
- package/build/common/eventEmitter.js.map +1 -0
- package/build/common/metadata.d.ts +7 -0
- package/build/common/metadata.d.ts.map +1 -0
- package/build/common/metadata.js +9 -0
- package/build/common/metadata.js.map +1 -0
- package/build/common/webRTC.d.ts +19 -0
- package/build/common/webRTC.d.ts.map +1 -0
- package/build/common/webRTC.js +22 -0
- package/build/common/webRTC.js.map +1 -0
- package/build/components/VideoPreviewView.d.ts +21 -0
- package/build/components/VideoPreviewView.d.ts.map +1 -0
- package/build/components/VideoPreviewView.js +7 -0
- package/build/components/VideoPreviewView.js.map +1 -0
- package/build/components/VideoRendererView.d.ts +19 -0
- package/build/components/VideoRendererView.d.ts.map +1 -0
- package/build/components/VideoRendererView.js +7 -0
- package/build/components/VideoRendererView.js.map +1 -0
- package/build/hooks/useAudioSettings.d.ts +23 -0
- package/build/hooks/useAudioSettings.d.ts.map +1 -0
- package/build/hooks/useAudioSettings.js +72 -0
- package/build/hooks/useAudioSettings.js.map +1 -0
- package/build/hooks/useBandwidthEstimation.d.ts +12 -0
- package/build/hooks/useBandwidthEstimation.d.ts.map +1 -0
- package/build/hooks/useBandwidthEstimation.js +16 -0
- package/build/hooks/useBandwidthEstimation.js.map +1 -0
- package/build/hooks/useCamera.d.ts +80 -0
- package/build/hooks/useCamera.d.ts.map +1 -0
- package/build/hooks/useCamera.js +140 -0
- package/build/hooks/useCamera.js.map +1 -0
- package/build/hooks/useMicrophone.d.ts +8 -0
- package/build/hooks/useMicrophone.d.ts.map +1 -0
- package/build/hooks/useMicrophone.js +27 -0
- package/build/hooks/useMicrophone.js.map +1 -0
- package/build/hooks/useParticipants.d.ts +62 -0
- package/build/hooks/useParticipants.d.ts.map +1 -0
- package/build/hooks/useParticipants.js +32 -0
- package/build/hooks/useParticipants.js.map +1 -0
- package/build/hooks/useReconnection.d.ts +5 -0
- package/build/hooks/useReconnection.d.ts.map +1 -0
- package/build/hooks/useReconnection.js +23 -0
- package/build/hooks/useReconnection.js.map +1 -0
- package/build/hooks/useScreencast.d.ts +38 -0
- package/build/hooks/useScreencast.d.ts.map +1 -0
- package/build/hooks/useScreencast.js +81 -0
- package/build/hooks/useScreencast.js.map +1 -0
- package/build/index.d.ts +24 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +14 -0
- package/build/index.js.map +1 -0
- package/build/protos/fishjam/peer_notifications.d.ts +63 -0
- package/build/protos/fishjam/peer_notifications.d.ts.map +1 -0
- package/build/protos/fishjam/peer_notifications.js +235 -0
- package/build/protos/fishjam/peer_notifications.js.map +1 -0
- package/build/stats/types.d.ts +55 -0
- package/build/stats/types.d.ts.map +1 -0
- package/build/stats/types.js +2 -0
- package/build/stats/types.js.map +1 -0
- package/build/stats/useRTCStatistics.d.ts +8 -0
- package/build/stats/useRTCStatistics.d.ts.map +1 -0
- package/build/stats/useRTCStatistics.js +78 -0
- package/build/stats/useRTCStatistics.js.map +1 -0
- package/build/types.d.ts +43 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/expo-module.config.json +17 -0
- package/ios/Events.swift +13 -0
- package/ios/RNFishjamClient.podspec +30 -0
- package/ios/RNFishjamClient.swift +836 -0
- package/ios/RNFishjamClientModule.swift +220 -0
- package/ios/Utils.swift +43 -0
- package/ios/VideoPreviewView.swift +64 -0
- package/ios/VideoPreviewViewModule.swift +21 -0
- package/ios/VideoRendererView.swift +84 -0
- package/ios/VideoRendererViewModule.swift +17 -0
- package/ios/swift-format-config.json +56 -0
- package/package.json +89 -0
- package/plugin/broadcastExtensionFiles/Info.plist +27 -0
- package/plugin/broadcastExtensionFiles/MembraneBroadcastSampleHandler.swift +50 -0
- package/plugin/broadcastExtensionFiles/MembraneScreenBroadcastExtension.entitlements +10 -0
- package/plugin/src/withMembrane.ts +310 -0
- package/plugin/tsconfig.json +9 -0
- package/scripts/lint.sh +18 -0
- package/scripts/lint_check.sh +14 -0
- package/src/RNFishjamClientModule.ts +73 -0
- package/src/__tests__/index.test.tsx +199 -0
- package/src/common/client.ts +33 -0
- package/src/common/eventEmitter.ts +21 -0
- package/src/common/metadata.ts +12 -0
- package/src/common/webRTC.ts +31 -0
- package/src/components/VideoPreviewView.tsx +33 -0
- package/src/components/VideoRendererView.tsx +31 -0
- package/src/hooks/useAudioSettings.ts +115 -0
- package/src/hooks/useBandwidthEstimation.ts +24 -0
- package/src/hooks/useCamera.ts +270 -0
- package/src/hooks/useMicrophone.ts +38 -0
- package/src/hooks/useParticipants.ts +118 -0
- package/src/hooks/useReconnection.ts +41 -0
- package/src/hooks/useScreencast.ts +146 -0
- package/src/index.tsx +63 -0
- package/src/protos/fishjam/peer_notifications.ts +299 -0
- package/src/stats/types.ts +56 -0
- package/src/stats/useRTCStatistics.ts +97 -0
- package/src/types.ts +49 -0
- package/tsconfig.json +9 -0
- package/typedoc.json +5 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TrackEncoding } from '../types';
|
|
2
|
+
import RNFishjamClientModule from '../RNFishjamClientModule';
|
|
3
|
+
|
|
4
|
+
export type LoggingSeverity = 'verbose' | 'info' | 'warning' | 'error' | 'none';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* sets track encoding that server should send to the client library.
|
|
8
|
+
* The encoding will be sent whenever it is available. If chooses encoding is
|
|
9
|
+
* temporarily unavailable, some other encoding will be sent until choose encoding
|
|
10
|
+
* becomes active again.
|
|
11
|
+
*
|
|
12
|
+
* @param trackId id of a track which encoding you want to select
|
|
13
|
+
* @param encoding encoding to select
|
|
14
|
+
*/
|
|
15
|
+
export async function setTargetTrackEncoding(
|
|
16
|
+
trackId: string,
|
|
17
|
+
encoding: TrackEncoding,
|
|
18
|
+
) {
|
|
19
|
+
await RNFishjamClientModule.setTargetTrackEncoding(trackId, encoding);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Function that changes level of debugging logs in WebRTC.
|
|
24
|
+
* @param severity to use when displaying logs
|
|
25
|
+
* @returns a promise that is resolved when debug severity is changed
|
|
26
|
+
*/
|
|
27
|
+
export function changeWebRTCLoggingSeverity(
|
|
28
|
+
severity: LoggingSeverity,
|
|
29
|
+
): Promise<void> {
|
|
30
|
+
return RNFishjamClientModule.changeWebRTCLoggingSeverity(severity);
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { ViewStyle } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import { VideoLayout } from '../types';
|
|
6
|
+
import { CaptureDeviceId } from '../hooks/useCamera';
|
|
7
|
+
|
|
8
|
+
export type VideoPreviewViewProps = {
|
|
9
|
+
/**
|
|
10
|
+
* `FILL` or `FIT` - it works just like RN Image component. `FILL` fills the whole view
|
|
11
|
+
* with video and it may cut some parts of the video. `FIT` scales the video so the whole
|
|
12
|
+
* video is visible, but it may leave some empty space in the view.
|
|
13
|
+
* @default `FILL`
|
|
14
|
+
*/
|
|
15
|
+
videoLayout?: VideoLayout;
|
|
16
|
+
style?: ViewStyle;
|
|
17
|
+
/**
|
|
18
|
+
* Id of the camera used for preview. Get available cameras with `getCaptureDevices()` function.
|
|
19
|
+
* @default the first front camera
|
|
20
|
+
*/
|
|
21
|
+
captureDeviceId?: CaptureDeviceId;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const NativeView: React.ComponentType<VideoPreviewViewProps> =
|
|
25
|
+
requireNativeViewManager('VideoPreviewViewModule');
|
|
26
|
+
|
|
27
|
+
export const VideoPreviewView = React.forwardRef<
|
|
28
|
+
React.ComponentType<VideoPreviewViewProps>,
|
|
29
|
+
VideoPreviewViewProps
|
|
30
|
+
>((props, ref) => (
|
|
31
|
+
// @ts-expect-error ref prop needs to be updated
|
|
32
|
+
<NativeView {...props} ref={ref} />
|
|
33
|
+
));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { ViewStyle } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import { VideoLayout } from '../types';
|
|
6
|
+
|
|
7
|
+
export type VideoRendererProps = {
|
|
8
|
+
/**
|
|
9
|
+
* id of the video track which you want to render.
|
|
10
|
+
*/
|
|
11
|
+
trackId: string;
|
|
12
|
+
/**
|
|
13
|
+
* `FILL` or `FIT` - it works just like RN Image component. `FILL` fills the whole view
|
|
14
|
+
* with video and it may cut some parts of the video. `FIT` scales the video so the whole
|
|
15
|
+
* video is visible, but it may leave some empty space in the view.
|
|
16
|
+
* @default `FILL`
|
|
17
|
+
*/
|
|
18
|
+
videoLayout?: VideoLayout;
|
|
19
|
+
style?: ViewStyle;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const NativeView: React.ComponentType<VideoRendererProps> =
|
|
23
|
+
requireNativeViewManager('VideoRendererViewModule');
|
|
24
|
+
|
|
25
|
+
export const VideoRendererView = React.forwardRef<
|
|
26
|
+
React.ComponentType<VideoRendererProps>,
|
|
27
|
+
VideoRendererProps
|
|
28
|
+
>((props, ref) => (
|
|
29
|
+
// @ts-expect-error ref prop needs to be updated
|
|
30
|
+
<NativeView {...props} ref={ref} />
|
|
31
|
+
));
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import RNFishjamClientModule from '../RNFishjamClientModule';
|
|
5
|
+
import { ReceivableEvents, eventEmitter } from '../common/eventEmitter';
|
|
6
|
+
|
|
7
|
+
export type AudioOutputDeviceType =
|
|
8
|
+
| 'bluetooth'
|
|
9
|
+
| 'headset'
|
|
10
|
+
| 'speaker'
|
|
11
|
+
| 'earpiece';
|
|
12
|
+
|
|
13
|
+
export type AudioSessionMode = 'voiceChat' | 'videoChat';
|
|
14
|
+
|
|
15
|
+
export type AudioOutputDevice = {
|
|
16
|
+
type: AudioOutputDeviceType;
|
|
17
|
+
name: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type OnAudioDeviceEvent = {
|
|
21
|
+
AudioDeviceUpdate: {
|
|
22
|
+
selectedDevice: AudioOutputDevice;
|
|
23
|
+
availableDevices: AudioOutputDevice[];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This hook manages audio settings.
|
|
29
|
+
*/
|
|
30
|
+
export function useAudioSettings() {
|
|
31
|
+
const [selectedAudioOutputDevice, setSelectedAudioOutputDevice] =
|
|
32
|
+
useState<AudioOutputDevice | null>(null);
|
|
33
|
+
const [availableDevices, setAvailableDevices] = useState<AudioOutputDevice[]>(
|
|
34
|
+
[],
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const onAudioDevice = useCallback((event: OnAudioDeviceEvent) => {
|
|
38
|
+
setSelectedAudioOutputDevice(event.AudioDeviceUpdate.selectedDevice);
|
|
39
|
+
setAvailableDevices(event.AudioDeviceUpdate.availableDevices);
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const eventListener = eventEmitter.addListener(
|
|
44
|
+
ReceivableEvents.AudioDeviceUpdate,
|
|
45
|
+
onAudioDevice,
|
|
46
|
+
);
|
|
47
|
+
RNFishjamClientModule.startAudioSwitcher();
|
|
48
|
+
return () => {
|
|
49
|
+
eventListener.remove();
|
|
50
|
+
if (Platform.OS === 'android') {
|
|
51
|
+
RNFishjamClientModule.stopAudioSwitcher();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}, [onAudioDevice]);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* [Android only] selects output audio device.
|
|
58
|
+
* For detecting and selecting bluettoth devices make sure you have the BLUETOOTH_CONNECT permission.
|
|
59
|
+
*/
|
|
60
|
+
const selectOutputAudioDevice = useCallback(
|
|
61
|
+
async (device: AudioOutputDeviceType) => {
|
|
62
|
+
if (Platform.OS === 'ios') {
|
|
63
|
+
throw Error(
|
|
64
|
+
'selectOutputAudioDevice function is supported only on Android. ' +
|
|
65
|
+
'To select an output audio device on iOS use selectAudioSessionMode or showAudioRoutePicker functions',
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
await RNFishjamClientModule.setOutputAudioDevice(device);
|
|
69
|
+
},
|
|
70
|
+
[],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* [iOS only] selects audio session mode. For more information refer to Apple's documentation:
|
|
75
|
+
* https://developer.apple.com/documentation/avfaudio/avaudiosession/mode/
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
const selectAudioSessionMode = useCallback(
|
|
79
|
+
async (audioSessionMode: AudioSessionMode) => {
|
|
80
|
+
if (Platform.OS === 'android') {
|
|
81
|
+
throw Error('selectAudioSessionMode function is supported only on iOS');
|
|
82
|
+
}
|
|
83
|
+
await RNFishjamClientModule.selectAudioSessionMode(audioSessionMode);
|
|
84
|
+
},
|
|
85
|
+
[],
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* [iOS only] Shows a picker modal that allows user to select output audio device. For more
|
|
90
|
+
* information refer to Apple's documentation: https://developer.apple.com/documentation/avkit/avroutepickerview
|
|
91
|
+
*/
|
|
92
|
+
const showAudioRoutePicker = useCallback(async () => {
|
|
93
|
+
if (Platform.OS === 'android') {
|
|
94
|
+
throw Error(
|
|
95
|
+
'showAudioRoutePicker function is supported only on iOS. ' +
|
|
96
|
+
'To select an output audio device on Android use selectOutputAudioDevice function',
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
await RNFishjamClientModule.showAudioRoutePicker();
|
|
100
|
+
}, []);
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
/**
|
|
104
|
+
* currently selected output audio device
|
|
105
|
+
*/
|
|
106
|
+
selectedAudioOutputDevice,
|
|
107
|
+
/**
|
|
108
|
+
* [Android only] available audio output devices to be set
|
|
109
|
+
*/
|
|
110
|
+
availableDevices,
|
|
111
|
+
selectOutputAudioDevice,
|
|
112
|
+
selectAudioSessionMode,
|
|
113
|
+
showAudioRoutePicker,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ReceivableEvents, eventEmitter } from '../common/eventEmitter';
|
|
4
|
+
|
|
5
|
+
export type BandwidthEstimationEvent = { BandwidthEstimation: number };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This hook provides current bandwidth estimation
|
|
9
|
+
* estimation - client's available incoming bitrate estimated
|
|
10
|
+
* by the server. It's measured in bits per second.
|
|
11
|
+
*/
|
|
12
|
+
export function useBandwidthEstimation() {
|
|
13
|
+
const [estimation, setEstimation] = useState<number | null>(null);
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const eventListener = eventEmitter.addListener<BandwidthEstimationEvent>(
|
|
17
|
+
ReceivableEvents.BandwidthEstimation,
|
|
18
|
+
(event) => setEstimation(event.BandwidthEstimation),
|
|
19
|
+
);
|
|
20
|
+
return () => eventListener.remove();
|
|
21
|
+
}, []);
|
|
22
|
+
|
|
23
|
+
return { estimation };
|
|
24
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
BandwidthLimit,
|
|
6
|
+
Brand,
|
|
7
|
+
SimulcastBandwidthLimit,
|
|
8
|
+
SimulcastConfig,
|
|
9
|
+
TrackBandwidthLimit,
|
|
10
|
+
TrackEncoding,
|
|
11
|
+
} from '../types';
|
|
12
|
+
import RNFishjamClientModule from '../RNFishjamClientModule';
|
|
13
|
+
import { ReceivableEvents, eventEmitter } from '../common/eventEmitter';
|
|
14
|
+
|
|
15
|
+
type IsCameraOnEvent = { IsCameraOn: boolean };
|
|
16
|
+
type SimulcastConfigUpdateEvent = SimulcastConfig;
|
|
17
|
+
export type CaptureDeviceId = Brand<string, 'CaptureDeviceId'>;
|
|
18
|
+
|
|
19
|
+
export type CaptureDevice = {
|
|
20
|
+
id: CaptureDeviceId;
|
|
21
|
+
name: string;
|
|
22
|
+
isFrontFacing: boolean;
|
|
23
|
+
isBackFacing: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type VideoQuality =
|
|
27
|
+
| 'QVGA169'
|
|
28
|
+
| 'VGA169'
|
|
29
|
+
| 'QHD169'
|
|
30
|
+
| 'HD169'
|
|
31
|
+
| 'FHD169'
|
|
32
|
+
| 'QVGA43'
|
|
33
|
+
| 'VGA43'
|
|
34
|
+
| 'QHD43'
|
|
35
|
+
| 'HD43'
|
|
36
|
+
| 'FHD43';
|
|
37
|
+
|
|
38
|
+
type CameraConfigBase = {
|
|
39
|
+
/**
|
|
40
|
+
* resolution + aspect ratio of local video track, one of: `QVGA_169`, `VGA_169`, `QHD_169`, `HD_169`,
|
|
41
|
+
* `FHD_169`, `QVGA_43`, `VGA_43`, `QHD_43`, `HD_43`, `FHD_43`. Note that quality might be worse than
|
|
42
|
+
* specified due to device capabilities, internet connection etc.
|
|
43
|
+
* @default `VGA_169`
|
|
44
|
+
*/
|
|
45
|
+
quality?: VideoQuality;
|
|
46
|
+
/**
|
|
47
|
+
* whether to flip the dimensions of the video, that is whether to film in vertical orientation.
|
|
48
|
+
* @default `true`
|
|
49
|
+
*/
|
|
50
|
+
flipVideo?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* whether the camera track is initially enabled, you can toggle it on/off later with toggleCamera method
|
|
53
|
+
* @default `true`
|
|
54
|
+
*/
|
|
55
|
+
cameraEnabled?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* id of the camera to start capture with. Get available cameras with `getCaptureDevices()`.
|
|
58
|
+
* You can switch the cameras later with `flipCamera`/`switchCamera` functions.
|
|
59
|
+
* @default the first front camera
|
|
60
|
+
*/
|
|
61
|
+
captureDeviceId?: CaptureDeviceId;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type CameraConfig = CameraConfigBase & {
|
|
65
|
+
/**
|
|
66
|
+
* whether video track uses simulcast. By default simulcast is disabled.
|
|
67
|
+
*/
|
|
68
|
+
simulcastEnabled?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* bandwidth limit of a video track. By default there is no bandwidth limit.
|
|
71
|
+
*/
|
|
72
|
+
maxBandwidth?: TrackBandwidthLimit;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type CameraConfigInternal = CameraConfigBase & {
|
|
76
|
+
videoTrackMetadata?: { active: boolean; type: 'camera' };
|
|
77
|
+
/**
|
|
78
|
+
* SimulcastConfig of a video track. By default simulcast is disabled.
|
|
79
|
+
*/
|
|
80
|
+
simulcastConfig?: SimulcastConfig;
|
|
81
|
+
/**
|
|
82
|
+
* bandwidth limit of a video track. By default there is no bandwidth limit.
|
|
83
|
+
*/
|
|
84
|
+
maxBandwidth?: TrackBandwidthLimit;
|
|
85
|
+
} & (
|
|
86
|
+
| { maxBandwidthInt?: BandwidthLimit }
|
|
87
|
+
| { maxBandwidthMap?: SimulcastBandwidthLimit }
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const defaultSimulcastConfig = () => ({
|
|
91
|
+
enabled: false,
|
|
92
|
+
activeEncodings: [],
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
function maxBandwidthConfig(maxBandwidth: TrackBandwidthLimit | undefined) {
|
|
96
|
+
if (Platform.OS === 'android') {
|
|
97
|
+
if (typeof maxBandwidth === 'object') {
|
|
98
|
+
return {
|
|
99
|
+
maxBandwidth: undefined,
|
|
100
|
+
maxBandwidthMap: maxBandwidth,
|
|
101
|
+
};
|
|
102
|
+
} else {
|
|
103
|
+
return {
|
|
104
|
+
maxBandwidth: undefined,
|
|
105
|
+
maxBandwidthInt: maxBandwidth,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return { maxBandwidth };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function simulcastConfig(
|
|
113
|
+
simulcastEnabled: boolean | undefined,
|
|
114
|
+
): SimulcastConfig | undefined {
|
|
115
|
+
// iOS has a limit of 3 hardware encoders
|
|
116
|
+
// 3 simulcast layers + 1 screencast layer = 4, which is too much
|
|
117
|
+
// so we limit simulcast layers to 2
|
|
118
|
+
if (simulcastEnabled) {
|
|
119
|
+
return Platform.select<SimulcastConfig>({
|
|
120
|
+
ios: { enabled: true, activeEncodings: ['l', 'h'] },
|
|
121
|
+
android: { enabled: true, activeEncodings: ['l', 'm', 'h'] },
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function updateCameraConfig(
|
|
128
|
+
config: Readonly<CameraConfig>,
|
|
129
|
+
): CameraConfigInternal {
|
|
130
|
+
return {
|
|
131
|
+
...config,
|
|
132
|
+
...maxBandwidthConfig(config.maxBandwidth),
|
|
133
|
+
videoTrackMetadata: { active: true, type: 'camera' },
|
|
134
|
+
simulcastConfig: simulcastConfig(config.simulcastEnabled),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* This hook can toggle camera on/off and provides current camera state.
|
|
140
|
+
*/
|
|
141
|
+
export function useCamera() {
|
|
142
|
+
const [isCameraOn, setIsCameraOn] = useState<boolean>(
|
|
143
|
+
RNFishjamClientModule.isCameraOn,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const [simulcastConfig, setSimulcastConfig] = useState<SimulcastConfig>(
|
|
147
|
+
defaultSimulcastConfig(),
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
const eventListener = eventEmitter.addListener<SimulcastConfigUpdateEvent>(
|
|
152
|
+
ReceivableEvents.SimulcastConfigUpdate,
|
|
153
|
+
(event) => setSimulcastConfig(event),
|
|
154
|
+
);
|
|
155
|
+
return () => eventListener.remove();
|
|
156
|
+
}, []);
|
|
157
|
+
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
const eventListener = eventEmitter.addListener<IsCameraOnEvent>(
|
|
160
|
+
ReceivableEvents.IsCameraOn,
|
|
161
|
+
(event) => setIsCameraOn(event.IsCameraOn),
|
|
162
|
+
);
|
|
163
|
+
setIsCameraOn(RNFishjamClientModule.isCameraOn);
|
|
164
|
+
return () => eventListener.remove();
|
|
165
|
+
}, []);
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* toggles encoding of a video track on/off
|
|
169
|
+
* @param encoding encoding to toggle
|
|
170
|
+
*/
|
|
171
|
+
const toggleVideoTrackEncoding = useCallback(
|
|
172
|
+
async (encoding: TrackEncoding) => {
|
|
173
|
+
const videoSimulcastConfig =
|
|
174
|
+
await RNFishjamClientModule.toggleVideoTrackEncoding(encoding);
|
|
175
|
+
setSimulcastConfig(videoSimulcastConfig);
|
|
176
|
+
},
|
|
177
|
+
[],
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* updates maximum bandwidth for the given simulcast encoding of the video track
|
|
182
|
+
* @param encoding encoding to update
|
|
183
|
+
* @param bandwidth BandwidthLimit to set
|
|
184
|
+
*/
|
|
185
|
+
const setVideoTrackEncodingBandwidth = useCallback(
|
|
186
|
+
async (encoding: TrackEncoding, bandwidth: BandwidthLimit) => {
|
|
187
|
+
await RNFishjamClientModule.setVideoTrackEncodingBandwidth(
|
|
188
|
+
encoding,
|
|
189
|
+
bandwidth,
|
|
190
|
+
);
|
|
191
|
+
},
|
|
192
|
+
[],
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Function to toggle camera on/off
|
|
197
|
+
*/
|
|
198
|
+
const toggleCamera = useCallback(async () => {
|
|
199
|
+
const state = await RNFishjamClientModule.toggleCamera();
|
|
200
|
+
await RNFishjamClientModule.updateVideoTrackMetadata({
|
|
201
|
+
active: state,
|
|
202
|
+
type: 'camera',
|
|
203
|
+
});
|
|
204
|
+
setIsCameraOn(state);
|
|
205
|
+
}, []);
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Starts local camera capture.
|
|
209
|
+
* @param config configuration of the camera capture
|
|
210
|
+
* @returns A promise that resolves when camera is started.
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
const startCamera = useCallback(
|
|
214
|
+
async (config: Readonly<CameraConfig> = {}) => {
|
|
215
|
+
const updatedConfig = updateCameraConfig(config);
|
|
216
|
+
await RNFishjamClientModule.startCamera(updatedConfig);
|
|
217
|
+
},
|
|
218
|
+
[],
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Function that toggles between front and back camera. By default the front camera is used.
|
|
223
|
+
* @returns A promise that resolves when camera is toggled.
|
|
224
|
+
*/
|
|
225
|
+
const flipCamera = useCallback(async () => {
|
|
226
|
+
await RNFishjamClientModule.flipCamera();
|
|
227
|
+
}, []);
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Function that switches to the specified camera. By default the front camera is used.
|
|
231
|
+
* @returns A promise that resolves when camera is switched.
|
|
232
|
+
*/
|
|
233
|
+
const switchCamera = useCallback(async (captureDeviceId: CaptureDeviceId) => {
|
|
234
|
+
await RNFishjamClientModule.switchCamera(captureDeviceId);
|
|
235
|
+
}, []);
|
|
236
|
+
|
|
237
|
+
/** Function that queries available cameras.
|
|
238
|
+
* @returns A promise that resolves to the list of available cameras.
|
|
239
|
+
*/
|
|
240
|
+
const getCaptureDevices = useCallback(async () => {
|
|
241
|
+
return RNFishjamClientModule.getCaptureDevices();
|
|
242
|
+
}, []);
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* updates maximum bandwidth for the video track. This value directly translates
|
|
246
|
+
* to quality of the stream and the amount of RTP packets being sent. In case simulcast
|
|
247
|
+
* is enabled bandwidth is split between all of the variant streams proportionally to
|
|
248
|
+
* their resolution.
|
|
249
|
+
* @param BandwidthLimit to set
|
|
250
|
+
*/
|
|
251
|
+
const setVideoTrackBandwidth = useCallback(
|
|
252
|
+
async (bandwidth: BandwidthLimit) => {
|
|
253
|
+
await RNFishjamClientModule.setVideoTrackBandwidth(bandwidth);
|
|
254
|
+
},
|
|
255
|
+
[],
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
isCameraOn,
|
|
260
|
+
simulcastConfig,
|
|
261
|
+
toggleCamera,
|
|
262
|
+
startCamera,
|
|
263
|
+
flipCamera,
|
|
264
|
+
switchCamera,
|
|
265
|
+
getCaptureDevices,
|
|
266
|
+
toggleVideoTrackEncoding,
|
|
267
|
+
setVideoTrackEncodingBandwidth,
|
|
268
|
+
setVideoTrackBandwidth,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import RNFishjamClientModule from '../RNFishjamClientModule';
|
|
4
|
+
import { ReceivableEvents, eventEmitter } from '../common/eventEmitter';
|
|
5
|
+
|
|
6
|
+
type IsMicrophoneOnEvent = { IsMicrophoneOn: boolean };
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This hook can toggle microphone on/off and provides current microphone state.
|
|
10
|
+
*/
|
|
11
|
+
export function useMicrophone() {
|
|
12
|
+
const [isMicrophoneOn, setIsMicrophoneOn] = useState<boolean>(
|
|
13
|
+
RNFishjamClientModule.isMicrophoneOn,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const eventListener = eventEmitter.addListener<IsMicrophoneOnEvent>(
|
|
18
|
+
ReceivableEvents.IsMicrophoneOn,
|
|
19
|
+
(event) => setIsMicrophoneOn(event.IsMicrophoneOn),
|
|
20
|
+
);
|
|
21
|
+
setIsMicrophoneOn(RNFishjamClientModule.isMicrophoneOn);
|
|
22
|
+
return () => eventListener.remove();
|
|
23
|
+
}, []);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Function to toggle microphone on/off
|
|
27
|
+
*/
|
|
28
|
+
const toggleMicrophone = useCallback(async () => {
|
|
29
|
+
const status = await RNFishjamClientModule.toggleMicrophone();
|
|
30
|
+
await RNFishjamClientModule.updateAudioTrackMetadata({
|
|
31
|
+
active: status,
|
|
32
|
+
type: 'audio',
|
|
33
|
+
});
|
|
34
|
+
setIsMicrophoneOn(status);
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
return { isMicrophoneOn, toggleMicrophone };
|
|
38
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { GenericMetadata, TrackEncoding, TrackMetadata } from '../types';
|
|
4
|
+
import RNFishjamClientModule from '../RNFishjamClientModule';
|
|
5
|
+
import { ReceivableEvents, eventEmitter } from '../common/eventEmitter';
|
|
6
|
+
|
|
7
|
+
export type TrackType = 'Audio' | 'Video';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Type describing Voice Activity Detection statuses.
|
|
11
|
+
*
|
|
12
|
+
* speech - voice activity has been detected
|
|
13
|
+
* silence - lack of voice activity has been detected
|
|
14
|
+
*/
|
|
15
|
+
export type VadStatus = 'silence' | 'speech';
|
|
16
|
+
|
|
17
|
+
type TrackBase = {
|
|
18
|
+
id: string;
|
|
19
|
+
type: TrackType;
|
|
20
|
+
isActive: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type AudioTrack = TrackBase & {
|
|
24
|
+
type: 'Audio';
|
|
25
|
+
vadStatus: VadStatus | undefined;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type VideoTrack = TrackBase & {
|
|
29
|
+
type: 'Video';
|
|
30
|
+
// Encoding that is currently received. Only present for remote tracks.
|
|
31
|
+
encoding: TrackEncoding | null;
|
|
32
|
+
// The reason of currently selected encoding. Only present for remote tracks.
|
|
33
|
+
encodingReason: EncodingReason | null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type Track = VideoTrack | AudioTrack;
|
|
37
|
+
/**
|
|
38
|
+
* Type describing possible reasons of currently selected encoding.
|
|
39
|
+
*
|
|
40
|
+
* - other - the exact reason couldn't be determined
|
|
41
|
+
* - encoding_inactive - previously selected encoding became inactive
|
|
42
|
+
* - low_bandwidth - there is no longer enough bandwidth to maintain previously selected encoding
|
|
43
|
+
*/
|
|
44
|
+
export type EncodingReason = 'other' | 'encoding_inactive' | 'low_bandwidth';
|
|
45
|
+
|
|
46
|
+
export type Participant<
|
|
47
|
+
ParticipantMetadata extends GenericMetadata = GenericMetadata,
|
|
48
|
+
> = {
|
|
49
|
+
/**
|
|
50
|
+
* id used to identify a participant
|
|
51
|
+
*/
|
|
52
|
+
id: string;
|
|
53
|
+
/**
|
|
54
|
+
* whether the participant is local or remote
|
|
55
|
+
*/
|
|
56
|
+
isLocal: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* a map indexed by strings, containing participant metadata from the server
|
|
59
|
+
*/
|
|
60
|
+
metadata: ParticipantMetadata;
|
|
61
|
+
/**
|
|
62
|
+
* a list of participants's video and audio tracks
|
|
63
|
+
*/
|
|
64
|
+
tracks: Track[];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type ParticipantsUpdateEvent<
|
|
68
|
+
ParticipantMetadata extends GenericMetadata = GenericMetadata,
|
|
69
|
+
> = {
|
|
70
|
+
PeersUpdate: Participant<ParticipantMetadata>[];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function addIsActiveToTracks<
|
|
74
|
+
ParticipantMetadata extends GenericMetadata = GenericMetadata,
|
|
75
|
+
>(
|
|
76
|
+
participants: ReadonlyArray<Participant<ParticipantMetadata>>,
|
|
77
|
+
): Participant<ParticipantMetadata>[] {
|
|
78
|
+
return participants.map((participant) => ({
|
|
79
|
+
...participant,
|
|
80
|
+
tracks: participant.tracks.map((track) => ({
|
|
81
|
+
...track,
|
|
82
|
+
isActive:
|
|
83
|
+
(track as { metadata?: TrackMetadata })?.metadata?.active ?? true,
|
|
84
|
+
})),
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* This hook provides live updates of room participants.
|
|
89
|
+
* @returns An array of room participants.
|
|
90
|
+
*/
|
|
91
|
+
export function useParticipants<
|
|
92
|
+
ParticipantMetadata extends GenericMetadata = GenericMetadata,
|
|
93
|
+
>() {
|
|
94
|
+
const [participants, setParticipants] = useState<
|
|
95
|
+
Participant<ParticipantMetadata>[]
|
|
96
|
+
>([]);
|
|
97
|
+
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
async function updateParticipants() {
|
|
100
|
+
const participants =
|
|
101
|
+
await RNFishjamClientModule.getPeers<ParticipantMetadata>();
|
|
102
|
+
setParticipants(addIsActiveToTracks<ParticipantMetadata>(participants));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const eventListener = eventEmitter.addListener<
|
|
106
|
+
ParticipantsUpdateEvent<ParticipantMetadata>
|
|
107
|
+
>(ReceivableEvents.PeersUpdate, (event) => {
|
|
108
|
+
setParticipants(
|
|
109
|
+
addIsActiveToTracks<ParticipantMetadata>(event.PeersUpdate),
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
updateParticipants();
|
|
114
|
+
return () => eventListener.remove();
|
|
115
|
+
}, []);
|
|
116
|
+
|
|
117
|
+
return { participants };
|
|
118
|
+
}
|