@fishjam-cloud/react-native-client 0.1.1 → 0.2.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.
Files changed (110) hide show
  1. package/README.md +403 -0
  2. package/android/build.gradle +6 -6
  3. package/app.plugin.js +1 -1
  4. package/build/RNFishjamClientModule.d.ts +7 -5
  5. package/build/RNFishjamClientModule.d.ts.map +1 -1
  6. package/build/RNFishjamClientModule.js.map +1 -1
  7. package/build/common/client.d.ts +8 -1
  8. package/build/common/client.d.ts.map +1 -1
  9. package/build/common/client.js +9 -2
  10. package/build/common/client.js.map +1 -1
  11. package/build/components/VideoPreviewView.d.ts +3 -3
  12. package/build/components/VideoPreviewView.d.ts.map +1 -1
  13. package/build/components/VideoPreviewView.js +1 -1
  14. package/build/components/VideoPreviewView.js.map +1 -1
  15. package/build/hooks/useAudioSettings.d.ts.map +1 -1
  16. package/build/hooks/useAudioSettings.js +4 -5
  17. package/build/hooks/useAudioSettings.js.map +1 -1
  18. package/build/hooks/useBandwidthEstimation.d.ts +0 -3
  19. package/build/hooks/useBandwidthEstimation.d.ts.map +1 -1
  20. package/build/hooks/useBandwidthEstimation.js +3 -6
  21. package/build/hooks/useBandwidthEstimation.js.map +1 -1
  22. package/build/hooks/useCamera.d.ts +12 -21
  23. package/build/hooks/useCamera.d.ts.map +1 -1
  24. package/build/hooks/useCamera.js +52 -52
  25. package/build/hooks/useCamera.js.map +1 -1
  26. package/build/{common/eventEmitter.d.ts → hooks/useFishjamEvent.d.ts} +2 -3
  27. package/build/hooks/useFishjamEvent.d.ts.map +1 -0
  28. package/build/{common/eventEmitter.js → hooks/useFishjamEvent.js} +11 -2
  29. package/build/hooks/useFishjamEvent.js.map +1 -0
  30. package/build/hooks/useMicrophone.d.ts.map +1 -1
  31. package/build/hooks/useMicrophone.js +3 -7
  32. package/build/hooks/useMicrophone.js.map +1 -1
  33. package/build/hooks/useParticipants.d.ts +0 -3
  34. package/build/hooks/useParticipants.d.ts.map +1 -1
  35. package/build/hooks/useParticipants.js +6 -6
  36. package/build/hooks/useParticipants.js.map +1 -1
  37. package/build/hooks/useReconnection.d.ts.map +1 -1
  38. package/build/hooks/useReconnection.js +8 -18
  39. package/build/hooks/useReconnection.js.map +1 -1
  40. package/build/hooks/useScreencast.d.ts.map +1 -1
  41. package/build/hooks/useScreencast.js +3 -7
  42. package/build/hooks/useScreencast.js.map +1 -1
  43. package/build/index.d.ts +4 -3
  44. package/build/index.d.ts.map +1 -1
  45. package/build/index.js +3 -1
  46. package/build/index.js.map +1 -1
  47. package/build/types.d.ts +25 -0
  48. package/build/types.d.ts.map +1 -1
  49. package/build/types.js +10 -1
  50. package/build/types.js.map +1 -1
  51. package/build/utils/foregroundService.d.ts +30 -0
  52. package/build/utils/foregroundService.d.ts.map +1 -0
  53. package/build/utils/foregroundService.js +41 -0
  54. package/build/utils/foregroundService.js.map +1 -0
  55. package/ios/RNFishjamClient.swift +34 -29
  56. package/ios/RNFishjamClientModule.swift +11 -7
  57. package/package.json +19 -17
  58. package/.eslintignore +0 -7
  59. package/.eslintrc +0 -6
  60. package/.prettierrc +0 -9
  61. package/.watchmanconfig +0 -1
  62. package/android/.editorconfig +0 -9
  63. package/android/src/main/AndroidManifest.xml +0 -2
  64. package/android/src/main/java/org/membraneframework/reactnative/AudioDeviceKind.kt +0 -34
  65. package/android/src/main/java/org/membraneframework/reactnative/AudioSwitchManager.kt +0 -61
  66. package/android/src/main/java/org/membraneframework/reactnative/EmitableEvents.kt +0 -14
  67. package/android/src/main/java/org/membraneframework/reactnative/Errors.kt +0 -31
  68. package/android/src/main/java/org/membraneframework/reactnative/RNFishjamClient.kt +0 -866
  69. package/android/src/main/java/org/membraneframework/reactnative/RNFishjamClientModule.kt +0 -294
  70. package/android/src/main/java/org/membraneframework/reactnative/Utils.kt +0 -11
  71. package/android/src/main/java/org/membraneframework/reactnative/VideoPreviewView.kt +0 -40
  72. package/android/src/main/java/org/membraneframework/reactnative/VideoPreviewViewModule.kt +0 -17
  73. package/android/src/main/java/org/membraneframework/reactnative/VideoRendererView.kt +0 -58
  74. package/android/src/main/java/org/membraneframework/reactnative/VideoRendererViewModule.kt +0 -25
  75. package/android/src/main/java/org/membraneframework/reactnative/VideoView.kt +0 -77
  76. package/babel.config.js +0 -2
  77. package/build/common/eventEmitter.d.ts.map +0 -1
  78. package/build/common/eventEmitter.js.map +0 -1
  79. package/expo-module.config.json +0 -17
  80. package/ios/RNFishjamClient.podspec +0 -30
  81. package/ios/swift-format-config.json +0 -56
  82. package/plugin/broadcastExtensionFiles/Info.plist +0 -27
  83. package/plugin/broadcastExtensionFiles/MembraneBroadcastSampleHandler.swift +0 -50
  84. package/plugin/broadcastExtensionFiles/MembraneScreenBroadcastExtension.entitlements +0 -10
  85. package/plugin/src/withMembrane.ts +0 -310
  86. package/plugin/tsconfig.json +0 -9
  87. package/scripts/lint.sh +0 -18
  88. package/scripts/lint_check.sh +0 -14
  89. package/src/RNFishjamClientModule.ts +0 -73
  90. package/src/__tests__/index.test.tsx +0 -199
  91. package/src/common/client.ts +0 -33
  92. package/src/common/eventEmitter.ts +0 -21
  93. package/src/common/metadata.ts +0 -12
  94. package/src/common/webRTC.ts +0 -31
  95. package/src/components/VideoPreviewView.tsx +0 -33
  96. package/src/components/VideoRendererView.tsx +0 -31
  97. package/src/hooks/useAudioSettings.ts +0 -115
  98. package/src/hooks/useBandwidthEstimation.ts +0 -24
  99. package/src/hooks/useCamera.ts +0 -270
  100. package/src/hooks/useMicrophone.ts +0 -38
  101. package/src/hooks/useParticipants.ts +0 -118
  102. package/src/hooks/useReconnection.ts +0 -41
  103. package/src/hooks/useScreencast.ts +0 -146
  104. package/src/index.tsx +0 -63
  105. package/src/protos/fishjam/peer_notifications.ts +0 -299
  106. package/src/stats/types.ts +0 -56
  107. package/src/stats/useRTCStatistics.ts +0 -97
  108. package/src/types.ts +0 -49
  109. package/tsconfig.json +0 -9
  110. package/typedoc.json +0 -5
