@stream-io/video-react-native-sdk 1.43.0 → 1.45.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 (150) hide show
  1. package/CHANGELOG.md +44 -1
  2. package/dist/commonjs/components/Call/CallControls/internal/ReactionsPicker.js.map +1 -1
  3. package/dist/commonjs/components/Call/Lobby/Lobby.js +4 -9
  4. package/dist/commonjs/components/Call/Lobby/Lobby.js.map +1 -1
  5. package/dist/commonjs/components/Call/Lobby/LobbyCameraPreview.js +93 -0
  6. package/dist/commonjs/components/Call/Lobby/LobbyCameraPreview.js.map +1 -0
  7. package/dist/commonjs/components/Call/Lobby/index.js +11 -0
  8. package/dist/commonjs/components/Call/Lobby/index.js.map +1 -1
  9. package/dist/commonjs/components/Participant/ParticipantView/VideoRenderer/TrackSubscriber.js +4 -15
  10. package/dist/commonjs/components/Participant/ParticipantView/VideoRenderer/TrackSubscriber.js.map +1 -1
  11. package/dist/commonjs/components/Participant/ParticipantView/VideoRenderer/index.js +10 -4
  12. package/dist/commonjs/components/Participant/ParticipantView/VideoRenderer/index.js.map +1 -1
  13. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js +9 -5
  14. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -1
  15. package/dist/commonjs/hooks/useLoopbackRecording.js +10 -127
  16. package/dist/commonjs/hooks/useLoopbackRecording.js.map +1 -1
  17. package/dist/commonjs/modules/call-manager/CallManager.js +37 -54
  18. package/dist/commonjs/modules/call-manager/CallManager.js.map +1 -1
  19. package/dist/commonjs/utils/StreamVideoRN/index.js +2 -0
  20. package/dist/commonjs/utils/StreamVideoRN/index.js.map +1 -1
  21. package/dist/commonjs/utils/internal/callingx/callingx.js +28 -39
  22. package/dist/commonjs/utils/internal/callingx/callingx.js.map +1 -1
  23. package/dist/commonjs/utils/internal/registerMediaEngine.js +41 -0
  24. package/dist/commonjs/utils/internal/registerMediaEngine.js.map +1 -0
  25. package/dist/commonjs/utils/internal/registerSDKGlobals.js +93 -35
  26. package/dist/commonjs/utils/internal/registerSDKGlobals.js.map +1 -1
  27. package/dist/commonjs/utils/push/android.js +13 -175
  28. package/dist/commonjs/utils/push/android.js.map +1 -1
  29. package/dist/commonjs/utils/push/internal/android.js +186 -0
  30. package/dist/commonjs/utils/push/internal/android.js.map +1 -0
  31. package/dist/commonjs/utils/push/libs/firebaseMessaging/index.js +8 -9
  32. package/dist/commonjs/utils/push/libs/firebaseMessaging/index.js.map +1 -1
  33. package/dist/commonjs/utils/push/libs/firebaseMessaging/lib.js +1 -1
  34. package/dist/commonjs/utils/push/libs/firebaseMessaging/lib.js.map +1 -1
  35. package/dist/commonjs/utils/push/setupAndroidPushEvents.js +25 -0
  36. package/dist/commonjs/utils/push/setupAndroidPushEvents.js.map +1 -0
  37. package/dist/commonjs/utils/push/setupCallingExpEvents.js +6 -2
  38. package/dist/commonjs/utils/push/setupCallingExpEvents.js.map +1 -1
  39. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js +6 -7
  40. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js.map +1 -1
  41. package/dist/commonjs/utils/push/utils.js.map +1 -1
  42. package/dist/commonjs/version.js +1 -1
  43. package/dist/module/components/Call/CallControls/internal/ReactionsPicker.js.map +1 -1
  44. package/dist/module/components/Call/Lobby/Lobby.js +4 -9
  45. package/dist/module/components/Call/Lobby/Lobby.js.map +1 -1
  46. package/dist/module/components/Call/Lobby/LobbyCameraPreview.js +87 -0
  47. package/dist/module/components/Call/Lobby/LobbyCameraPreview.js.map +1 -0
  48. package/dist/module/components/Call/Lobby/index.js +1 -0
  49. package/dist/module/components/Call/Lobby/index.js.map +1 -1
  50. package/dist/module/components/Participant/ParticipantView/VideoRenderer/TrackSubscriber.js +6 -17
  51. package/dist/module/components/Participant/ParticipantView/VideoRenderer/TrackSubscriber.js.map +1 -1
  52. package/dist/module/components/Participant/ParticipantView/VideoRenderer/index.js +11 -5
  53. package/dist/module/components/Participant/ParticipantView/VideoRenderer/index.js.map +1 -1
  54. package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js +9 -5
  55. package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -1
  56. package/dist/module/hooks/useLoopbackRecording.js +10 -127
  57. package/dist/module/hooks/useLoopbackRecording.js.map +1 -1
  58. package/dist/module/modules/call-manager/CallManager.js +36 -53
  59. package/dist/module/modules/call-manager/CallManager.js.map +1 -1
  60. package/dist/module/utils/StreamVideoRN/index.js +2 -0
  61. package/dist/module/utils/StreamVideoRN/index.js.map +1 -1
  62. package/dist/module/utils/internal/callingx/callingx.js +27 -40
  63. package/dist/module/utils/internal/callingx/callingx.js.map +1 -1
  64. package/dist/module/utils/internal/registerMediaEngine.js +37 -0
  65. package/dist/module/utils/internal/registerMediaEngine.js.map +1 -0
  66. package/dist/module/utils/internal/registerSDKGlobals.js +95 -37
  67. package/dist/module/utils/internal/registerSDKGlobals.js.map +1 -1
  68. package/dist/module/utils/push/android.js +16 -178
  69. package/dist/module/utils/push/android.js.map +1 -1
  70. package/dist/module/utils/push/internal/android.js +182 -0
  71. package/dist/module/utils/push/internal/android.js.map +1 -0
  72. package/dist/module/utils/push/libs/firebaseMessaging/index.js +8 -8
  73. package/dist/module/utils/push/libs/firebaseMessaging/index.js.map +1 -1
  74. package/dist/module/utils/push/libs/firebaseMessaging/lib.js +1 -1
  75. package/dist/module/utils/push/libs/firebaseMessaging/lib.js.map +1 -1
  76. package/dist/module/utils/push/setupAndroidPushEvents.js +21 -0
  77. package/dist/module/utils/push/setupAndroidPushEvents.js.map +1 -0
  78. package/dist/module/utils/push/setupCallingExpEvents.js +6 -2
  79. package/dist/module/utils/push/setupCallingExpEvents.js.map +1 -1
  80. package/dist/module/utils/push/setupIosVoipPushEvents.js +6 -7
  81. package/dist/module/utils/push/setupIosVoipPushEvents.js.map +1 -1
  82. package/dist/module/utils/push/utils.js.map +1 -1
  83. package/dist/module/version.js +1 -1
  84. package/dist/typescript/components/Call/Lobby/Lobby.d.ts.map +1 -1
  85. package/dist/typescript/components/Call/Lobby/LobbyCameraPreview.d.ts +28 -0
  86. package/dist/typescript/components/Call/Lobby/LobbyCameraPreview.d.ts.map +1 -0
  87. package/dist/typescript/components/Call/Lobby/index.d.ts +1 -0
  88. package/dist/typescript/components/Call/Lobby/index.d.ts.map +1 -1
  89. package/dist/typescript/components/Participant/ParticipantView/VideoRenderer/TrackSubscriber.d.ts +11 -6
  90. package/dist/typescript/components/Participant/ParticipantView/VideoRenderer/TrackSubscriber.d.ts.map +1 -1
  91. package/dist/typescript/components/Participant/ParticipantView/VideoRenderer/index.d.ts.map +1 -1
  92. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts.map +1 -1
  93. package/dist/typescript/hooks/useLoopbackRecording.d.ts +12 -69
  94. package/dist/typescript/hooks/useLoopbackRecording.d.ts.map +1 -1
  95. package/dist/typescript/modules/call-manager/CallManager.d.ts +28 -6
  96. package/dist/typescript/modules/call-manager/CallManager.d.ts.map +1 -1
  97. package/dist/typescript/modules/call-manager/types.d.ts +0 -1
  98. package/dist/typescript/modules/call-manager/types.d.ts.map +1 -1
  99. package/dist/typescript/utils/StreamVideoRN/index.d.ts.map +1 -1
  100. package/dist/typescript/utils/StreamVideoRN/types.d.ts +3 -0
  101. package/dist/typescript/utils/StreamVideoRN/types.d.ts.map +1 -1
  102. package/dist/typescript/utils/internal/callingx/callingx.d.ts +2 -0
  103. package/dist/typescript/utils/internal/callingx/callingx.d.ts.map +1 -1
  104. package/dist/typescript/utils/internal/registerMediaEngine.d.ts +15 -0
  105. package/dist/typescript/utils/internal/registerMediaEngine.d.ts.map +1 -0
  106. package/dist/typescript/utils/internal/registerSDKGlobals.d.ts.map +1 -1
  107. package/dist/typescript/utils/push/android.d.ts +3 -4
  108. package/dist/typescript/utils/push/android.d.ts.map +1 -1
  109. package/dist/typescript/utils/push/internal/android.d.ts +8 -0
  110. package/dist/typescript/utils/push/internal/android.d.ts.map +1 -0
  111. package/dist/typescript/utils/push/libs/firebaseMessaging/index.d.ts +6 -5
  112. package/dist/typescript/utils/push/libs/firebaseMessaging/index.d.ts.map +1 -1
  113. package/dist/typescript/utils/push/libs/firebaseMessaging/lib.d.ts +2 -2
  114. package/dist/typescript/utils/push/libs/firebaseMessaging/lib.d.ts.map +1 -1
  115. package/dist/typescript/utils/push/setupAndroidPushEvents.d.ts +3 -0
  116. package/dist/typescript/utils/push/setupAndroidPushEvents.d.ts.map +1 -0
  117. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts.map +1 -1
  118. package/dist/typescript/utils/push/setupIosVoipPushEvents.d.ts.map +1 -1
  119. package/dist/typescript/utils/push/utils.d.ts +2 -2
  120. package/dist/typescript/utils/push/utils.d.ts.map +1 -1
  121. package/dist/typescript/version.d.ts +1 -1
  122. package/ios/StreamInCallManager.m +4 -0
  123. package/ios/StreamInCallManager.swift +42 -10
  124. package/ios/TracksRecorder/RecorderVideoSink.swift +92 -5
  125. package/package.json +8 -8
  126. package/src/components/Call/CallControls/internal/ReactionsPicker.tsx +2 -2
  127. package/src/components/Call/Lobby/Lobby.tsx +4 -11
  128. package/src/components/Call/Lobby/LobbyCameraPreview.tsx +99 -0
  129. package/src/components/Call/Lobby/index.ts +1 -0
  130. package/src/components/Participant/ParticipantView/VideoRenderer/TrackSubscriber.tsx +56 -75
  131. package/src/components/Participant/ParticipantView/VideoRenderer/index.tsx +18 -7
  132. package/src/hooks/push/useCallingExpWithCallingStateEffect.ts +12 -5
  133. package/src/hooks/useLoopbackRecording.ts +36 -248
  134. package/src/modules/call-manager/CallManager.ts +40 -71
  135. package/src/modules/call-manager/native-module.d.ts +13 -0
  136. package/src/modules/call-manager/types.ts +0 -1
  137. package/src/utils/StreamVideoRN/index.ts +2 -0
  138. package/src/utils/StreamVideoRN/types.ts +3 -0
  139. package/src/utils/internal/callingx/callingx.ts +37 -46
  140. package/src/utils/internal/registerMediaEngine.ts +42 -0
  141. package/src/utils/internal/registerSDKGlobals.ts +115 -42
  142. package/src/utils/push/android.ts +20 -253
  143. package/src/utils/push/internal/android.ts +252 -0
  144. package/src/utils/push/libs/firebaseMessaging/index.ts +14 -22
  145. package/src/utils/push/libs/firebaseMessaging/lib.ts +3 -3
  146. package/src/utils/push/setupAndroidPushEvents.ts +25 -0
  147. package/src/utils/push/setupCallingExpEvents.ts +6 -3
  148. package/src/utils/push/setupIosVoipPushEvents.ts +8 -7
  149. package/src/utils/push/utils.ts +2 -4
  150. package/src/version.ts +1 -1
