@fishjam-cloud/react-native-client 0.4.1 → 0.6.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/android/build.gradle +1 -1
- package/android/src/main/java/io/fishjam/reactnative/EmitableEvents.kt +104 -20
- package/android/src/main/java/io/fishjam/reactnative/RNFishjamClient.kt +83 -99
- package/android/src/main/java/io/fishjam/reactnative/RNFishjamClientModule.kt +21 -30
- package/android/src/main/java/io/fishjam/reactnative/VideoRendererViewModule.kt +6 -2
- package/android/src/main/java/io/fishjam/reactnative/VideoView.kt +41 -3
- package/android/src/main/java/io/fishjam/reactnative/extensions/CaptureDevice.kt +17 -0
- package/android/src/main/java/io/fishjam/reactnative/foregroundService/FishjamForegroundService.kt +10 -4
- package/android/src/main/java/io/fishjam/reactnative/foregroundService/ForegroundServiceManager.kt +41 -70
- package/android/src/main/java/io/fishjam/reactnative/foregroundService/ForegroundServiceState.kt +46 -0
- package/android/src/main/java/io/fishjam/reactnative/managers/ListenerManager.kt +22 -0
- package/android/src/main/java/io/fishjam/reactnative/managers/LocalCameraTracksChangedListenersManager.kt +2 -15
- package/android/src/main/java/io/fishjam/reactnative/managers/LocalTracksSwitchListenersManager.kt +1 -11
- package/android/src/main/java/io/fishjam/reactnative/managers/TracksUpdateListenersManager.kt +1 -15
- package/build/RNFishjamClientModule.d.ts +28 -12
- package/build/RNFishjamClientModule.d.ts.map +1 -1
- package/build/RNFishjamClientModule.js +19 -4
- package/build/RNFishjamClientModule.js.map +1 -1
- package/build/common/client.d.ts +0 -4
- package/build/common/client.d.ts.map +1 -1
- package/build/common/client.js +0 -4
- package/build/common/client.js.map +1 -1
- package/build/common/metadata.d.ts +1 -1
- package/build/common/metadata.js +1 -1
- package/build/common/metadata.js.map +1 -1
- package/build/common/webRTC.d.ts +2 -1
- package/build/common/webRTC.d.ts.map +1 -1
- package/build/common/webRTC.js.map +1 -1
- package/build/components/FishjamRoom/GridTrackItem.d.ts +11 -0
- package/build/components/FishjamRoom/GridTrackItem.d.ts.map +1 -0
- package/build/components/FishjamRoom/GridTrackItem.js +56 -0
- package/build/components/FishjamRoom/GridTrackItem.js.map +1 -0
- package/build/components/FishjamRoom/VideosGrid.d.ts +3 -0
- package/build/components/FishjamRoom/VideosGrid.d.ts.map +1 -0
- package/build/components/FishjamRoom/VideosGrid.js +20 -0
- package/build/components/FishjamRoom/VideosGrid.js.map +1 -0
- package/build/components/FishjamRoom/index.d.ts +6 -0
- package/build/components/FishjamRoom/index.d.ts.map +1 -0
- package/build/components/FishjamRoom/index.js +29 -0
- package/build/components/FishjamRoom/index.js.map +1 -0
- package/build/components/FishjamRoom/parsePeersToTracks.d.ts +4 -0
- package/build/components/FishjamRoom/parsePeersToTracks.d.ts.map +1 -0
- package/build/components/FishjamRoom/parsePeersToTracks.js +34 -0
- package/build/components/FishjamRoom/parsePeersToTracks.js.map +1 -0
- package/build/components/VideoRendererView.d.ts +6 -1
- package/build/components/VideoRendererView.d.ts.map +1 -1
- package/build/components/VideoRendererView.js.map +1 -1
- package/build/debug/stats/useRTCStatistics.d.ts.map +1 -1
- package/build/debug/stats/useRTCStatistics.js +13 -13
- package/build/debug/stats/useRTCStatistics.js.map +1 -1
- package/build/hooks/internal/useFishjamEvent.d.ts +3 -0
- package/build/hooks/internal/useFishjamEvent.d.ts.map +1 -0
- package/build/hooks/internal/useFishjamEvent.js +11 -0
- package/build/hooks/internal/useFishjamEvent.js.map +1 -0
- package/build/hooks/internal/useFishjamEventState.d.ts +3 -0
- package/build/hooks/internal/useFishjamEventState.d.ts.map +1 -0
- package/build/hooks/internal/useFishjamEventState.js +18 -0
- package/build/hooks/internal/useFishjamEventState.js.map +1 -0
- package/build/hooks/useAppScreenShare.d.ts.map +1 -1
- package/build/hooks/useAppScreenShare.js +6 -8
- package/build/hooks/useAppScreenShare.js.map +1 -1
- package/build/hooks/useAudioSettings.d.ts.map +1 -1
- package/build/hooks/useAudioSettings.js +8 -11
- package/build/hooks/useAudioSettings.js.map +1 -1
- package/build/hooks/useBandwidthEstimation.d.ts.map +1 -1
- package/build/hooks/useBandwidthEstimation.js +3 -4
- package/build/hooks/useBandwidthEstimation.js.map +1 -1
- package/build/hooks/useCamera.d.ts +6 -2
- package/build/hooks/useCamera.d.ts.map +1 -1
- package/build/hooks/useCamera.js +19 -23
- package/build/hooks/useCamera.js.map +1 -1
- package/build/hooks/useConnection.d.ts +42 -0
- package/build/hooks/useConnection.d.ts.map +1 -0
- package/build/hooks/useConnection.js +33 -0
- package/build/hooks/useConnection.js.map +1 -0
- package/build/hooks/useForegroundService.d.ts +12 -20
- package/build/hooks/useForegroundService.d.ts.map +1 -1
- package/build/hooks/useForegroundService.js +14 -4
- package/build/hooks/useForegroundService.js.map +1 -1
- package/build/hooks/useMicrophone.d.ts.map +1 -1
- package/build/hooks/useMicrophone.js +5 -11
- package/build/hooks/useMicrophone.js.map +1 -1
- package/build/hooks/usePeerStatus.d.ts +2 -3
- package/build/hooks/usePeerStatus.d.ts.map +1 -1
- package/build/hooks/usePeerStatus.js +4 -10
- package/build/hooks/usePeerStatus.js.map +1 -1
- package/build/hooks/usePeers.d.ts +50 -11
- package/build/hooks/usePeers.d.ts.map +1 -1
- package/build/hooks/usePeers.js +42 -18
- package/build/hooks/usePeers.js.map +1 -1
- package/build/hooks/useReconnection.d.ts +1 -1
- package/build/hooks/useReconnection.d.ts.map +1 -1
- package/build/hooks/useReconnection.js +4 -10
- package/build/hooks/useReconnection.js.map +1 -1
- package/build/hooks/useScreenShare.d.ts.map +1 -1
- package/build/hooks/useScreenShare.js +11 -16
- package/build/hooks/useScreenShare.js.map +1 -1
- package/build/hooks/useUpdatePeerMetadata.d.ts +15 -0
- package/build/hooks/useUpdatePeerMetadata.d.ts.map +1 -0
- package/build/hooks/useUpdatePeerMetadata.js +21 -0
- package/build/hooks/useUpdatePeerMetadata.js.map +1 -0
- package/build/index.d.ts +24 -16
- package/build/index.d.ts.map +1 -1
- package/build/index.js +18 -6
- package/build/index.js.map +1 -1
- package/build/types.d.ts +1 -1
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils/errorListener.d.ts.map +1 -1
- package/build/utils/errorListener.js +3 -4
- package/build/utils/errorListener.js.map +1 -1
- package/ios/Events.swift +94 -19
- package/ios/RNFishjamClient.podspec +1 -1
- package/ios/RNFishjamClient.swift +84 -114
- package/ios/RNFishjamClientModule.swift +14 -10
- package/ios/Utils.swift +0 -20
- package/ios/VideoPreviewView.swift +13 -13
- package/ios/VideoRendererView.swift +28 -25
- package/ios/VideoRendererViewModule.swift +8 -4
- package/ios/extensions/AVCaptureDevice.swift +20 -0
- package/package.json +11 -14
- package/plugin/build/withFishjamAndroid.js +18 -20
- package/plugin/build/withFishjamIos.js +99 -103
- package/build/hooks/useFishjamEvent.d.ts +0 -18
- package/build/hooks/useFishjamEvent.d.ts.map +0 -1
- package/build/hooks/useFishjamEvent.js +0 -27
- package/build/hooks/useFishjamEvent.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAudioSettings.js","sourceRoot":"","sources":["../../src/hooks/useAudioSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"useAudioSettings.js","sourceRoot":"","sources":["../../src/hooks/useAudioSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,qBAAqB,EAAE,EAC5B,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAoBvE;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,EAAE,cAAc,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,GACnE,oBAAoB,CAClB,gBAAgB,CAAC,iBAAiB,EAClC;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;;;WAGG;QACH,uBAAuB;QACvB;;;;WAIG;QACH,sBAAsB;QACtB;;;WAGG;QACH,oBAAoB;KACrB,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useEffect } from 'react';\nimport { Platform } from 'react-native';\n\nimport RNFishjamClientModule, {\n ReceivableEvents,\n} from '../RNFishjamClientModule';\nimport { useFishjamEventState } from './internal/useFishjamEventState';\n\nexport type AudioOutputDeviceType =\n | 'bluetooth'\n | 'headset'\n | 'speaker'\n | 'earpiece';\n\nexport type AudioSessionMode = 'voiceChat' | 'videoChat';\n\nexport type AudioOutputDevice = {\n type: AudioOutputDeviceType;\n name: string;\n};\n\ntype OnAudioDeviceEvent = {\n selectedDevice: AudioOutputDevice | null;\n availableDevices: AudioOutputDevice[];\n};\n\n/**\n * This hook manages audio settings.\n * @category Devices\n * @group Hooks\n */\nexport function useAudioSettings() {\n const { selectedDevice: selectedAudioOutputDevice, availableDevices } =\n useFishjamEventState<OnAudioDeviceEvent>(\n ReceivableEvents.AudioDeviceUpdate,\n {\n selectedDevice: null,\n availableDevices: [],\n },\n );\n\n useEffect(() => {\n RNFishjamClientModule.startAudioSwitcher();\n return () => {\n if (Platform.OS === 'android') {\n RNFishjamClientModule.stopAudioSwitcher();\n }\n };\n }, []);\n\n const selectOutputAudioDevice = useCallback(\n async (device: AudioOutputDeviceType) => {\n if (Platform.OS === 'ios') {\n throw Error(\n 'selectOutputAudioDevice function is supported only on Android. ' +\n 'To select an output audio device on iOS use selectAudioSessionMode or showAudioRoutePicker functions',\n );\n }\n await RNFishjamClientModule.setOutputAudioDevice(device);\n },\n [],\n );\n\n const selectAudioSessionMode = useCallback(\n async (audioSessionMode: AudioSessionMode) => {\n if (Platform.OS === 'android') {\n throw Error('selectAudioSessionMode function is supported only on iOS');\n }\n await RNFishjamClientModule.selectAudioSessionMode(audioSessionMode);\n },\n [],\n );\n\n const showAudioRoutePicker = useCallback(async () => {\n if (Platform.OS === 'android') {\n throw Error(\n 'showAudioRoutePicker function is supported only on iOS. ' +\n 'To select an output audio device on Android use selectOutputAudioDevice function',\n );\n }\n await RNFishjamClientModule.showAudioRoutePicker();\n }, []);\n\n return {\n /**\n * currently selected output audio device\n */\n selectedAudioOutputDevice,\n /**\n * [Android only] available audio output devices to be set\n */\n availableDevices,\n /**\n * [Android only] selects output audio device.\n * For detecting and selecting bluettoth devices make sure you have the BLUETOOTH_CONNECT permission.\n */\n selectOutputAudioDevice,\n /**\n * [iOS only] selects audio session mode. For more information refer to Apple's documentation:\n * https://developer.apple.com/documentation/avfaudio/avaudiosession/mode/\n *\n */\n selectAudioSessionMode,\n /**\n * [iOS only] Shows a picker modal that allows user to select output audio device. For more\n * information refer to Apple's documentation: https://developer.apple.com/documentation/avkit/avroutepickerview\n */\n showAudioRoutePicker,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBandwidthEstimation.d.ts","sourceRoot":"","sources":["../../src/hooks/useBandwidthEstimation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useBandwidthEstimation.d.ts","sourceRoot":"","sources":["../../src/hooks/useBandwidthEstimation.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,sBAAsB;;EAMrC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ReceivableEvents } from '../RNFishjamClientModule';
|
|
2
|
+
import { useFishjamEventState } from './internal/useFishjamEventState';
|
|
3
3
|
/**
|
|
4
4
|
* This hook provides current bandwidth estimation
|
|
5
5
|
* estimation - client's available incoming bitrate estimated
|
|
@@ -8,8 +8,7 @@ import { ReceivableEvents, useFishjamEvent } from './useFishjamEvent';
|
|
|
8
8
|
* @group Hooks
|
|
9
9
|
*/
|
|
10
10
|
export function useBandwidthEstimation() {
|
|
11
|
-
const
|
|
12
|
-
useFishjamEvent(ReceivableEvents.BandwidthEstimation, setEstimation);
|
|
11
|
+
const estimation = useFishjamEventState(ReceivableEvents.BandwidthEstimation, null);
|
|
13
12
|
return { estimation };
|
|
14
13
|
}
|
|
15
14
|
//# sourceMappingURL=useBandwidthEstimation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBandwidthEstimation.js","sourceRoot":"","sources":["../../src/hooks/useBandwidthEstimation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useBandwidthEstimation.js","sourceRoot":"","sources":["../../src/hooks/useBandwidthEstimation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,UAAU,GAAG,oBAAoB,CACrC,gBAAgB,CAAC,mBAAmB,EACpC,IAAI,CACL,CAAC;IACF,OAAO,EAAE,UAAU,EAAE,CAAC;AACxB,CAAC","sourcesContent":["import { ReceivableEvents } from '../RNFishjamClientModule';\nimport { useFishjamEventState } from './internal/useFishjamEventState';\n\n/**\n * This hook provides current bandwidth estimation\n * estimation - client's available incoming bitrate estimated\n * by the server. It's measured in bits per second.\n * @category Debugging\n * @group Hooks\n */\nexport function useBandwidthEstimation() {\n const estimation = useFishjamEventState<number | null>(\n ReceivableEvents.BandwidthEstimation,\n null,\n );\n return { estimation };\n}\n"]}
|
|
@@ -6,6 +6,10 @@ export type Camera = {
|
|
|
6
6
|
name: string;
|
|
7
7
|
facingDirection: CameraFacingDirection;
|
|
8
8
|
};
|
|
9
|
+
export type CurrentCameraChangedType = {
|
|
10
|
+
currentCamera: Camera | null;
|
|
11
|
+
isCameraOn: boolean;
|
|
12
|
+
};
|
|
9
13
|
export type VideoQuality = 'QVGA169' | 'VGA169' | 'QHD169' | 'HD169' | 'FHD169' | 'QVGA43' | 'VGA43' | 'QHD43' | 'HD43' | 'FHD43';
|
|
10
14
|
type CameraConfigBase = {
|
|
11
15
|
/**
|
|
@@ -82,7 +86,7 @@ export declare function useCamera(): {
|
|
|
82
86
|
/**
|
|
83
87
|
* Which camera is now used for streaming (or will be used as default when camera will be enabled)
|
|
84
88
|
*/
|
|
85
|
-
currentCamera: Camera |
|
|
89
|
+
currentCamera: Camera | null;
|
|
86
90
|
/**
|
|
87
91
|
* Simulcast configuration
|
|
88
92
|
*/
|
|
@@ -99,7 +103,7 @@ export declare function useCamera(): {
|
|
|
99
103
|
* @param config configuration of the camera capture
|
|
100
104
|
* @returns A promise that resolves when camera is started.
|
|
101
105
|
*/
|
|
102
|
-
prepareCamera: (config?: Readonly<CameraConfig>) => Promise<
|
|
106
|
+
prepareCamera: (config?: Readonly<CameraConfig>) => Promise<boolean>;
|
|
103
107
|
/**
|
|
104
108
|
* Switches to the specified camera.
|
|
105
109
|
* List of available devices can be retrieved from `cameras` variable
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCamera.d.ts","sourceRoot":"","sources":["../../src/hooks/useCamera.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,cAAc,EACd,KAAK,EACL,uBAAuB,EACvB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACd,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"useCamera.d.ts","sourceRoot":"","sources":["../../src/hooks/useCamera.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,cAAc,EACd,KAAK,EACL,uBAAuB,EACvB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACd,MAAM,UAAU,CAAC;AAMlB,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAEjD,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,CAAC;AAErE,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,QAAQ,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,qBAAqB,CAAC;CACxC,CAAC;AA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C,YAAY,CAAC;IA+ErC;;;;OAIG,0BA3D6C,QAAQ;IA6DxD;;;;OAIG;yCArDc,aAAa;IAuD9B;;;;;OAKG;+CArDc,aAAa,aAAa,cAAc;IAuDzD;;;;;;;OAOG;wCA5Ee,cAAc;EA+EnC"}
|
package/build/hooks/useCamera.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useCallback, useMemo
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
2
|
import { Platform } from 'react-native';
|
|
3
|
-
import RNFishjamClientModule from '../RNFishjamClientModule';
|
|
4
|
-
import {
|
|
3
|
+
import RNFishjamClientModule, { ReceivableEvents, } from '../RNFishjamClientModule';
|
|
4
|
+
import { useFishjamEventState } from './internal/useFishjamEventState';
|
|
5
5
|
const defaultSimulcastConfig = () => ({
|
|
6
6
|
enabled: false,
|
|
7
7
|
activeEncodings: [],
|
|
@@ -23,7 +23,7 @@ function maxBandwidthConfig(maxBandwidth) {
|
|
|
23
23
|
}
|
|
24
24
|
return { maxBandwidth };
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function getSimulcastConfig(simulcastEnabled) {
|
|
27
27
|
// iOS has a limit of 3 hardware encoders
|
|
28
28
|
// 3 simulcast layers + 1 screen share layer = 4, which is too much
|
|
29
29
|
// so we limit simulcast layers to 2
|
|
@@ -40,7 +40,7 @@ export function updateCameraConfig(config) {
|
|
|
40
40
|
...config,
|
|
41
41
|
...maxBandwidthConfig({ l: 150, m: 500, h: 1500 }),
|
|
42
42
|
videoTrackMetadata: { active: true, type: 'camera' },
|
|
43
|
-
simulcastConfig:
|
|
43
|
+
simulcastConfig: getSimulcastConfig(config.simulcastEnabled),
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -49,24 +49,23 @@ export function updateCameraConfig(config) {
|
|
|
49
49
|
* @group Hooks
|
|
50
50
|
*/
|
|
51
51
|
export function useCamera() {
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
const simulcastConfig = useFishjamEventState(ReceivableEvents.SimulcastConfigUpdate, defaultSimulcastConfig());
|
|
53
|
+
const { currentCamera: currentCameraState, isCameraOn } = useFishjamEventState(ReceivableEvents.CurrentCameraChanged, {
|
|
54
|
+
currentCamera: RNFishjamClientModule.currentCamera,
|
|
55
|
+
isCameraOn: RNFishjamClientModule.isCameraOn,
|
|
56
|
+
});
|
|
57
|
+
// For Android Expo converts null to undefined ¯\_(ツ)_/¯
|
|
58
|
+
const currentCamera = currentCameraState ?? null;
|
|
59
|
+
const cameras = useMemo(() => RNFishjamClientModule.cameras, []);
|
|
60
60
|
const prepareCamera = useCallback(async (config = {}) => {
|
|
61
|
-
const camera = RNFishjamClientModule.cameras.find((
|
|
62
|
-
?
|
|
63
|
-
:
|
|
64
|
-
setCurrentCamera(camera);
|
|
61
|
+
const camera = RNFishjamClientModule.cameras.find((cam) => config.cameraId
|
|
62
|
+
? cam.id === config.cameraId
|
|
63
|
+
: cam.facingDirection === 'front');
|
|
65
64
|
const updatedConfig = updateCameraConfig({
|
|
66
65
|
...config,
|
|
67
66
|
cameraId: camera?.id,
|
|
68
67
|
});
|
|
69
|
-
|
|
68
|
+
return RNFishjamClientModule.startCamera(updatedConfig);
|
|
70
69
|
}, []);
|
|
71
70
|
const toggleCamera = useCallback(async () => {
|
|
72
71
|
const state = await RNFishjamClientModule.toggleCamera();
|
|
@@ -74,18 +73,15 @@ export function useCamera() {
|
|
|
74
73
|
active: state,
|
|
75
74
|
type: 'camera',
|
|
76
75
|
});
|
|
77
|
-
setIsCameraOn(state);
|
|
78
76
|
}, []);
|
|
79
77
|
const switchCamera = useCallback(async (cameraId) => {
|
|
80
78
|
await RNFishjamClientModule.switchCamera(cameraId);
|
|
81
|
-
|
|
82
|
-
}, [cameras]);
|
|
79
|
+
}, []);
|
|
83
80
|
const setVideoTrackBandwidth = useCallback(async (bandwidth) => {
|
|
84
81
|
await RNFishjamClientModule.setVideoTrackBandwidth(bandwidth);
|
|
85
82
|
}, []);
|
|
86
83
|
const toggleVideoTrackEncoding = useCallback(async (encoding) => {
|
|
87
|
-
|
|
88
|
-
setSimulcastConfig(videoSimulcastConfig);
|
|
84
|
+
await RNFishjamClientModule.toggleVideoTrackEncoding(encoding);
|
|
89
85
|
}, []);
|
|
90
86
|
const setVideoTrackEncodingBandwidth = useCallback(async (encoding, bandwidth) => {
|
|
91
87
|
await RNFishjamClientModule.setVideoTrackEncodingBandwidth(encoding, bandwidth);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCamera.js","sourceRoot":"","sources":["../../src/hooks/useCamera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAUxC,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAwFtE,MAAM,sBAAsB,GAAG,GAAG,EAAE,CAAC,CAAC;IACpC,OAAO,EAAE,KAAK;IACd,eAAe,EAAE,EAAE;CACpB,CAAC,CAAC;AAEH,SAAS,kBAAkB,CAAC,YAA6C;IACvE,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;QAC9B,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO;gBACL,YAAY,EAAE,SAAS;gBACvB,eAAe,EAAE,YAAY;aAC9B,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,YAAY,EAAE,SAAS;gBACvB,eAAe,EAAE,YAAY;aAC9B,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC;AAED,SAAS,eAAe,CACtB,gBAAqC;IAEr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SAAyB,EAAE,EAAE;QAClC,MAAM,qBAAqB,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC,EACD,EAAE,CACH,CAAC;IAEF,MAAM,wBAAwB,GAAG,WAAW,CAC1C,KAAK,EAAE,QAAuB,EAAE,EAAE;QAChC,MAAM,oBAAoB,GACxB,MAAM,qBAAqB,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC;QACjE,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;IAC3C,CAAC,EACD,EAAE,CACH,CAAC;IAEF,MAAM,8BAA8B,GAAG,WAAW,CAChD,KAAK,EAAE,QAAuB,EAAE,SAAyB,EAAE,EAAE;QAC3D,MAAM,qBAAqB,CAAC,8BAA8B,CACxD,QAAQ,EACR,SAAS,CACV,CAAC;IACJ,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO;QACL;;WAEG;QACH,UAAU;QACV;;WAEG;QACH,aAAa;QACb;;WAEG;QACH,eAAe;QACf;;;WAGG;QACH,OAAO;QAEP,oCAAoC;QACpC,YAAY;QACZ;;;;WAIG;QACH,aAAa;QACb;;;;WAIG,CAAC,YAAY;QAEhB;;;;WAIG;QACH,wBAAwB;QACxB;;;;;WAKG;QACH,8BAA8B;QAC9B;;;;;;;WAOG;QACH,sBAAsB;KACvB,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useMemo, useState } from 'react';\nimport { Platform } from 'react-native';\n\nimport {\n BandwidthLimit,\n Brand,\n SimulcastBandwidthLimit,\n SimulcastConfig,\n TrackBandwidthLimit,\n TrackEncoding,\n} from '../types';\nimport RNFishjamClientModule from '../RNFishjamClientModule';\nimport { ReceivableEvents, useFishjamEvent } from './useFishjamEvent';\n\ntype SimulcastConfigUpdateEvent = SimulcastConfig;\nexport type CameraId = Brand<string, 'CameraId'>;\n\nexport type CameraFacingDirection = 'front' | 'back' | 'unspecified';\n\nexport type Camera = {\n id: CameraId;\n name: string;\n facingDirection: CameraFacingDirection;\n};\n\nexport type VideoQuality =\n | 'QVGA169'\n | 'VGA169'\n | 'QHD169'\n | 'HD169'\n | 'FHD169'\n | 'QVGA43'\n | 'VGA43'\n | 'QHD43'\n | 'HD43'\n | 'FHD43';\n\ntype CameraConfigBase = {\n /**\n * resolution + aspect ratio of local video track, one of: `QVGA_169`, `VGA_169`, `QHD_169`, `HD_169`,\n * `FHD_169`, `QVGA_43`, `VGA_43`, `QHD_43`, `HD_43`, `FHD_43`. Note that quality might be worse than\n * specified due to device capabilities, internet connection etc.\n * @default `VGA_169`\n */\n quality?: VideoQuality;\n /**\n * whether to flip the dimensions of the video, that is whether to film in vertical orientation.\n * This basically switches width with height and is only used to select closes capture format.\n *\n * To record horizontal video your phone orientation must be in landscape and your app must support this orientation.\n *\n * Platform specific capture formats:\n * @see iOS: https://developer.apple.com/documentation/avfoundation/avcapturedevice/format\n * @see Android: https://github.com/webrtc-sdk/webrtc/blob/cdc3bba5aa38910a55428b919ba45aceac1ad9ad/sdk/android/api/org/webrtc/CameraEnumerationAndroid.java#L50\n *\n * WebRTC device orientation handling:\n * @see iOS: https://github.com/webrtc-sdk/webrtc/blob/cdc3bba5aa38910a55428b919ba45aceac1ad9ad/sdk/objc/components/capturer/RTCCameraVideoCapturer.m#L285\n * @see Android: https://github.com/pristineio/webrtc-mirror/blob/7a5bcdffaab90a05bc1146b2b1ea71c004e54d71/webrtc/sdk/android/src/java/org/webrtc/Camera2Session.java#L347\n *\n * @default `true`\n */\n flipDimensions?: boolean;\n /**\n * whether the camera track is initially enabled, you can toggle it on/off later with toggleCamera method\n * @default `true`\n */\n cameraEnabled?: boolean;\n /**\n * id of the camera to start capture with. Get available cameras with `cameras`.\n * You can switch the cameras later with `switchCamera` functions.\n * @default the first front camera\n */\n cameraId?: CameraId;\n};\n\nexport type CameraConfig = CameraConfigBase & {\n /**\n * whether video track uses simulcast. By default simulcast is disabled.\n */\n simulcastEnabled?: boolean;\n /**\n * bandwidth limit of a video track. By default there is no bandwidth limit.\n */\n};\n\nexport type CameraConfigInternal = CameraConfigBase & {\n videoTrackMetadata?: { active: boolean; type: 'camera' };\n /**\n * SimulcastConfig of a video track. By default simulcast is disabled.\n */\n simulcastConfig?: SimulcastConfig;\n /**\n * bandwidth limit of a video track. By default there is no bandwidth limit.\n */\n maxBandwidth?: TrackBandwidthLimit;\n} & (\n | { maxBandwidthInt?: BandwidthLimit }\n | { maxBandwidthMap?: SimulcastBandwidthLimit }\n );\n\nconst defaultSimulcastConfig = () => ({\n enabled: false,\n activeEncodings: [],\n});\n\nfunction maxBandwidthConfig(maxBandwidth: TrackBandwidthLimit | undefined) {\n if (Platform.OS === 'android') {\n if (typeof maxBandwidth === 'object') {\n return {\n maxBandwidth: undefined,\n maxBandwidthMap: maxBandwidth,\n };\n } else {\n return {\n maxBandwidth: undefined,\n maxBandwidthInt: maxBandwidth,\n };\n }\n }\n return { maxBandwidth };\n}\n\nfunction simulcastConfig(\n simulcastEnabled: boolean | undefined,\n): SimulcastConfig | undefined {\n // iOS has a limit of 3 hardware encoders\n // 3 simulcast layers + 1 screen share layer = 4, which is too much\n // so we limit simulcast layers to 2\n if (simulcastEnabled) {\n return Platform.select<SimulcastConfig>({\n ios: { enabled: true, activeEncodings: ['l', 'h'] },\n android: { enabled: true, activeEncodings: ['l', 'm', 'h'] },\n });\n }\n return undefined;\n}\n\nexport function updateCameraConfig(\n config: Readonly<CameraConfig>,\n): CameraConfigInternal {\n return {\n ...config,\n ...maxBandwidthConfig({ l: 150, m: 500, h: 1500 }),\n videoTrackMetadata: { active: true, type: 'camera' },\n simulcastConfig: simulcastConfig(config.simulcastEnabled),\n };\n}\n\n/**\n * This hook can toggle camera on/off and provides current camera state.\n * @category Devices\n * @group Hooks\n */\nexport function useCamera() {\n const [isCameraOn, setIsCameraOn] = useState<boolean>(\n RNFishjamClientModule.isCameraOn,\n );\n\n const [currentCamera, setCurrentCamera] = useState<Camera | undefined>(\n undefined,\n );\n\n const [simulcastConfig, setSimulcastConfig] = useState<SimulcastConfig>(\n defaultSimulcastConfig(),\n );\n\n useFishjamEvent<SimulcastConfigUpdateEvent>(\n ReceivableEvents.SimulcastConfigUpdate,\n setSimulcastConfig,\n );\n\n useFishjamEvent(ReceivableEvents.IsCameraOn, setIsCameraOn);\n\n const cameras = useMemo(() => {\n return RNFishjamClientModule.cameras;\n }, []);\n\n const prepareCamera = useCallback(\n async (config: Readonly<CameraConfig> = {}) => {\n const camera = RNFishjamClientModule.cameras.find((camera) =>\n config.cameraId\n ? camera.id === config.cameraId\n : camera.facingDirection === 'front',\n );\n\n setCurrentCamera(camera);\n const updatedConfig = updateCameraConfig({\n ...config,\n cameraId: camera?.id,\n });\n await RNFishjamClientModule.startCamera(updatedConfig);\n },\n [],\n );\n\n const toggleCamera = useCallback(async () => {\n const state = await RNFishjamClientModule.toggleCamera();\n await RNFishjamClientModule.updateVideoTrackMetadata({\n active: state,\n type: 'camera',\n });\n setIsCameraOn(state);\n }, []);\n\n const switchCamera = useCallback(\n async (cameraId: CameraId) => {\n await RNFishjamClientModule.switchCamera(cameraId);\n setCurrentCamera(cameras.find((camera) => camera.id === cameraId));\n },\n [cameras],\n );\n\n const setVideoTrackBandwidth = useCallback(\n async (bandwidth: BandwidthLimit) => {\n await RNFishjamClientModule.setVideoTrackBandwidth(bandwidth);\n },\n [],\n );\n\n const toggleVideoTrackEncoding = useCallback(\n async (encoding: TrackEncoding) => {\n const videoSimulcastConfig =\n await RNFishjamClientModule.toggleVideoTrackEncoding(encoding);\n setSimulcastConfig(videoSimulcastConfig);\n },\n [],\n );\n\n const setVideoTrackEncodingBandwidth = useCallback(\n async (encoding: TrackEncoding, bandwidth: BandwidthLimit) => {\n await RNFishjamClientModule.setVideoTrackEncodingBandwidth(\n encoding,\n bandwidth,\n );\n },\n [],\n );\n\n return {\n /**\n * Informs if user camera is streaming video\n */\n isCameraOn,\n /**\n * Which camera is now used for streaming (or will be used as default when camera will be enabled)\n */\n currentCamera,\n /**\n * Simulcast configuration\n */\n simulcastConfig,\n /**\n * Property that lists cameras available on device.\n * @returns A promise that resolves to the list of available cameras.\n */\n cameras,\n\n /** Enable/disable current camera */\n toggleCamera,\n /**\n * Prepares camera and starts local video track\n * @param config configuration of the camera capture\n * @returns A promise that resolves when camera is started.\n */\n prepareCamera,\n /**\n * Switches to the specified camera.\n * List of available devices can be retrieved from `cameras` variable\n * @returns A promise that resolves when camera is switched.\n */ switchCamera,\n\n /**\n * @deprecated\n * toggles encoding of a video track on/off\n * @param encoding encoding to toggle\n */\n toggleVideoTrackEncoding,\n /**\n * updates maximum bandwidth for the given simulcast encoding of the video track\n * @param encoding encoding to update\n * @param bandwidth BandwidthLimit to set\n * @deprecated\n */\n setVideoTrackEncodingBandwidth,\n /**\n * updates maximum bandwidth for the video track. This value directly translates\n * to quality of the stream and the amount of RTP packets being sent. In case simulcast\n * is enabled bandwidth is split between all of the variant streams proportionally to\n * their resolution.\n * @param BandwidthLimit to set\n * @deprecated\n */\n setVideoTrackBandwidth,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useCamera.js","sourceRoot":"","sources":["../../src/hooks/useCamera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAUxC,OAAO,qBAAqB,EAAE,EAC5B,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AA4FvE,MAAM,sBAAsB,GAAG,GAAG,EAAE,CAAC,CAAC;IACpC,OAAO,EAAE,KAAK;IACd,eAAe,EAAE,EAAE;CACpB,CAAC,CAAC;AAEH,SAAS,kBAAkB,CAAC,YAA6C;IACvE,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;QAC9B,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO;gBACL,YAAY,EAAE,SAAS;gBACvB,eAAe,EAAE,Y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AAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC,EACD,EAAE,CACH,CAAC;IAEF,MAAM,wBAAwB,GAAG,WAAW,CAC1C,KAAK,EAAE,QAAuB,EAAE,EAAE;QAChC,MAAM,qBAAqB,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC,EACD,EAAE,CACH,CAAC;IAEF,MAAM,8BAA8B,GAAG,WAAW,CAChD,KAAK,EAAE,QAAuB,EAAE,SAAyB,EAAE,EAAE;QAC3D,MAAM,qBAAqB,CAAC,8BAA8B,CACxD,QAAQ,EACR,SAAS,CACV,CAAC;IACJ,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO;QACL;;WAEG;QACH,UAAU;QACV;;WAEG;QACH,aAAa;QACb;;WAEG;QACH,eAAe;QACf;;;WAGG;QACH,OAAO;QAEP,oCAAoC;QACpC,YAAY;QACZ;;;;WAIG;QACH,aAAa;QACb;;;;WAIG,CAAC,YAAY;QAEhB;;;;WAIG;QACH,wBAAwB;QACxB;;;;;WAKG;QACH,8BAA8B;QAC9B;;;;;;;WAOG;QACH,sBAAsB;KACvB,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useMemo } from 'react';\nimport { Platform } from 'react-native';\n\nimport {\n BandwidthLimit,\n Brand,\n SimulcastBandwidthLimit,\n SimulcastConfig,\n TrackBandwidthLimit,\n TrackEncoding,\n} from '../types';\nimport RNFishjamClientModule, {\n ReceivableEvents,\n} from '../RNFishjamClientModule';\nimport { useFishjamEventState } from './internal/useFishjamEventState';\n\nexport type CameraId = Brand<string, 'CameraId'>;\n\nexport type CameraFacingDirection = 'front' | 'back' | 'unspecified';\n\nexport type Camera = {\n id: CameraId;\n name: string;\n facingDirection: CameraFacingDirection;\n};\n\nexport type CurrentCameraChangedType = {\n currentCamera: Camera | null;\n isCameraOn: boolean;\n};\n\nexport type VideoQuality =\n | 'QVGA169'\n | 'VGA169'\n | 'QHD169'\n | 'HD169'\n | 'FHD169'\n | 'QVGA43'\n | 'VGA43'\n | 'QHD43'\n | 'HD43'\n | 'FHD43';\n\ntype CameraConfigBase = {\n /**\n * resolution + aspect ratio of local video track, one of: `QVGA_169`, `VGA_169`, `QHD_169`, `HD_169`,\n * `FHD_169`, `QVGA_43`, `VGA_43`, `QHD_43`, `HD_43`, `FHD_43`. Note that quality might be worse than\n * specified due to device capabilities, internet connection etc.\n * @default `VGA_169`\n */\n quality?: VideoQuality;\n /**\n * whether to flip the dimensions of the video, that is whether to film in vertical orientation.\n * This basically switches width with height and is only used to select closes capture format.\n *\n * To record horizontal video your phone orientation must be in landscape and your app must support this orientation.\n *\n * Platform specific capture formats:\n * @see iOS: https://developer.apple.com/documentation/avfoundation/avcapturedevice/format\n * @see Android: https://github.com/webrtc-sdk/webrtc/blob/cdc3bba5aa38910a55428b919ba45aceac1ad9ad/sdk/android/api/org/webrtc/CameraEnumerationAndroid.java#L50\n *\n * WebRTC device orientation handling:\n * @see iOS: https://github.com/webrtc-sdk/webrtc/blob/cdc3bba5aa38910a55428b919ba45aceac1ad9ad/sdk/objc/components/capturer/RTCCameraVideoCapturer.m#L285\n * @see Android: https://github.com/pristineio/webrtc-mirror/blob/7a5bcdffaab90a05bc1146b2b1ea71c004e54d71/webrtc/sdk/android/src/java/org/webrtc/Camera2Session.java#L347\n *\n * @default `true`\n */\n flipDimensions?: boolean;\n /**\n * whether the camera track is initially enabled, you can toggle it on/off later with toggleCamera method\n * @default `true`\n */\n cameraEnabled?: boolean;\n /**\n * id of the camera to start capture with. Get available cameras with `cameras`.\n * You can switch the cameras later with `switchCamera` functions.\n * @default the first front camera\n */\n cameraId?: CameraId;\n};\n\nexport type CameraConfig = CameraConfigBase & {\n /**\n * whether video track uses simulcast. By default simulcast is disabled.\n */\n simulcastEnabled?: boolean;\n /**\n * bandwidth limit of a video track. By default there is no bandwidth limit.\n */\n};\n\nexport type CameraConfigInternal = CameraConfigBase & {\n videoTrackMetadata?: { active: boolean; type: 'camera' };\n /**\n * SimulcastConfig of a video track. By default simulcast is disabled.\n */\n simulcastConfig?: SimulcastConfig;\n /**\n * bandwidth limit of a video track. By default there is no bandwidth limit.\n */\n maxBandwidth?: TrackBandwidthLimit;\n} & (\n | { maxBandwidthInt?: BandwidthLimit }\n | { maxBandwidthMap?: SimulcastBandwidthLimit }\n );\n\nconst defaultSimulcastConfig = () => ({\n enabled: false,\n activeEncodings: [],\n});\n\nfunction maxBandwidthConfig(maxBandwidth: TrackBandwidthLimit | undefined) {\n if (Platform.OS === 'android') {\n if (typeof maxBandwidth === 'object') {\n return {\n maxBandwidth: undefined,\n maxBandwidthMap: maxBandwidth,\n };\n } else {\n return {\n maxBandwidth: undefined,\n maxBandwidthInt: maxBandwidth,\n };\n }\n }\n return { maxBandwidth };\n}\n\nfunction getSimulcastConfig(\n simulcastEnabled: boolean | undefined,\n): SimulcastConfig | undefined {\n // iOS has a limit of 3 hardware encoders\n // 3 simulcast layers + 1 screen share layer = 4, which is too much\n // so we limit simulcast layers to 2\n if (simulcastEnabled) {\n return Platform.select<SimulcastConfig>({\n ios: { enabled: true, activeEncodings: ['l', 'h'] },\n android: { enabled: true, activeEncodings: ['l', 'm', 'h'] },\n });\n }\n return undefined;\n}\n\nexport function updateCameraConfig(\n config: Readonly<CameraConfig>,\n): CameraConfigInternal {\n return {\n ...config,\n ...maxBandwidthConfig({ l: 150, m: 500, h: 1500 }),\n videoTrackMetadata: { active: true, type: 'camera' },\n simulcastConfig: getSimulcastConfig(config.simulcastEnabled),\n };\n}\n\n/**\n * This hook can toggle camera on/off and provides current camera state.\n * @category Devices\n * @group Hooks\n */\nexport function useCamera() {\n const simulcastConfig = useFishjamEventState<SimulcastConfig>(\n ReceivableEvents.SimulcastConfigUpdate,\n defaultSimulcastConfig(), // TODO: Fetch from native\n );\n\n const { currentCamera: currentCameraState, isCameraOn } =\n useFishjamEventState<CurrentCameraChangedType>(\n ReceivableEvents.CurrentCameraChanged,\n {\n currentCamera: RNFishjamClientModule.currentCamera,\n isCameraOn: RNFishjamClientModule.isCameraOn,\n },\n );\n\n // For Android Expo converts null to undefined ¯\\_(ツ)_/¯\n const currentCamera = currentCameraState ?? null;\n\n const cameras = useMemo(() => RNFishjamClientModule.cameras, []);\n\n const prepareCamera = useCallback(\n async (config: Readonly<CameraConfig> = {}) => {\n const camera = RNFishjamClientModule.cameras.find((cam) =>\n config.cameraId\n ? cam.id === config.cameraId\n : cam.facingDirection === 'front',\n );\n\n const updatedConfig = updateCameraConfig({\n ...config,\n cameraId: camera?.id,\n });\n return RNFishjamClientModule.startCamera(updatedConfig);\n },\n [],\n );\n\n const toggleCamera = useCallback(async () => {\n const state = await RNFishjamClientModule.toggleCamera();\n await RNFishjamClientModule.updateVideoTrackMetadata({\n active: state,\n type: 'camera',\n });\n }, []);\n\n const switchCamera = useCallback(async (cameraId: CameraId) => {\n await RNFishjamClientModule.switchCamera(cameraId);\n }, []);\n\n const setVideoTrackBandwidth = useCallback(\n async (bandwidth: BandwidthLimit) => {\n await RNFishjamClientModule.setVideoTrackBandwidth(bandwidth);\n },\n [],\n );\n\n const toggleVideoTrackEncoding = useCallback(\n async (encoding: TrackEncoding) => {\n await RNFishjamClientModule.toggleVideoTrackEncoding(encoding);\n },\n [],\n );\n\n const setVideoTrackEncodingBandwidth = useCallback(\n async (encoding: TrackEncoding, bandwidth: BandwidthLimit) => {\n await RNFishjamClientModule.setVideoTrackEncodingBandwidth(\n encoding,\n bandwidth,\n );\n },\n [],\n );\n\n return {\n /**\n * Informs if user camera is streaming video\n */\n isCameraOn,\n /**\n * Which camera is now used for streaming (or will be used as default when camera will be enabled)\n */\n currentCamera,\n /**\n * Simulcast configuration\n */\n simulcastConfig,\n /**\n * Property that lists cameras available on device.\n * @returns A promise that resolves to the list of available cameras.\n */\n cameras,\n\n /** Enable/disable current camera */\n toggleCamera,\n /**\n * Prepares camera and starts local video track\n * @param config configuration of the camera capture\n * @returns A promise that resolves when camera is started.\n */\n prepareCamera,\n /**\n * Switches to the specified camera.\n * List of available devices can be retrieved from `cameras` variable\n * @returns A promise that resolves when camera is switched.\n */ switchCamera,\n\n /**\n * @deprecated\n * toggles encoding of a video track on/off\n * @param encoding encoding to toggle\n */\n toggleVideoTrackEncoding,\n /**\n * updates maximum bandwidth for the given simulcast encoding of the video track\n * @param encoding encoding to update\n * @param bandwidth BandwidthLimit to set\n * @deprecated\n */\n setVideoTrackEncodingBandwidth,\n /**\n * updates maximum bandwidth for the video track. This value directly translates\n * to quality of the stream and the amount of RTP packets being sent. In case simulcast\n * is enabled bandwidth is split between all of the variant streams proportionally to\n * their resolution.\n * @param BandwidthLimit to set\n * @deprecated\n */\n setVideoTrackBandwidth,\n };\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ConnectionConfig, leaveRoom } from '../common/client';
|
|
2
|
+
import { GenericMetadata } from '../types';
|
|
3
|
+
type ReconnectionStatus = 'idle' | 'reconnecting' | 'error';
|
|
4
|
+
type PeerStatus = 'connecting' | 'connected' | 'error' | 'idle';
|
|
5
|
+
export type ConnectionStatus = ReconnectionStatus | PeerStatus;
|
|
6
|
+
export interface JoinRoomConfig<PeerMetadata extends GenericMetadata = GenericMetadata> {
|
|
7
|
+
/**
|
|
8
|
+
* fishjam URL
|
|
9
|
+
*/
|
|
10
|
+
url: string;
|
|
11
|
+
/**
|
|
12
|
+
* token received from server (or Room Manager)
|
|
13
|
+
*/
|
|
14
|
+
peerToken: string;
|
|
15
|
+
/**
|
|
16
|
+
* string indexed record with metadata, that will be available to all other peers
|
|
17
|
+
*/
|
|
18
|
+
peerMetadata?: PeerMetadata;
|
|
19
|
+
/**
|
|
20
|
+
* additional connection configuration
|
|
21
|
+
*/
|
|
22
|
+
config?: ConnectionConfig;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Connect/leave room. And get connection status.
|
|
26
|
+
* @group Hooks
|
|
27
|
+
* @category Connection
|
|
28
|
+
*/
|
|
29
|
+
export declare function useConnection(): {
|
|
30
|
+
/**
|
|
31
|
+
* join room and start streaming camera and microphone
|
|
32
|
+
*/
|
|
33
|
+
joinRoom: <PeerMetadata extends GenericMetadata = GenericMetadata>({ url, peerToken, peerMetadata, config, }: JoinRoomConfig<PeerMetadata>) => Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Leave room and stop streaming
|
|
36
|
+
*/
|
|
37
|
+
leaveRoom: typeof leaveRoom;
|
|
38
|
+
peerStatus: PeerStatus;
|
|
39
|
+
reconnectionStatus: ReconnectionStatus;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=useConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnection.d.ts","sourceRoot":"","sources":["../../src/hooks/useConnection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAY,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAMzE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,KAAK,kBAAkB,GAAG,MAAM,GAAG,cAAc,GAAG,OAAO,CAAC;AAC5D,KAAK,UAAU,GAAG,YAAY,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,GAAG,UAAU,CAAC;AAe/D,MAAM,WAAW,cAAc,CAC7B,YAAY,SAAS,eAAe,GAAG,eAAe;IAEtD;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,aAAa;IAgBzB;;OAEG;eAdI,YAAY,SAAS,eAAe,+DAKxC,cAAc,CAAC,YAAY,CAAC;IAW/B;;OAEG;;;;EAKN"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { joinRoom, leaveRoom } from '../common/client';
|
|
3
|
+
import RNFishjamClientModule, { ReceivableEvents, } from '../RNFishjamClientModule';
|
|
4
|
+
import { useFishjamEventState } from './internal/useFishjamEventState';
|
|
5
|
+
function useConnectionStatus() {
|
|
6
|
+
const peerStatus = useFishjamEventState(ReceivableEvents.PeerStatusChanged, RNFishjamClientModule.peerStatus);
|
|
7
|
+
const reconnectionStatus = useFishjamEventState(ReceivableEvents.ReconnectionStatusChanged, RNFishjamClientModule.reconnectionStatus);
|
|
8
|
+
return { peerStatus, reconnectionStatus };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Connect/leave room. And get connection status.
|
|
12
|
+
* @group Hooks
|
|
13
|
+
* @category Connection
|
|
14
|
+
*/
|
|
15
|
+
export function useConnection() {
|
|
16
|
+
const { peerStatus, reconnectionStatus } = useConnectionStatus();
|
|
17
|
+
const join = useCallback(async ({ url, peerToken, peerMetadata, config, }) => {
|
|
18
|
+
await joinRoom(url, peerToken, peerMetadata, config);
|
|
19
|
+
}, []);
|
|
20
|
+
return {
|
|
21
|
+
/**
|
|
22
|
+
* join room and start streaming camera and microphone
|
|
23
|
+
*/
|
|
24
|
+
joinRoom: join,
|
|
25
|
+
/**
|
|
26
|
+
* Leave room and stop streaming
|
|
27
|
+
*/
|
|
28
|
+
leaveRoom,
|
|
29
|
+
peerStatus,
|
|
30
|
+
reconnectionStatus,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=useConnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnection.js","sourceRoot":"","sources":["../../src/hooks/useConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAoB,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEzE,OAAO,qBAAqB,EAAE,EAC5B,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAQvE,SAAS,mBAAmB;IAC1B,MAAM,UAAU,GAAG,oBAAoB,CACrC,gBAAgB,CAAC,iBAAiB,EAClC,qBAAqB,CAAC,UAAU,CACjC,CAAC;IAEF,MAAM,kBAAkB,GAAG,oBAAoB,CAC7C,gBAAgB,CAAC,yBAAyB,EAC1C,qBAAqB,CAAC,kBAAkB,CACzC,CAAC;IAEF,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAC;AAC5C,CAAC;AAsBD;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,GAAG,mBAAmB,EAAE,CAAC;IAEjE,MAAM,IAAI,GAAG,WAAW,CACtB,KAAK,EAA0D,EAC7D,GAAG,EACH,SAAS,EACT,YAAY,EACZ,MAAM,GACuB,EAAE,EAAE;QACjC,MAAM,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IACvD,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO;QACL;;WAEG;QACH,QAAQ,EAAE,IAAI;QACd;;WAEG;QACH,SAAS;QACT,UAAU;QACV,kBAAkB;KACnB,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback } from 'react';\nimport { ConnectionConfig, joinRoom, leaveRoom } from '../common/client';\n\nimport RNFishjamClientModule, {\n ReceivableEvents,\n} from '../RNFishjamClientModule';\nimport { useFishjamEventState } from './internal/useFishjamEventState';\nimport { GenericMetadata } from '../types';\n\ntype ReconnectionStatus = 'idle' | 'reconnecting' | 'error';\ntype PeerStatus = 'connecting' | 'connected' | 'error' | 'idle';\n\nexport type ConnectionStatus = ReconnectionStatus | PeerStatus;\n\nfunction useConnectionStatus() {\n const peerStatus = useFishjamEventState<PeerStatus>(\n ReceivableEvents.PeerStatusChanged,\n RNFishjamClientModule.peerStatus,\n );\n\n const reconnectionStatus = useFishjamEventState<ReconnectionStatus>(\n ReceivableEvents.ReconnectionStatusChanged,\n RNFishjamClientModule.reconnectionStatus,\n );\n\n return { peerStatus, reconnectionStatus };\n}\nexport interface JoinRoomConfig<\n PeerMetadata extends GenericMetadata = GenericMetadata,\n> {\n /**\n * fishjam URL\n */\n url: string;\n /**\n * token received from server (or Room Manager)\n */\n peerToken: string;\n /**\n * string indexed record with metadata, that will be available to all other peers\n */\n peerMetadata?: PeerMetadata;\n /**\n * additional connection configuration\n */\n config?: ConnectionConfig;\n}\n\n/**\n * Connect/leave room. And get connection status.\n * @group Hooks\n * @category Connection\n */\nexport function useConnection() {\n const { peerStatus, reconnectionStatus } = useConnectionStatus();\n\n const join = useCallback(\n async <PeerMetadata extends GenericMetadata = GenericMetadata>({\n url,\n peerToken,\n peerMetadata,\n config,\n }: JoinRoomConfig<PeerMetadata>) => {\n await joinRoom(url, peerToken, peerMetadata, config);\n },\n [],\n );\n\n return {\n /**\n * join room and start streaming camera and microphone\n */\n joinRoom: join,\n /**\n * Leave room and stop streaming\n */\n leaveRoom,\n peerStatus,\n reconnectionStatus,\n };\n}\n"]}
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
export type ForegroundServicePermissionsConfigInternal = {
|
|
2
|
-
enableCamera?: boolean;
|
|
3
|
-
enableMicrophone?: boolean;
|
|
4
|
-
enableScreenSharing?: boolean;
|
|
5
|
-
};
|
|
6
1
|
/**
|
|
7
|
-
* A type representing the
|
|
2
|
+
* A type representing the configuration for foreground service permissions.
|
|
8
3
|
*
|
|
4
|
+
* @param enableCamera Indicates whether the camera is enabled for the foreground service.
|
|
5
|
+
* @param enableMicrophone Indicates whether the microphone is enabled for the foreground service.
|
|
9
6
|
* @param channelId The id of the channel. Must be unique per package.
|
|
10
7
|
* @param channelName The user visible name of the channel.
|
|
11
8
|
* @param notificationTitle The title (first row) of the notification, in a standard notification.
|
|
12
9
|
* @param notificationContent The text (second row) of the notification, in a standard notification.
|
|
13
|
-
*/
|
|
14
|
-
export type ForegroundServiceNotificationConfig = {
|
|
15
|
-
channelId: string;
|
|
16
|
-
channelName: string;
|
|
17
|
-
notificationTitle: string;
|
|
18
|
-
notificationContent: string;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* A type representing the configuration for foreground service permissions.
|
|
22
|
-
*
|
|
23
|
-
* @param enableCamera Indicates whether the camera is enabled for the foreground service.
|
|
24
|
-
* @param enableMicrophone Indicates whether the microphone is enabled for the foreground service.
|
|
25
10
|
*
|
|
26
11
|
*/
|
|
27
|
-
export type
|
|
12
|
+
export type ForegroundServiceConfig = {
|
|
13
|
+
enableCamera?: boolean;
|
|
14
|
+
enableMicrophone?: boolean;
|
|
15
|
+
channelId?: string;
|
|
16
|
+
channelName?: string;
|
|
17
|
+
notificationTitle?: string;
|
|
18
|
+
notificationContent?: string;
|
|
19
|
+
};
|
|
28
20
|
/**
|
|
29
21
|
* useForegroundService
|
|
30
22
|
*
|
|
@@ -40,5 +32,5 @@ export type ForegroundServicePermissionsConfig = Pick<ForegroundServicePermissio
|
|
|
40
32
|
* @param {Object} config.notificationContent - The text (second row) of the notification, in a standard notification.
|
|
41
33
|
*
|
|
42
34
|
*/
|
|
43
|
-
export declare const useForegroundService: ({ enableCamera, enableMicrophone,
|
|
35
|
+
export declare const useForegroundService: ({ enableCamera, enableMicrophone, channelId, channelName, notificationContent, notificationTitle, }: ForegroundServiceConfig) => void;
|
|
44
36
|
//# sourceMappingURL=useForegroundService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForegroundService.d.ts","sourceRoot":"","sources":["../../src/hooks/useForegroundService.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"useForegroundService.d.ts","sourceRoot":"","sources":["../../src/hooks/useForegroundService.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AA6DF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,wGApD9B,uBAAuB,SAuDxB,CAAC"}
|
|
@@ -12,7 +12,7 @@ const requestNotificationsPermission = async () => {
|
|
|
12
12
|
console.warn(err);
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
const useForegroundServiceAndroid = ({ enableCamera, enableMicrophone,
|
|
15
|
+
const useForegroundServiceAndroid = ({ enableCamera, enableMicrophone, channelId, channelName, notificationContent, notificationTitle, }) => {
|
|
16
16
|
const [isConfigured, setIsConfigured] = useState(false);
|
|
17
17
|
useEffect(() => {
|
|
18
18
|
if (!isConfigured) {
|
|
@@ -21,17 +21,27 @@ const useForegroundServiceAndroid = ({ enableCamera, enableMicrophone, ...restOp
|
|
|
21
21
|
RNFishjamClientModule.startForegroundService({
|
|
22
22
|
enableCamera,
|
|
23
23
|
enableMicrophone,
|
|
24
|
+
channelId,
|
|
25
|
+
channelName,
|
|
26
|
+
notificationContent,
|
|
27
|
+
notificationTitle,
|
|
24
28
|
});
|
|
25
|
-
}, [
|
|
29
|
+
}, [
|
|
30
|
+
channelId,
|
|
31
|
+
channelName,
|
|
32
|
+
enableCamera,
|
|
33
|
+
enableMicrophone,
|
|
34
|
+
isConfigured,
|
|
35
|
+
notificationContent,
|
|
36
|
+
notificationTitle,
|
|
37
|
+
]);
|
|
26
38
|
useEffect(() => {
|
|
27
39
|
const runConfiguration = async () => {
|
|
28
40
|
await requestNotificationsPermission();
|
|
29
|
-
RNFishjamClientModule.configureForegroundService(restOptions);
|
|
30
41
|
setIsConfigured(true);
|
|
31
42
|
};
|
|
32
43
|
runConfiguration();
|
|
33
44
|
return () => RNFishjamClientModule.stopForegroundService();
|
|
34
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
45
|
}, []);
|
|
36
46
|
};
|
|
37
47
|
const emptyFunction = () => { };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForegroundService.js","sourceRoot":"","sources":["../../src/hooks/useForegroundService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"useForegroundService.js","sourceRoot":"","sources":["../../src/hooks/useForegroundService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAsB5D,MAAM,8BAA8B,GAAG,KAAK,IAAI,EAAE;IAChD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAC7C,kBAAkB,CAAC,WAAW,CAAC,kBAAkB,CAClD,CAAC;QACF,IAAI,MAAM,KAAK,kBAAkB,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAClD,OAAO,CAAC,IAAI,CACV,6FAA6F,CAC9F,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,2BAA2B,GAAG,CAAC,EACnC,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,iBAAiB,GACO,EAAE,EAAE;IAC5B,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QACD,qBAAqB,CAAC,sBAAsB,CAAC;YAC3C,YAAY;YACZ,gBAAgB;YAChB,SAAS;YACT,WAAW;YACX,mBAAmB;YACnB,iBAAiB;SAClB,CAAC,CAAC;IACL,CAAC,EAAE;QACD,SAAS;QACT,WAAW;QACX,YAAY;QACZ,gBAAgB;QAChB,YAAY;QACZ,mBAAmB;QACnB,iBAAiB;KAClB,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;YAClC,MAAM,8BAA8B,EAAE,CAAC;YACvC,eAAe,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC;QACF,gBAAgB,EAAE,CAAC;QACnB,OAAO,GAAG,EAAE,CAAC,qBAAqB,CAAC,qBAAqB,EAAE,CAAC;IAC7D,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAE/B;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC,MAAM,CAAC;IAClD,OAAO,EAAE,2BAA2B;IACpC,OAAO,EAAE,aAAa;CACvB,CAAC,CAAC","sourcesContent":["import { useEffect, useState } from 'react';\nimport RNFishjamClientModule from '../RNFishjamClientModule';\n\nimport { PermissionsAndroid, Platform } from 'react-native';\n\n/**\n * A type representing the configuration for foreground service permissions.\n *\n * @param enableCamera Indicates whether the camera is enabled for the foreground service.\n * @param enableMicrophone Indicates whether the microphone is enabled for the foreground service.\n * @param channelId The id of the channel. Must be unique per package.\n * @param channelName The user visible name of the channel.\n * @param notificationTitle The title (first row) of the notification, in a standard notification.\n * @param notificationContent The text (second row) of the notification, in a standard notification.\n *\n */\nexport type ForegroundServiceConfig = {\n enableCamera?: boolean;\n enableMicrophone?: boolean;\n channelId?: string;\n channelName?: string;\n notificationTitle?: string;\n notificationContent?: string;\n};\n\nconst requestNotificationsPermission = async () => {\n try {\n const result = await PermissionsAndroid.request(\n PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,\n );\n if (result !== PermissionsAndroid.RESULTS.GRANTED) {\n console.warn(\n \"Notifications permission not granted. User won't be able to see a the app is in background.\",\n );\n }\n } catch (err) {\n console.warn(err);\n }\n};\n\nconst useForegroundServiceAndroid = ({\n enableCamera,\n enableMicrophone,\n channelId,\n channelName,\n notificationContent,\n notificationTitle,\n}: ForegroundServiceConfig) => {\n const [isConfigured, setIsConfigured] = useState(false);\n\n useEffect(() => {\n if (!isConfigured) {\n return;\n }\n RNFishjamClientModule.startForegroundService({\n enableCamera,\n enableMicrophone,\n channelId,\n channelName,\n notificationContent,\n notificationTitle,\n });\n }, [\n channelId,\n channelName,\n enableCamera,\n enableMicrophone,\n isConfigured,\n notificationContent,\n notificationTitle,\n ]);\n\n useEffect(() => {\n const runConfiguration = async () => {\n await requestNotificationsPermission();\n setIsConfigured(true);\n };\n runConfiguration();\n return () => RNFishjamClientModule.stopForegroundService();\n }, []);\n};\n\nconst emptyFunction = () => {};\n\n/**\n * useForegroundService\n *\n * A hook for managing a foreground service on Android. Does nothing on other platforms.\n * You can use this hook to keep your app running in the background. You're also required to run a foreground service when screen sharing.\n *\n * @param {Object} config - Configuration options for the foreground service.\n * @param {boolean} config.enableCamera - Flag to enable or disable camera usage in the foreground service. Only enable after the user has granted the necessary permissions.\n * @param {boolean} config.enableMicrophone - Flag to enable or disable microphone usage in the foreground service. Only enable after the user has granted the necessary permissions.\n * @param {Object} config.channelId - The id of the channel. Must be unique per package.\n * @param {Object} config.channelName - The user visible name of the channel.\n * @param {Object} config.notificationTitle - The title (first row) of the notification, in a standard notification.\n * @param {Object} config.notificationContent - The text (second row) of the notification, in a standard notification.\n *\n */\nexport const useForegroundService = Platform.select({\n android: useForegroundServiceAndroid,\n default: emptyFunction,\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMicrophone.d.ts","sourceRoot":"","sources":["../../src/hooks/useMicrophone.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useMicrophone.d.ts","sourceRoot":"","sources":["../../src/hooks/useMicrophone.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,wBAAgB,aAAa;IAWzB,+CAA+C;;IAE/C,2CAA2C;;EAG9C"}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import { useCallback
|
|
2
|
-
import RNFishjamClientModule from '../RNFishjamClientModule';
|
|
3
|
-
import {
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import RNFishjamClientModule, { ReceivableEvents, } from '../RNFishjamClientModule';
|
|
3
|
+
import { useFishjamEventState } from './internal/useFishjamEventState';
|
|
4
4
|
/**
|
|
5
5
|
* This hook can toggle microphone on/off and provides current microphone state.
|
|
6
6
|
* @category Devices
|
|
7
7
|
* @group Hooks
|
|
8
8
|
*/
|
|
9
9
|
export function useMicrophone() {
|
|
10
|
-
const
|
|
11
|
-
useFishjamEvent(ReceivableEvents.IsMicrophoneOn, setIsMicrophoneOn);
|
|
10
|
+
const isMicrophoneOn = useFishjamEventState(ReceivableEvents.IsMicrophoneOn, RNFishjamClientModule.isMicrophoneOn);
|
|
12
11
|
const toggleMicrophone = useCallback(async () => {
|
|
13
|
-
|
|
14
|
-
await RNFishjamClientModule.updateAudioTrackMetadata({
|
|
15
|
-
active: status,
|
|
16
|
-
type: 'audio',
|
|
17
|
-
});
|
|
18
|
-
setIsMicrophoneOn(status);
|
|
12
|
+
await RNFishjamClientModule.toggleMicrophone();
|
|
19
13
|
}, []);
|
|
20
14
|
return {
|
|
21
15
|
/** Informs if microphone is streaming audio */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMicrophone.js","sourceRoot":"","sources":["../../src/hooks/useMicrophone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"useMicrophone.js","sourceRoot":"","sources":["../../src/hooks/useMicrophone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,qBAAqB,EAAE,EAC5B,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,cAAc,GAAG,oBAAoB,CACzC,gBAAgB,CAAC,cAAc,EAC/B,qBAAqB,CAAC,cAAc,CACrC,CAAC;IAEF,MAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QAC9C,MAAM,qBAAqB,CAAC,gBAAgB,EAAE,CAAC;IACjD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,+CAA+C;QAC/C,cAAc;QACd,2CAA2C;QAC3C,gBAAgB;KACjB,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback } from 'react';\n\nimport RNFishjamClientModule, {\n ReceivableEvents,\n} from '../RNFishjamClientModule';\nimport { useFishjamEventState } from './internal/useFishjamEventState';\n\n/**\n * This hook can toggle microphone on/off and provides current microphone state.\n * @category Devices\n * @group Hooks\n */\nexport function useMicrophone() {\n const isMicrophoneOn = useFishjamEventState<boolean>(\n ReceivableEvents.IsMicrophoneOn,\n RNFishjamClientModule.isMicrophoneOn,\n );\n\n const toggleMicrophone = useCallback(async () => {\n await RNFishjamClientModule.toggleMicrophone();\n }, []);\n\n return {\n /** Informs if microphone is streaming audio */\n isMicrophoneOn,\n /** Function to toggle microphone on/off */\n toggleMicrophone,\n };\n}\n"]}
|
|
@@ -10,10 +10,9 @@ export type PeerStatus = 'connecting' | 'connected' | 'error' | 'idle';
|
|
|
10
10
|
/**
|
|
11
11
|
* This hook provides live updates of current connection state of the local peer to a room (websocket state)
|
|
12
12
|
* @returns Current peer status.
|
|
13
|
-
* @
|
|
14
|
-
* @group Hooks
|
|
13
|
+
* @deprecated
|
|
15
14
|
*/
|
|
16
15
|
export declare const usePeerStatus: () => {
|
|
17
|
-
peerStatus:
|
|
16
|
+
peerStatus: PeerStatus;
|
|
18
17
|
};
|
|
19
18
|
//# sourceMappingURL=usePeerStatus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePeerStatus.d.ts","sourceRoot":"","sources":["../../src/hooks/usePeerStatus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePeerStatus.d.ts","sourceRoot":"","sources":["../../src/hooks/usePeerStatus.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAEvE;;;;GAIG;AACH,eAAO,MAAM,aAAa;;CAOzB,CAAC"}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import RNFishjamClientModule from '../RNFishjamClientModule';
|
|
1
|
+
import RNFishjamClientModule, { ReceivableEvents, } from '../RNFishjamClientModule';
|
|
2
|
+
import { useFishjamEventState } from './internal/useFishjamEventState';
|
|
4
3
|
/**
|
|
5
4
|
* This hook provides live updates of current connection state of the local peer to a room (websocket state)
|
|
6
5
|
* @returns Current peer status.
|
|
7
|
-
* @
|
|
8
|
-
* @group Hooks
|
|
6
|
+
* @deprecated
|
|
9
7
|
*/
|
|
10
8
|
export const usePeerStatus = () => {
|
|
11
|
-
const
|
|
12
|
-
const onPeerStatusChanged = useCallback((status) => {
|
|
13
|
-
status && setPeerStatus(status);
|
|
14
|
-
}, []);
|
|
15
|
-
useFishjamEvent(ReceivableEvents.PeerStatusChanged, onPeerStatusChanged);
|
|
9
|
+
const peerStatus = useFishjamEventState(ReceivableEvents.PeerStatusChanged, RNFishjamClientModule.peerStatus);
|
|
16
10
|
return { peerStatus };
|
|
17
11
|
};
|
|
18
12
|
//# sourceMappingURL=usePeerStatus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePeerStatus.js","sourceRoot":"","sources":["../../src/hooks/usePeerStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"usePeerStatus.js","sourceRoot":"","sources":["../../src/hooks/usePeerStatus.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,EAAE,EAC5B,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAYvE;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,MAAM,UAAU,GAAG,oBAAoB,CACrC,gBAAgB,CAAC,iBAAiB,EAClC,qBAAqB,CAAC,UAAU,CACjC,CAAC;IAEF,OAAO,EAAE,UAAU,EAAE,CAAC;AACxB,CAAC,CAAC","sourcesContent":["import RNFishjamClientModule, {\n ReceivableEvents,\n} from '../RNFishjamClientModule';\nimport { useFishjamEventState } from './internal/useFishjamEventState';\n\n/**\n * Represents the possible statuses of a peer connection to a room (websocket state).\n *\n * idle - Peer is not connected, either never connected or successfully disconnected.\n * connecting - Peer is in the process of connecting.\n * connected - Peer has successfully connected.\n * error - There was an error in the connection process.\n */\nexport type PeerStatus = 'connecting' | 'connected' | 'error' | 'idle';\n\n/**\n * This hook provides live updates of current connection state of the local peer to a room (websocket state)\n * @returns Current peer status.\n * @deprecated\n */\nexport const usePeerStatus = () => {\n const peerStatus = useFishjamEventState<PeerStatus>(\n ReceivableEvents.PeerStatusChanged,\n RNFishjamClientModule.peerStatus,\n );\n\n return { peerStatus };\n};\n"]}
|