@@ -1,33 +0,0 @@
1
- import { GenericMetadata } from '../types';
2
- import RNFishjamClientModule from '../RNFishjamClientModule';
3
-
4
- export type ConnectionConfig = {
5
- /**
6
- * Configuration for automatic reconnection
7
- * sdk uses a linear backoff algorithm, that is the formula
8
- * for the delay of the nth attempt is
9
- * n * delayMs + initialDelayMs
10
- *
11
- * Pass 0 for maxAttempts to disable automatic reconnection
12
- */
13
- reconnectConfig?: {
14
- maxAttempts?: number;
15
- initialDelayMs?: number;
16
- delayMs?: number;
17
- };
18
- };
19
-
20
- export async function connect<
21
- ParticipantMetadata extends GenericMetadata = GenericMetadata,
22
- >(
23
- url: string,
24
- peerToken: string,
25
- peerMetadata: ParticipantMetadata,
26
- config: ConnectionConfig = {},
27
- ) {
28
- await RNFishjamClientModule.connect(url, peerToken, peerMetadata, config);
29
- }
30
-
31
- export async function leaveRoom() {
32
- await RNFishjamClientModule.leaveRoom();
33
- }
@@ -1,21 +0,0 @@
1
- import { NativeModulesProxy, EventEmitter } from 'expo-modules-core';
2
-
3
- import RNFishjamClientModule from '../RNFishjamClientModule';
4
-
5
- export const ReceivableEvents = {
6
- IsCameraOn: 'IsCameraOn',
7
- IsMicrophoneOn: 'IsMicrophoneOn',
8
- IsScreencastOn: 'IsScreencastOn',
9
- SimulcastConfigUpdate: 'SimulcastConfigUpdate',
10
- PeersUpdate: 'PeersUpdate',
11
- AudioDeviceUpdate: 'AudioDeviceUpdate',
12
- SendMediaEvent: 'SendMediaEvent',
13
- BandwidthEstimation: 'BandwidthEstimation',
14
- ReconnectionRetriesLimitReached: 'ReconnectionRetriesLimitReached',
15
- ReconnectionStarted: 'ReconnectionStarted',
16
- Reconnected: 'Reconnected',
17
- } as const;
18
-
19
- export const eventEmitter = new EventEmitter(
20
- RNFishjamClientModule ?? NativeModulesProxy.RNFishjamClient,
21
- );
@@ -1,12 +0,0 @@
1
- import { GenericMetadata } from '../types';
2
- import RNFishjamClientModule from '../RNFishjamClientModule';
3
-
4
- /**
5
- * a function that updates endpoints's metadata on the server
6
- * @param metadata a map indexed by strings, containing participants metadata to be sent to the server
7
- */
8
- export async function updatePeerMetadata<
9
- ParticipantMetadata extends GenericMetadata = GenericMetadata,
10
- >(metadata: ParticipantMetadata) {
11
- await RNFishjamClientModule.updatePeerMetadata(metadata);
12
- }
@@ -1,31 +0,0 @@
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
- }
@@ -1,33 +0,0 @@
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
- ));
@@ -1,31 +0,0 @@
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
- ));
@@ -1,115 +0,0 @@
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
- }
@@ -1,24 +0,0 @@
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
- }
@@ -1,270 +0,0 @@
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
- }
@@ -1,38 +0,0 @@
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
- }