@@ -17,7 +17,7 @@ export const useCallingExpWithCallingStateEffect = () => {
17
17
  useCallStateHooks();
18
18
 
19
19
  const activeCall = useCall();
20
- const { isMute, microphone } = useMicrophoneState();
20
+ const { optimisticStatus, microphone } = useMicrophoneState();
21
21
  const callMembers = useCallMembers();
22
22
  const participants = useParticipants();
23
23
 
@@ -30,7 +30,7 @@ export const useCallingExpWithCallingStateEffect = () => {
30
30
 
31
31
  const callDisplayName = useMemo(
32
32
  () =>
33
- callCustomDisplayName ??
33
+ callCustomDisplayName ||
34
34
  getCallDisplayName(callMembers, participants, currentUserId),
35
35
  [callMembers, participants, currentUserId, callCustomDisplayName],
36
36
  );
@@ -135,8 +135,14 @@ export const useCallingExpWithCallingStateEffect = () => {
135
135
  return;
136
136
  }
137
137
 
138
- callingx.setMutedCall(activeCallCid, isMute);
139
- }, [activeCallCid, isMute]);
138
+ if (optimisticStatus === undefined) {
139
+ logger.debug(
140
+ `useCallingExpWithCallingStateEffect: mic status is not resolved yet, skipping mute sync for: ${activeCallCid}`,
141
+ );
142
+ return;
143
+ }
144
+ callingx.setMutedCall(activeCallCid, optimisticStatus === 'disabled');
145
+ }, [activeCallCid, optimisticStatus]);
140
146
 
