@stream-io/video-react-native-sdk 1.44.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.
- package/CHANGELOG.md +25 -3
- package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js +9 -5
- package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -1
- package/dist/commonjs/hooks/useLoopbackRecording.js +10 -127
- package/dist/commonjs/hooks/useLoopbackRecording.js.map +1 -1
- package/dist/commonjs/utils/StreamVideoRN/index.js +2 -0
- package/dist/commonjs/utils/StreamVideoRN/index.js.map +1 -1
- package/dist/commonjs/utils/internal/callingx/callingx.js +2 -2
- package/dist/commonjs/utils/push/android.js +7 -167
- package/dist/commonjs/utils/push/android.js.map +1 -1
- package/dist/commonjs/utils/push/internal/android.js +186 -0
- package/dist/commonjs/utils/push/internal/android.js.map +1 -0
- package/dist/commonjs/utils/push/libs/firebaseMessaging/index.js +9 -1
- package/dist/commonjs/utils/push/libs/firebaseMessaging/index.js.map +1 -1
- package/dist/commonjs/utils/push/libs/firebaseMessaging/lib.js +1 -1
- package/dist/commonjs/utils/push/libs/firebaseMessaging/lib.js.map +1 -1
- package/dist/commonjs/utils/push/setupAndroidPushEvents.js +25 -0
- package/dist/commonjs/utils/push/setupAndroidPushEvents.js.map +1 -0
- package/dist/commonjs/utils/push/setupCallingExpEvents.js +6 -2
- package/dist/commonjs/utils/push/setupCallingExpEvents.js.map +1 -1
- package/dist/commonjs/utils/push/setupIosVoipPushEvents.js +6 -7
- package/dist/commonjs/utils/push/setupIosVoipPushEvents.js.map +1 -1
- package/dist/commonjs/utils/push/utils.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js +9 -5
- package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -1
- package/dist/module/hooks/useLoopbackRecording.js +10 -127
- package/dist/module/hooks/useLoopbackRecording.js.map +1 -1
- package/dist/module/utils/StreamVideoRN/index.js +2 -0
- package/dist/module/utils/StreamVideoRN/index.js.map +1 -1
- package/dist/module/utils/internal/callingx/callingx.js +2 -2
- package/dist/module/utils/push/android.js +9 -169
- package/dist/module/utils/push/android.js.map +1 -1
- package/dist/module/utils/push/internal/android.js +182 -0
- package/dist/module/utils/push/internal/android.js.map +1 -0
- package/dist/module/utils/push/libs/firebaseMessaging/index.js +9 -1
- package/dist/module/utils/push/libs/firebaseMessaging/index.js.map +1 -1
- package/dist/module/utils/push/libs/firebaseMessaging/lib.js +1 -1
- package/dist/module/utils/push/libs/firebaseMessaging/lib.js.map +1 -1
- package/dist/module/utils/push/setupAndroidPushEvents.js +21 -0
- package/dist/module/utils/push/setupAndroidPushEvents.js.map +1 -0
- package/dist/module/utils/push/setupCallingExpEvents.js +6 -2
- package/dist/module/utils/push/setupCallingExpEvents.js.map +1 -1
- package/dist/module/utils/push/setupIosVoipPushEvents.js +6 -7
- package/dist/module/utils/push/setupIosVoipPushEvents.js.map +1 -1
- package/dist/module/utils/push/utils.js.map +1 -1
- package/dist/module/version.js +1 -1
- package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts.map +1 -1
- package/dist/typescript/hooks/useLoopbackRecording.d.ts +12 -69
- package/dist/typescript/hooks/useLoopbackRecording.d.ts.map +1 -1
- package/dist/typescript/utils/StreamVideoRN/index.d.ts.map +1 -1
- package/dist/typescript/utils/push/android.d.ts +3 -4
- package/dist/typescript/utils/push/android.d.ts.map +1 -1
- package/dist/typescript/utils/push/internal/android.d.ts +8 -0
- package/dist/typescript/utils/push/internal/android.d.ts.map +1 -0
- package/dist/typescript/utils/push/libs/firebaseMessaging/index.d.ts +6 -4
- package/dist/typescript/utils/push/libs/firebaseMessaging/index.d.ts.map +1 -1
- package/dist/typescript/utils/push/libs/firebaseMessaging/lib.d.ts +2 -2
- package/dist/typescript/utils/push/libs/firebaseMessaging/lib.d.ts.map +1 -1
- package/dist/typescript/utils/push/setupAndroidPushEvents.d.ts +3 -0
- package/dist/typescript/utils/push/setupAndroidPushEvents.d.ts.map +1 -0
- package/dist/typescript/utils/push/setupCallingExpEvents.d.ts.map +1 -1
- package/dist/typescript/utils/push/setupIosVoipPushEvents.d.ts.map +1 -1
- package/dist/typescript/utils/push/utils.d.ts +2 -2
- package/dist/typescript/utils/push/utils.d.ts.map +1 -1
- package/dist/typescript/version.d.ts +1 -1
- package/ios/TracksRecorder/RecorderVideoSink.swift +92 -5
- package/package.json +4 -4
- package/src/hooks/push/useCallingExpWithCallingStateEffect.ts +12 -5
- package/src/hooks/useLoopbackRecording.ts +36 -248
- package/src/utils/StreamVideoRN/index.ts +2 -0
- package/src/utils/internal/callingx/callingx.ts +2 -2
- package/src/utils/push/android.ts +12 -237
- package/src/utils/push/internal/android.ts +252 -0
- package/src/utils/push/libs/firebaseMessaging/index.ts +16 -5
- package/src/utils/push/libs/firebaseMessaging/lib.ts +3 -3
- package/src/utils/push/setupAndroidPushEvents.ts +25 -0
- package/src/utils/push/setupCallingExpEvents.ts +6 -3
- package/src/utils/push/setupIosVoipPushEvents.ts +8 -7
- package/src/utils/push/utils.ts +2 -4
- package/src/version.ts +1 -1
|
@@ -12,11 +12,21 @@ import WebRTC
|
|
|
12
12
|
///
|
|
13
13
|
/// Each delivered `RTCVideoFrame` is normalised to a CVPixelBuffer in the
|
|
14
14
|
/// hardware H.264 encoder's native format — **NV12**
|
|
15
|
-
/// (`kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange`).
|
|
16
|
-
/// `
|
|
17
|
-
///
|
|
18
|
-
///
|
|
19
|
-
///
|
|
15
|
+
/// (`kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange`). One branch per
|
|
16
|
+
/// buffer type `renderFrame` can be handed:
|
|
17
|
+
///
|
|
18
|
+
/// - `RTCCVPixelBuffer` (camera passthrough) already wraps a CVPixelBuffer,
|
|
19
|
+
/// so the underlying buffer is forwarded unchanged.
|
|
20
|
+
/// - `RTCNV12Buffer` already holds NV12 planes, but as raw pointers rather
|
|
21
|
+
/// than a CVPixelBuffer, so the planes are copied row-wise into a fresh
|
|
22
|
+
/// one. No format conversion. This is the buffer type decoded remote
|
|
23
|
+
/// frames arrive as, so it is the hot path for loopback recording — do
|
|
24
|
+
/// not remove it. Without it these frames fall through to `toI420()`
|
|
25
|
+
/// below, which converts NV12 → I420 → NV12 and caps throughput at
|
|
26
|
+
/// roughly half the source frame rate.
|
|
27
|
+
/// - `RTCI420Buffer` (and anything else, via `toI420()`) is converted into
|
|
28
|
+
/// a fresh IOSurface-backed NV12 buffer by interleaving the U and V
|
|
29
|
+
/// planes — a plane reorder, no colour-space conversion.
|
|
20
30
|
///
|
|
21
31
|
/// **Why NV12 and not BGRA?** AVAssetWriter's hardware encoder accepts
|
|
22
32
|
/// both, but BGRA requires an internal colour-space conversion that
|
|
@@ -51,6 +61,8 @@ import WebRTC
|
|
|
51
61
|
if let cvBuffer = frame.buffer as? RTCCVPixelBuffer {
|
|
52
62
|
// Camera passthrough — already a CVPixelBuffer (typically NV12 on iOS).
|
|
53
63
|
pixelBuffer = cvBuffer.pixelBuffer
|
|
64
|
+
} else if let nv12 = frame.buffer as? RTCNV12Buffer {
|
|
65
|
+
pixelBuffer = Self.makeNV12PixelBuffer(fromNV12: nv12)
|
|
54
66
|
} else if let i420 = frame.buffer as? RTCI420Buffer {
|
|
55
67
|
pixelBuffer = Self.makeNV12PixelBuffer(fromI420: i420)
|
|
56
68
|
} else {
|
|
@@ -67,6 +79,81 @@ import WebRTC
|
|
|
67
79
|
frameHandler(outputBuffer, frame.width, frame.height, frame.timeStampNs)
|
|
68
80
|
}
|
|
69
81
|
|
|
82
|
+
private static func makeNV12PixelBuffer(fromNV12 nv12: RTCNV12Buffer) -> CVPixelBuffer? {
|
|
83
|
+
let width = Int(nv12.width)
|
|
84
|
+
let height = Int(nv12.height)
|
|
85
|
+
let chromaWidth = Int(nv12.chromaWidth)
|
|
86
|
+
let chromaHeight = Int(nv12.chromaHeight)
|
|
87
|
+
|
|
88
|
+
guard let buffer = makePixelBuffer(width: width, height: height) else { return nil }
|
|
89
|
+
|
|
90
|
+
CVPixelBufferLockBaseAddress(buffer, [])
|
|
91
|
+
defer { CVPixelBufferUnlockBaseAddress(buffer, []) }
|
|
92
|
+
|
|
93
|
+
guard let yDest = CVPixelBufferGetBaseAddressOfPlane(buffer, 0) else { return nil }
|
|
94
|
+
copyPlane(
|
|
95
|
+
source: UnsafeRawPointer(nv12.dataY),
|
|
96
|
+
sourceStride: Int(nv12.strideY),
|
|
97
|
+
destination: yDest,
|
|
98
|
+
destinationStride: CVPixelBufferGetBytesPerRowOfPlane(buffer, 0),
|
|
99
|
+
rowBytes: width,
|
|
100
|
+
rows: height
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
// Plane 1: UV — already interleaved, so two bytes per chroma sample.
|
|
104
|
+
guard let uvDest = CVPixelBufferGetBaseAddressOfPlane(buffer, 1) else { return nil }
|
|
105
|
+
copyPlane(
|
|
106
|
+
source: UnsafeRawPointer(nv12.dataUV),
|
|
107
|
+
sourceStride: Int(nv12.strideUV),
|
|
108
|
+
destination: uvDest,
|
|
109
|
+
destinationStride: CVPixelBufferGetBytesPerRowOfPlane(buffer, 1),
|
|
110
|
+
rowBytes: chromaWidth * 2,
|
|
111
|
+
rows: chromaHeight
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
return buffer
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private static func makePixelBuffer(width: Int, height: Int) -> CVPixelBuffer? {
|
|
118
|
+
var pixelBuffer: CVPixelBuffer?
|
|
119
|
+
let attrs: [String: Any] = [
|
|
120
|
+
kCVPixelBufferIOSurfacePropertiesKey as String: [:] as [String: Any],
|
|
121
|
+
]
|
|
122
|
+
let status = CVPixelBufferCreate(
|
|
123
|
+
kCFAllocatorDefault,
|
|
124
|
+
width,
|
|
125
|
+
height,
|
|
126
|
+
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
|
|
127
|
+
attrs as CFDictionary,
|
|
128
|
+
&pixelBuffer
|
|
129
|
+
)
|
|
130
|
+
guard status == kCVReturnSuccess else { return nil }
|
|
131
|
+
return pixelBuffer
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/// Row-wise copy, collapsing to a single `memcpy` when the strides match.
|
|
135
|
+
private static func copyPlane(
|
|
136
|
+
source: UnsafeRawPointer,
|
|
137
|
+
sourceStride: Int,
|
|
138
|
+
destination: UnsafeMutableRawPointer,
|
|
139
|
+
destinationStride: Int,
|
|
140
|
+
rowBytes: Int,
|
|
141
|
+
rows: Int
|
|
142
|
+
) {
|
|
143
|
+
if sourceStride == destinationStride && sourceStride == rowBytes {
|
|
144
|
+
memcpy(destination, source, rowBytes * rows)
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
let copyBytes = min(rowBytes, min(sourceStride, destinationStride))
|
|
148
|
+
for row in 0..<rows {
|
|
149
|
+
memcpy(
|
|
150
|
+
destination.advanced(by: row * destinationStride),
|
|
151
|
+
source.advanced(by: row * sourceStride),
|
|
152
|
+
copyBytes
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
70
157
|
// MARK: - I420 → NV12
|
|
71
158
|
|
|
72
159
|
/// Allocates a fresh IOSurface-backed NV12 `CVPixelBuffer` and copies
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stream-io/video-react-native-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.45.0",
|
|
4
4
|
"description": "Stream Video SDK for React Native",
|
|
5
5
|
"author": "https://getstream.io",
|
|
6
6
|
"homepage": "https://getstream.io/video/docs/react-native/",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"!**/.*"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@stream-io/video-client": "1.
|
|
56
|
-
"@stream-io/video-react-bindings": "1.20.
|
|
55
|
+
"@stream-io/video-client": "1.59.0",
|
|
56
|
+
"@stream-io/video-react-bindings": "1.20.1",
|
|
57
57
|
"intl-pluralrules": "2.0.1",
|
|
58
58
|
"react-native-url-polyfill": "^3.0.0",
|
|
59
59
|
"rxjs": "~7.8.2",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"@react-native/jest-preset": "0.86.2",
|
|
119
119
|
"@react-native/metro-config": "0.86.2",
|
|
120
120
|
"@stream-io/noise-cancellation-react-native": "^0.11.0",
|
|
121
|
-
"@stream-io/react-native-callingx": "^0.
|
|
121
|
+
"@stream-io/react-native-callingx": "^0.11.0",
|
|
122
122
|
"@stream-io/react-native-webrtc": "145.3.1",
|
|
123
123
|
"@stream-io/typescript-config": "^0.0.0",
|
|
124
124
|
"@stream-io/video-filters-react-native": "^0.16.0",
|
|
@@ -17,7 +17,7 @@ export const useCallingExpWithCallingStateEffect = () => {
|
|
|
17
17
|
useCallStateHooks();
|
|
18
18
|
|
|
19
19
|
const activeCall = useCall();
|
|
20
|
-
const {
|
|
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
|
-
|
|
139
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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:
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
}
|
|
@@ -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() {
|
|
@@ -48,7 +48,7 @@ export function getCallDisplayName(
|
|
|
48
48
|
if (names.length === 0) {
|
|
49
49
|
names = [
|
|
50
50
|
participants.find((participant) => participant.userId === currentUserId)
|
|
51
|
-
?.name
|
|
51
|
+
?.name || 'Call',
|
|
52
52
|
];
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -57,7 +57,7 @@ export function getCallDisplayName(
|
|
|
57
57
|
|
|
58
58
|
function getCallDisplayNameFromCall(call: Call): string {
|
|
59
59
|
return (
|
|
60
|
-
call.state.custom?.display_name
|
|
60
|
+
call.state.custom?.display_name ||
|
|
61
61
|
getCallDisplayName(
|
|
62
62
|
call.state.members,
|
|
63
63
|
call.state.participants,
|