141
147
  // Sync mute state from CallKit → app (only for system-initiated mute actions)
142
148
  useEffect(() => {
@@ -165,7 +171,8 @@ export const useCallingExpWithCallingStateEffect = () => {
165
171
  return;
166
172
  }
167
173
 
168
- const isCurrentlyMuted = microphone.state.status === 'disabled';
174
+ const isCurrentlyMuted =
175
+ microphone.state.optimisticStatus === 'disabled';
169
176
  if (isCurrentlyMuted === muted) {
170
177
  logger.debug(
171
178
  `useCallingExpWithCallingStateEffect: Mic toggle is already in the desired state: ${muted} for call: ${activeCallCid}`,
@@ -1,146 +1,71 @@
1
1
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { NativeModules } from 'react-native';
3
- import { combineLatest } from 'rxjs';
4
3
  import {
5
- Call,
6
4
  CallingState,
5
+ DEFAULT_LOOPBACK_RECORDING_DURATION_MS,
6
+ LOOPBACK_STREAMS_WAIT_TIMEOUT_MS,
7
+ clampLoopbackRecordingDuration,
8
+ getLoopbackStreams,
7
9
  videoLoggerSystem,
8
- type StreamVideoParticipant,
10
+ waitForLoopbackStreams,
11
+ withLoopbackAudioEnabled,
12
+ type LoopbackStreams,
13
+ type LoopbackTracks,
9
14
  } from '@stream-io/video-client';
15
+
10
16
  import { useCall, useCallStateHooks } from '@stream-io/video-react-bindings';
11
17
 
12
18
  /** @internal */
13
19
  const { StreamVideoReactNative } = NativeModules;
14
20
 
15
- // Upper bound on how long `startRecording` will wait for the SFU to
16
- // echo loopback tracks back via the Subscriber. Tuned generously since
17
- // this includes connection setup; consumers that want shorter feedback
18
- // should call `stopRecording` to cancel the wait early.
19
- const STREAMS_WAIT_TIMEOUT_MS = 10 * 1000;
20
- const DEFAULT_RECORDING_DURATION = 10 * 1000;
21
- const MIN_RECORDING_DURATION = 5 * 1000;
22
- const MAX_RECORDING_DURATION = 2 * 60 * 1000;
23
-
24
- type LoopbackStreams = {
25
- loopbackVideoStream?: MediaStream;
26
- loopbackAudioStream?: MediaStream;
27
- };
28
-
29
21
  export type LoopbackRecordingState = 'idle' | 'awaiting-streams' | 'recording';
30
22
 
31
- export type ResolvedStreams = {
32
- audioTrack?: MediaStreamTrack;
33
- videoTrack?: MediaStreamTrack;
34
- };
23
+ export type ResolvedStreams = LoopbackTracks;
35
24
 
36
25
  export interface StartLoopbackRecordingOptions {
37
- /**
38
- * Whether to include the loopback video track in the recording.
39
- * Defaults to `true`. Set to `false` for an audio-only recording.
40
- * Audio is always recorded — there is no video-only mode.
41
- */
26
+ /** Whether to include loopback video. Audio is always recorded. */
42
27
  includeVideo?: boolean;
43
- /**
44
- * Maximum recording duration in milliseconds, after which the
45
- * recording auto-stops and finalises the file.
46
- *
47
- * Defaults to `10_000` (10 seconds). Clamped to
48
- * `[5_000, 120_000]` (5 seconds — 2 minutes).
49
- */
28
+ /** Maximum recording duration in milliseconds. */
50
29
  maxDurationMs?: number;
51
30
  }
52
31
 
53
32
  export interface UseLoopbackRecordingResult {
54
- /**
55
- * Start a recording. The hook waits internally for the SFU loopback
56
- * streams to arrive on `localParticipant`, then begins recording.
57
- *
58
- * The returned promise resolves with the produced `file://` URI **at
59
- * the recording's terminal moment** — whether that is the auto-stop
60
- * timer expiring, an explicit `stopRecording` call, or a cleanup-
61
- * driven stop on unmount/leave. Resolves with `null` if no file was
62
- * produced (writer torn down before any buffer arrived, or
63
- * `stopRecording` was called while still awaiting streams). Rejects
64
- * on a fatal error, if a recording is already running, or if the
65
- * stream-wait times out.
66
- */
33
+ /** Starts recording and resolves with a `file://` URI. */
67
34
  startRecording: (
68
35
  options?: StartLoopbackRecordingOptions,
69
36
  ) => Promise<string | null>;
70
- /**
71
- * Signal an early termination. While `awaiting-streams` this aborts
72
- * the wait and the pending `startRecording` resolves with `null`.
73
- * While `recording` this signals native finalisation and resolves
74
- * once it completes.
75
- */
37
+ /** Stops the current recording or stream wait. */
76
38
  stopRecording: () => Promise<void>;
77
- /**
78
- * Recursively delete every file under the SDK's recordings directory.
79
- */
39
+ /** Deletes all SDK recording files. */
80
40
  clearRecordings: () => Promise<void>;
81
- /**
82
- * List every `file://` URI in the SDK's recordings directory, sorted
83
- * most-recent first. Returns an empty array if the directory doesn't
84
- * exist yet.
85
- */
41
+ /** Lists SDK recording file URIs. */
86
42
  getRecordings: () => Promise<string[]>;
87
- /**
88
- * Lifecycle phase of the recording, owned by the hook:
89
- * - `'idle'`: no recording in progress.
90
- * - `'awaiting-streams'`: `startRecording` was called but the SFU
91
- * has not yet echoed the loopback tracks back.
92
- * - `'recording'`: native pipeline is actively writing.
93
- */
43
+ /** Lifecycle phase of the recording. */
94
44
  recordingState: LoopbackRecordingState;
95
- /**
96
- * The SFU loopback video stream on the local participant, when
97
- * present. Identified by reference inequality against
98
- * `call.camera.state.mediaStream`.
99
- */
45
+ /** SFU-echoed video stream on the local participant. */
100
46
  loopbackVideoStream?: MediaStream;
101
- /**
102
- * The SFU loopback audio stream on the local participant, when
103
- * present. Identified by reference inequality against
104
- * `call.microphone.state.mediaStream`.
105
- */
47
+ /** SFU-echoed audio stream on the local participant. */
106
48
  loopbackAudioStream?: MediaStream;
107
49
  }
108
50
 
109
- /**
110
- * Records the SFU loopback streams (audio + video) on the local participant
111
- * to a local MP4 file. Designed for the `allowOwnTracksLoopback` pre-call test mode:
112
- * the SFU echoes the caller's published tracks back through the Subscriber
113
- * peer connection. The hook identifies the loopback streams on the local
114
- * participant by reference inequality against
115
- * `call.camera.state.mediaStream` / `call.microphone.state.mediaStream` —
116
- * the canonical references to the local capture — and captures them.
117
- */
51
+ /** Records SFU loopback streams to a local MP4 file. */
118
52
  export function useLoopbackRecording(): UseLoopbackRecordingResult {
119
53
  const call = useCall();
120
- const {
121
- useCallCallingState,
122
- useParticipantCount,
123
- useLocalParticipant,
124
- useCameraState,
125
- useMicrophoneState,
126
- } = useCallStateHooks();
54
+ const { useCallCallingState, useParticipantCount, useLocalParticipant } =
55
+ useCallStateHooks();
127
56
  const callingState = useCallCallingState();
128
57
  const participantCount = useParticipantCount();
129
58
  const localParticipant = useLocalParticipant();
130
- const { mediaStream: cameraStream } = useCameraState();
131
- const { mediaStream: microphoneStream } = useMicrophoneState();
132
59
 
133
60
  const [recordingState, setRecordingState] =
134
61
  useState<LoopbackRecordingState>('idle');
135
62
  const recordingStateRef = useRef<LoopbackRecordingState>('idle');
136
63
  const isMountedRef = useRef(true);
137
- // Used to abort the awaiting-streams wait on stop / leave / unmount.
138
64
  const awaitAbortRef = useRef<AbortController | null>(null);
139
65
 
140
66
  const loopbackStreams = useMemo<LoopbackStreams>(
141
- () =>
142
- getLoopbackStreamsFor(localParticipant, cameraStream, microphoneStream),
143
- [localParticipant, cameraStream, microphoneStream],
67
+ () => getLoopbackStreams(call, localParticipant),
68
+ [call, localParticipant],
144
69
  );
145
70
 
146
71
  const updateState = useCallback((next: LoopbackRecordingState) => {
@@ -177,7 +102,7 @@ export function useLoopbackRecording(): UseLoopbackRecordingResult {
177
102
  const startRecording = useCallback(
178
103
  async ({
179
104
  includeVideo = true,
180
- maxDurationMs = DEFAULT_RECORDING_DURATION,
105
+ maxDurationMs = DEFAULT_LOOPBACK_RECORDING_DURATION_MS,
181
106
  }: StartLoopbackRecordingOptions = {}): Promise<string | null> => {
182
107
  if (!call) {
183
108
  return null;
@@ -200,12 +125,11 @@ export function useLoopbackRecording(): UseLoopbackRecordingResult {
200
125
  awaitAbortRef.current = new AbortController();
201
126
  updateState('awaiting-streams');
202
127
 
203
- let audioTrack: MediaStreamTrack | undefined;
204
128
  try {
205
129
  const streams = await waitForLoopbackStreams(call, {
206
130
  includeVideo,
207
131
  signal: awaitAbortRef.current.signal,
208
- timeoutMs: STREAMS_WAIT_TIMEOUT_MS,
132
+ timeoutMs: LOOPBACK_STREAMS_WAIT_TIMEOUT_MS,
209
133
  });
210
134
 
211
135
  if (streams === null) {
@@ -215,38 +139,21 @@ export function useLoopbackRecording(): UseLoopbackRecordingResult {
215
139
  return null;
216
140
  }
217
141
 
218
- audioTrack = streams.audioTrack;
219
- const videoTrackId = streams.videoTrack?.id;
220
-
221
- // The loopback audio track lands disabled (the SDK default-mutes
222
- // it to prevent echo). Enable it so the native recording
223
- // pipeline receives PCM; `finally` returns it to muted.
224
- if (audioTrack) {
225
- audioTrack.enabled = true;
226
- }
227
142
  updateState('recording');
228
143
 
229
- const clampedDuration = Math.min(
230
- MAX_RECORDING_DURATION,
231
- Math.max(MIN_RECORDING_DURATION, maxDurationMs),
232
- );
233
-
234
- // Pre-size the native encoder to the publisher's max video
235
- // publish-option dimension. Without this, the encoder locks to
236
- // whatever the SFU happens to echo *first* and stays there for the
237
- // rest of the recording even after the network improves and
238
- // higher layers arrive.
239
144
  const publishMaxDim = call.getMaxVideoPublishDimension();
240
145
 
241
146
  try {
242
- const uri: string | null =
243
- await StreamVideoReactNative.startTrackRecording({
244
- videoTrackId,
245
- maxDurationMs: Math.round(clampedDuration),
246
- targetWidth: publishMaxDim?.width,
247
- targetHeight: publishMaxDim?.height,
248
- });
249
- return uri;
147
+ return await withLoopbackAudioEnabled(
148
+ streams,
149
+ (): Promise<string | null> =>
150
+ StreamVideoReactNative.startTrackRecording({
151
+ videoTrackId: streams.videoTrack?.id,
152
+ maxDurationMs: clampLoopbackRecordingDuration(maxDurationMs),
153
+ targetWidth: publishMaxDim?.width,
154
+ targetHeight: publishMaxDim?.height,
155
+ }),
156
+ );
250
157
  } catch (error) {
251
158
  videoLoggerSystem
252
159
  .getLogger('useLoopbackRecording')
@@ -254,9 +161,6 @@ export function useLoopbackRecording(): UseLoopbackRecordingResult {
254
161
  throw new Error('failed to start recording');
255
162
  }
256
163
  } finally {
257
- if (audioTrack) {
258
- audioTrack.enabled = false;
259
- }
260
164
  awaitAbortRef.current = null;
261
165
  updateState('idle');
262
166
  }
@@ -288,11 +192,6 @@ export function useLoopbackRecording(): UseLoopbackRecordingResult {
288
192
  }
289
193
  }, []);
290
194
 
291
- // Auto-stop on call leave / end. Aborts an awaiting-streams wait or
292
- // signals native finalisation depending on which phase we're in.
293
- // Without this, leaving the call mid-recording would leave native
294
- // encoders mid-write while the SFU subscriber tracks end under their
295
- // feet — undefined final file state.
296
195
  useEffect(() => {
297
196
  if (
298
197
  callingState === CallingState.LEFT ||
@@ -305,8 +204,6 @@ export function useLoopbackRecording(): UseLoopbackRecordingResult {
305
204
  }
306
205
  }, [callingState, stopRecording]);
307
206
 
308
- // Auto-stop if another participant joins. Loopback recording is a
309
- // single-user pre-call test.
310
207
  useEffect(() => {
311
208
  if (recordingState !== 'idle' && participantCount > 1) {
312
209
  stopRecording().catch(() => {});
@@ -337,112 +234,3 @@ export function useLoopbackRecording(): UseLoopbackRecordingResult {
337
234
  loopbackAudioStream: loopbackStreams.loopbackAudioStream,
338
235
  };
339
236
  }
340
-
341
- function getLoopbackStreamsFor(
342
- participant: StreamVideoParticipant | undefined,
343
- cameraStream: MediaStream | undefined,
344
- microphoneStream: MediaStream | undefined,
345
- ): LoopbackStreams {
346
- return {
347
- loopbackVideoStream:
348
- participant?.videoStream && participant.videoStream !== cameraStream
349
- ? participant.videoStream
350
- : undefined,
351
- loopbackAudioStream:
352
- participant?.audioStream && participant.audioStream !== microphoneStream
353
- ? participant.audioStream
354
- : undefined,
355
- };
356
- }
357
-
358
- /**
359
- * Subscribe to `localParticipant$` and resolve once the requested loopback
360
- * streams are present on the participant. Aborts cleanly on `signal`
361
- * (resolves `null`) and rejects on timeout.
362
- */
363
- function waitForLoopbackStreams(
364
- call: Call,
365
- opts: { includeVideo: boolean; signal: AbortSignal; timeoutMs: number },
366
- ): Promise<ResolvedStreams | null> {
367
- return new Promise((resolve, reject) => {
368
- const initial = getLoopbackStreams(
369
- call.state.localParticipant,
370
- call.camera.state.mediaStream,
371
- call.microphone.state.mediaStream,
372
- opts.includeVideo,
373
- );
374
- if (initial) {
375
- resolve(initial);
376
- return;
377
- }
378
-
379
- const cleanup = () => {
380
- subscription.unsubscribe();
381
- if (timeoutId !== undefined) {
382
- clearTimeout(timeoutId);
383
- }
384
- opts.signal.removeEventListener('abort', onAbort);
385
- };
386
-
387
- const onAbort = () => {
388
- cleanup();
389
- resolve(null);
390
- };
391
-
392
- opts.signal.addEventListener('abort', onAbort);
393
-
394
- const timeoutId = setTimeout(() => {
395
- cleanup();
396
- reject(
397
- new Error(
398
- 'useLoopbackRecording: timed out waiting for loopback streams. ' +
399
- 'Ensure the call was joined with `allowOwnTracksLoopback: true` and ' +
400
- 'that the SFU is configured to echo self-sub tracks.',
401
- ),
402
- );
403
- }, opts.timeoutMs);
404
-
405
- const subscription = combineLatest([
406
- call.state.localParticipant$,
407
- call.camera.state.mediaStream$,
408
- call.microphone.state.mediaStream$,
409
- ]).subscribe(([participant, cameraStream, microphoneStream]) => {
410
- const ready = getLoopbackStreams(
411
- participant,
412
- cameraStream,
413
- microphoneStream,
414
- opts.includeVideo,
415
- );
416
- if (ready) {
417
- cleanup();
418
- resolve(ready);
419
- }
420
- });
421
- });
422
- }
423
-
424
- function getLoopbackStreams(
425
- participant: StreamVideoParticipant | undefined,
426
- cameraStream: MediaStream | undefined,
427
- microphoneStream: MediaStream | undefined,
428
- includeVideo: boolean,
429
- ): ResolvedStreams | undefined {
430
- if (!participant) return undefined;
431
-
432
- const { loopbackAudioStream, loopbackVideoStream } = getLoopbackStreamsFor(
433
- participant,
434
- cameraStream,
435
- microphoneStream,
436
- );
437
-
438
- const audioTrack = loopbackAudioStream?.getAudioTracks()[0];
439
- const videoTrack = includeVideo
440
- ? loopbackVideoStream?.getVideoTracks()[0]
441
- : undefined;
442
-
443
- if (!audioTrack || (includeVideo && !videoTrack)) {
444
- return undefined;
445
- }
446
-
447
- return { audioTrack, videoTrack };
448
- }
@@ -9,8 +9,8 @@ import type {
9
9
  AudioEndpoint as CallingxAudioEndpoint,
10
10
  AudioEndpointsSnapshot as CallingxAudioSnapshot,
11
11
  } from '@stream-io/react-native-callingx';
12
- import { getCallingxLibIfAvailable } from '../../utils/push/libs/callingx';
13
12
  import { videoLoggerSystem } from '@stream-io/video-client';
13
+ import { getCallingxLibIfAvailable } from '../../utils/push/libs';
14
14
 
15
15
  const NativeManager = NativeModules.StreamInCallManager;
16
16
  const CallingxModule = getCallingxLibIfAvailable();
@@ -296,26 +296,32 @@ class SpeakerManager {
296
296
  };
297
297
  }
298
298
 
299
- const shouldBypassForCallKit = (): boolean => {
300
- if (Platform.OS !== 'ios') {
301
- return false;
302
- }
303
- if (!CallingxModule) {
304
- return false;
305
- }
306
- return (
307
- CallingxModule.isSetup &&
308
- (CallingxModule.hasRegisteredCall() || CallingxModule.isOngoingCallsEnabled)
309
- );
310
- };
311
-
312
299
  export class CallManager {
313
300
  audioDevices = new AudioDevicesManager();
314
301
  ios = new IOSCallManager();
315
302
  speaker = new SpeakerManager();
316
303
 
317
304
  /**
318
- * Starts the in call manager.
305
+ * The audio config recorded via {@link start}. The SDK's internal call manager reads it at the
306
+ * next join-time start and applies it before the native audio manager is activated.
307
+ */
308
+ private storedConfig?: StreamInCallManagerConfig;
309
+
310
+ /**
311
+ * The config recorded via {@link start}.
312
+ *
313
+ * @internal Read by the SDK's internal call manager at join; not intended for app use.
314
+ */
315
+ getStoredConfig = (): StreamInCallManagerConfig | undefined =>
316
+ this.storedConfig;
317
+
318
+ /**
319
+ * Records the desired audio config for the call.
320
+ *
321
+ * This does NOT start the native audio manager — the SDK owns native start/stop and applies this
322
+ * config at the next join-time start (before the audio manager is activated). Call it **before**
323
+ * joining. Calling it mid-call only updates the stored config; it does not change the running
324
+ * call's audio, and the new config takes effect on the next call/rejoin.
319
325
  *
320
326
  * @param config.audioRole The audio role to set. It can be one of the following:
321
327
  * - `'communicator'`: (Default) For use cases like video or voice calls.
@@ -325,80 +331,43 @@ export class CallManager {
325
331
  * It prioritizes high-quality stereo audio streaming.
326
332
  * Audio routing is controlled by the OS, and manual switching is not supported.
327
333
  *
328
- * @param config.deviceEndpointType The default audio device endpoint type to set. It can be one of the following:
329
- * - `'speaker'`: (Default) For normal video or voice calls.
334
+ * @param config.deviceEndpointType Overrides the default audio device endpoint. When omitted,
335
+ * the SDK uses the device derived from the call settings. It can be one of the following:
336
+ * - `'speaker'`: For normal video or voice calls.
330
337
  * - `'earpiece'`: For voice-only mobile call type scenarios.
331
- *
332
- * @param config.enableStereoAudioOutput Whether to enable stereo audio output. Only supported for listener audio role.
333
338
  */
334
339
  start = (config?: StreamInCallManagerConfig): void => {
335
- if (shouldBypassForCallKit()) {
336
- if (config?.audioRole === 'communicator' && CallingxModule) {
337
- const type = config.deviceEndpointType ?? 'speaker';
338
- safeNativeCall('setDefaultAudioDeviceEndpointType (callingx)', () =>
339
- CallingxModule.setDefaultAudioDeviceEndpointType(type),
340
- );
341
- safeNativeCall('setDefaultAudioDeviceEndpointType', () =>
342
- NativeManager.setDefaultAudioDeviceEndpointType(type),
343
- );
344
- }
345
- videoLoggerSystem
346
- .getLogger('CallManager')
347
- .debug(
348
- 'start: skipping start as callkit is handling the audio session',
349
- );
350
- return;
351
- }
352
- if (isAndroidTelecomManaged()) {
353
- // Telecom owns routing/focus; forward the sticky preference to callingx and run in
354
- // telecom-managed mode (StreamInCallManager keeps proximity/keep-screen-on only).
355
- if (config?.audioRole !== 'listener' && CallingxModule) {
356
- safeNativeCall('setDefaultAudioDeviceEndpointType (callingx)', () =>
357
- CallingxModule.setDefaultAudioDeviceEndpointType(
358
- config?.deviceEndpointType ?? 'speaker',
359
- ),
360
- );
361
- }
362
- NativeManager.setTelecomManagedMode(true);
363
- NativeManager.setAudioRole(config?.audioRole ?? 'communicator');
364
- NativeManager.start();
365
- return;
366
- }
367
- if (Platform.OS === 'android') {
368
- NativeManager.setTelecomManagedMode(false);
369
- }
370
- NativeManager.setAudioRole(config?.audioRole ?? 'communicator');
371
- if (config?.audioRole === 'communicator') {
372
- const type = config.deviceEndpointType ?? 'speaker';
373
- NativeManager.setDefaultAudioDeviceEndpointType(type);
374
- }
375
- if (config?.audioRole === 'listener' && config.enableStereoAudioOutput) {
376
- NativeManager.setEnableStereoAudioOutput(true);
377
- }
378
- NativeManager.start();
340
+ this.storedConfig = config;
341
+ videoLoggerSystem
342
+ .getLogger('CallManager')
343
+ .debug('start: stored call manager config', { config });
379
344
  };
380
345
 
381
346
  /**
382
- * Stops the in call manager.
347
+ * Clears the stored audio config.
383
348
  */
384
349
  stop = (): void => {
385
- if (shouldBypassForCallKit()) {
386
- videoLoggerSystem
387
- .getLogger('CallManager')
388
- .debug('stop: skipping stop as callkit is handling the audio session');
389
- return;
390
- }
391
- NativeManager.stop();
350
+ this.storedConfig = undefined;
351
+ videoLoggerSystem
352
+ .getLogger('CallManager')
353
+ .debug('[public] stop(): cleared stored config');
392
354
  };
393
355
 
394
356
  /**
395
357
  * For debugging purposes, will emit a log event with the current audio state.
396
358
  * in the native layer.
359
+ *
360
+ * NOTE: This method might be called outside of the call JOIN/LEFT window,
361
+ * so it may lead to default peer connection factory and adm being created.
397
362
  */
398
363
  logAudioState = (): void => NativeManager.logAudioState();
399
364
 
400
365
  /**
401
366
  * For debugging purposes, returns the current audio state as a string.
367
+ *
368
+ * NOTE: This method might be called outside of the call JOIN/LEFT window,
369
+ * so it may lead to default peer connection factory and adm being created.
370
+ *
402
371
  * @returns A string containing the current audio state information.
403
372
  */
404
373
  getAudioStateLog = (): string => NativeManager.getAudioStateLog();
@@ -92,6 +92,19 @@ export interface CallManager extends NativeModule {
92
92
  */
93
93
  setEnableStereoAudioOutput: (enable: boolean) => void;
94
94
 
95
+ /**
96
+ * Sets the microphone mute mode on the call's ADM. No-ops when no call ADM is active. iOS-only.
97
+ * @param mode - The `AudioEngineMuteMode` value.
98
+ */
99
+ setMuteMode: (mode: number) => void;
100
+
101
+ /**
102
+ * Keeps the recording chain prepared while muted so the engine stays
103
+ * full-duplex. No-ops when no call ADM is active. iOS-only.
104
+ * @param enabled - Whether to keep recording always prepared.
105
+ */
106
+ setRecordingAlwaysPreparedMode: (enabled: boolean) => void;
107
+
95
108
  /**
96
109
  * Log the current audio state natively.
97
110
  * Meant for debugging purposes.
@@ -56,5 +56,4 @@ export type StreamInCallManagerConfig =
56
56
  }
57
57
  | {
58
58
  audioRole: 'listener';
59
- enableStereoAudioOutput?: boolean;
60
59
  };
@@ -1,6 +1,7 @@
1
1
  import type { StreamVideoConfig } from './types';
2
2
  import pushLogoutCallbacks from '../internal/pushLogoutCallback';
3
3
  import { setupIosVoipPushEvents } from '../push/setupIosVoipPushEvents';
4
+ import { setupAndroidPushEvents } from '../push/setupAndroidPushEvents';
4
5
  import { setupCallingExpEvents } from '../push/setupCallingExpEvents';
5
6
  import {
6
7
  extractCallingExpOptions,
@@ -133,6 +134,7 @@ export class StreamVideoRN {
133
134
 
134
135
  setupCallingExpEvents(pushConfig);
135
136
  setupIosVoipPushEvents(pushConfig);
137
+ setupAndroidPushEvents(pushConfig);
136
138
  }
137
139
 
138
140
  static getConfig() {
@@ -26,6 +26,9 @@ export type StreamVideoConfig = {
26
26
  * @default undefined
27
27
  */
28
28
  push?: {
29
+ /**
30
+ * @deprecated Expo is auto-detected; this value is ignored and the property will be removed in a future major version.
31
+ */
29
32
  isExpo?: boolean;
30
33
  /**
31
34
  * The publish options to be used when joining a call from a push notification.