@openpeepshq/rn-components 0.15.0 → 0.17.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/package.json +3 -3
- package/src/components/conversations/ConversationPreviewCard.tsx +2 -6
- package/src/components/custom/navigation/side-menu.test.tsx +212 -0
- package/src/components/custom/navigation/side-menu.tsx +3 -8
- package/src/components/groups/GroupCard.tsx +3 -6
- package/src/components/icons/index.ts +2 -0
- package/src/components/jams/JamChatDrawer.test.tsx +113 -41
- package/src/components/jams/JamChatDrawer.tsx +23 -20
- package/src/components/jams/JamVideoLayout.tsx +2 -2
- package/src/components/jams/useLateTrackMediaStream.test.ts +113 -24
- package/src/components/jams/useLateTrackMediaStream.ts +86 -24
- package/src/components/navigation/nativeRouter.tsx +13 -3
- package/src/components/notifications/NotificationHeaderActions.test.tsx +285 -0
- package/src/components/notifications/NotificationHeaderActions.tsx +91 -4
- package/src/components/notifications/NotificationsList.test.tsx +109 -0
- package/src/components/notifications/NotificationsList.tsx +13 -3
- package/src/components/notifications/types/Reaction.tsx +6 -2
- package/src/components/post/pieces/PostActions.test.tsx +244 -0
- package/src/components/post/pieces/PostActions.tsx +74 -49
- package/src/components/post/pieces/ReactionPicker.test.tsx +184 -0
- package/src/components/post/pieces/ReactionPicker.tsx +58 -0
- package/src/components/post/pieces/index.ts +1 -0
- package/src/components/post/pieces/modals/ReactionsModal.tsx +1 -1
- package/src/components/post/post-form/ResourceForm.tsx +1 -1
- package/src/components/profile/EditProfileForm.test.tsx +316 -0
- package/src/components/profile/EditProfileForm.tsx +33 -4
- package/src/components/ui/dropdown-menu.test.ts +332 -0
- package/src/components/ui/dropdown-menu.tsx +108 -19
- package/src/components/ui/index.ts +1 -0
- package/src/components/ui/unread-badge.test.tsx +111 -0
- package/src/components/ui/unread-badge.tsx +43 -0
- package/src/pages/Members.test.tsx +117 -0
- package/src/pages/Members.tsx +1 -1
- package/src/pages/Notifications.tsx +3 -1
- package/src/pages/Welcome.test.tsx +166 -0
- package/src/pages/Welcome.tsx +50 -4
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
FlatList,
|
|
5
5
|
Keyboard,
|
|
6
6
|
KeyboardAvoidingView,
|
|
7
|
-
Platform,
|
|
8
7
|
Pressable,
|
|
9
8
|
View,
|
|
10
9
|
} from 'react-native';
|
|
@@ -55,13 +54,14 @@ const JamChatDrawerBody = ({
|
|
|
55
54
|
}: JamChatDrawerProps) => {
|
|
56
55
|
const { t } = useTranslation();
|
|
57
56
|
const participants = useParticipants();
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
57
|
+
// The offset is the screen-Y of the KAV's parent — the JamDrawer root,
|
|
58
|
+
// inside the shell's content area, which the screen's safe-area view pads
|
|
59
|
+
// by insets.top (on both platforms). The KAV measures the keyboard in
|
|
60
|
+
// screen space but its own frame is parent-relative. The title bar and
|
|
61
|
+
// gap-3 are siblings above the KAV in that parent, so they sit inside it
|
|
62
|
+
// and do not shift its screen-Y — correctly excluded from the offset.
|
|
63
|
+
// The body only renders where a provider has settled non-null insets, so
|
|
64
|
+
// the read below is plain.
|
|
65
65
|
const keyboardVerticalOffset = React.useContext(SafeAreaInsetsContext)!.top;
|
|
66
66
|
const {
|
|
67
67
|
messages,
|
|
@@ -85,16 +85,17 @@ const JamChatDrawerBody = ({
|
|
|
85
85
|
return () => clearTimeout(timeout);
|
|
86
86
|
}, [open, messages.length]);
|
|
87
87
|
|
|
88
|
-
// Re-pin the newest message
|
|
89
|
-
// pattern)
|
|
90
|
-
//
|
|
88
|
+
// Re-pin the newest message when the keyboard shows (the base-sheet.tsx
|
|
89
|
+
// pattern). Cross-platform: the KAV's 'padding' reflow lands after the
|
|
90
|
+
// keyboard animation, so the re-pin then settles the newest message above
|
|
91
|
+
// the composer. Skipped when readOnly (no composer to re-pin against).
|
|
91
92
|
useEffect(() => {
|
|
92
|
-
if (!open || readOnly
|
|
93
|
+
if (!open || readOnly) return;
|
|
93
94
|
const sub = Keyboard.addListener('keyboardDidShow', () =>
|
|
94
95
|
listRef.current?.scrollToEnd({ animated: true })
|
|
95
96
|
);
|
|
96
97
|
return () => sub.remove();
|
|
97
|
-
}, [open, readOnly
|
|
98
|
+
}, [open, readOnly]);
|
|
98
99
|
|
|
99
100
|
const handleSendMessage = async () => {
|
|
100
101
|
if (!(await send())) return;
|
|
@@ -107,16 +108,18 @@ const JamChatDrawerBody = ({
|
|
|
107
108
|
|
|
108
109
|
return (
|
|
109
110
|
<JamDrawer title={t('jams.drawer.chatTitle')} onClose={onClose}>
|
|
110
|
-
{/*
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
{/* Keyboard avoidance is the component's own job on both platforms so
|
|
112
|
+
it does not depend on the host app's windowSoftInputMode — the
|
|
113
|
+
shipping host does not resize, and leaving the KAV disabled there
|
|
114
|
+
left the keyboard covering the chat (the QA retest on the shipping
|
|
115
|
+
build found the keyboard still covers the chat).
|
|
116
|
+
'padding' is the validated iOS mechanism; it is host-independent
|
|
117
|
+
and self-correcting (the KAV measures the real overlap, so it adds
|
|
118
|
+
~0 when a host already resizes — no double-shrink). */}
|
|
115
119
|
<KeyboardAvoidingView
|
|
116
120
|
className="flex-1"
|
|
117
|
-
behavior=
|
|
121
|
+
behavior="padding"
|
|
118
122
|
keyboardVerticalOffset={keyboardVerticalOffset}
|
|
119
|
-
enabled={isIos}
|
|
120
123
|
>
|
|
121
124
|
{/* flex-1 is load-bearing here — without it FlatList sizes to
|
|
122
125
|
content and does not fill the remaining KAV space. */}
|
|
@@ -187,7 +187,7 @@ const ScreenSharingLayout = ({
|
|
|
187
187
|
const videoTrack = isTrackReference(screenShareTrack)
|
|
188
188
|
? screenShareTrack.publication.track
|
|
189
189
|
: undefined;
|
|
190
|
-
const
|
|
190
|
+
const { remountKey } = useLateTrackMediaStream(videoTrack);
|
|
191
191
|
|
|
192
192
|
return (
|
|
193
193
|
<View className="size-full gap-2">
|
|
@@ -199,7 +199,7 @@ const ScreenSharingLayout = ({
|
|
|
199
199
|
<View className="relative min-h-0 w-full flex-1 overflow-hidden rounded-xl border border-border">
|
|
200
200
|
{videoTrack ? (
|
|
201
201
|
<VideoTrack
|
|
202
|
-
key={`${videoTrack.sid}-${
|
|
202
|
+
key={`${videoTrack.sid}-${remountKey}`}
|
|
203
203
|
trackRef={screenShareTrack as TrackReference}
|
|
204
204
|
style={StyleSheet.absoluteFill}
|
|
205
205
|
objectFit="contain"
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useLateTrackMediaStream:
|
|
3
|
-
* stream
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* is mounted.
|
|
2
|
+
* useLateTrackMediaStream: emits a changing `remountKey` when the track's
|
|
3
|
+
* media stream gains its first video track (and a few times after, as a
|
|
4
|
+
* bounded burst). That is what lets the screen-share VideoTrack remount — and
|
|
5
|
+
* its native view re-run its one-shot `streamURL` attach — once a share that
|
|
6
|
+
* started after we joined delivers its video track, including the first share
|
|
7
|
+
* where `addtrack` fires before the layout is mounted.
|
|
9
8
|
*/
|
|
10
9
|
import React, { act } from 'react';
|
|
11
10
|
import TestRenderer from 'react-test-renderer';
|
|
@@ -37,7 +36,9 @@ type TrackLike = { mediaStream?: Stream };
|
|
|
37
36
|
|
|
38
37
|
const renderHook = (initial: TrackLike | undefined) => {
|
|
39
38
|
let track = initial;
|
|
40
|
-
const captured:
|
|
39
|
+
const captured: Array<
|
|
40
|
+
ReturnType<typeof useLateTrackMediaStream> | undefined
|
|
41
|
+
> = [];
|
|
41
42
|
const Probe = () => {
|
|
42
43
|
captured[0] = useLateTrackMediaStream(
|
|
43
44
|
track as unknown as Parameters<typeof useLateTrackMediaStream>[0]
|
|
@@ -50,7 +51,7 @@ const renderHook = (initial: TrackLike | undefined) => {
|
|
|
50
51
|
});
|
|
51
52
|
return {
|
|
52
53
|
get current() {
|
|
53
|
-
return captured[0]
|
|
54
|
+
return captured[0]!;
|
|
54
55
|
},
|
|
55
56
|
rerender(next: TrackLike | undefined) {
|
|
56
57
|
track = next;
|
|
@@ -67,27 +68,29 @@ const renderHook = (initial: TrackLike | undefined) => {
|
|
|
67
68
|
};
|
|
68
69
|
|
|
69
70
|
describe('useLateTrackMediaStream', () => {
|
|
70
|
-
it('
|
|
71
|
+
it('stays at a zero key when there is no track or stream', () => {
|
|
71
72
|
const hook = renderHook(undefined);
|
|
72
|
-
expect(hook.current).toBe(0);
|
|
73
|
+
expect(hook.current.remountKey).toBe(0);
|
|
73
74
|
hook.unmount();
|
|
74
75
|
});
|
|
75
76
|
|
|
76
|
-
it('
|
|
77
|
+
it('does not remount when the stream already has its track at mount', () => {
|
|
77
78
|
const hook = renderHook({ mediaStream: makeMediaStream(1) });
|
|
78
|
-
|
|
79
|
+
// The share is already attached: no first-track transition, so the key
|
|
80
|
+
// stays at 0 (no pointless remount of a working view).
|
|
81
|
+
expect(hook.current.remountKey).toBe(0);
|
|
79
82
|
hook.unmount();
|
|
80
83
|
});
|
|
81
84
|
|
|
82
|
-
it('
|
|
85
|
+
it('bumps the key once when the stream gains its first video track late', () => {
|
|
83
86
|
const stream = makeMediaStream(0);
|
|
84
87
|
const hook = renderHook({ mediaStream: stream });
|
|
85
|
-
expect(hook.current).toBe(0);
|
|
88
|
+
expect(hook.current.remountKey).toBe(0);
|
|
86
89
|
|
|
87
90
|
act(() => {
|
|
88
91
|
stream.addVideoTrack();
|
|
89
92
|
});
|
|
90
|
-
expect(hook.current).toBe(1);
|
|
93
|
+
expect(hook.current.remountKey).toBe(1);
|
|
91
94
|
hook.unmount();
|
|
92
95
|
});
|
|
93
96
|
|
|
@@ -96,7 +99,7 @@ describe('useLateTrackMediaStream', () => {
|
|
|
96
99
|
try {
|
|
97
100
|
const stream = makeMediaStream(0);
|
|
98
101
|
const hook = renderHook({ mediaStream: stream });
|
|
99
|
-
expect(hook.current).toBe(0);
|
|
102
|
+
expect(hook.current.remountKey).toBe(0);
|
|
100
103
|
|
|
101
104
|
// Simulate the first-share race: the track is added while the layout is
|
|
102
105
|
// not yet mounted, so no `addtrack` listener receives an event.
|
|
@@ -104,7 +107,57 @@ describe('useLateTrackMediaStream', () => {
|
|
|
104
107
|
act(() => {
|
|
105
108
|
jest.advanceTimersByTime(150);
|
|
106
109
|
});
|
|
107
|
-
expect(hook.current).toBe(1);
|
|
110
|
+
expect(hook.current.remountKey).toBe(1);
|
|
111
|
+
hook.unmount();
|
|
112
|
+
} finally {
|
|
113
|
+
jest.useRealTimers();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('emits a bounded burst of remounts after the first track appears', () => {
|
|
118
|
+
jest.useFakeTimers();
|
|
119
|
+
try {
|
|
120
|
+
const stream = makeMediaStream(0);
|
|
121
|
+
const hook = renderHook({ mediaStream: stream });
|
|
122
|
+
expect(hook.current.remountKey).toBe(0);
|
|
123
|
+
|
|
124
|
+
// The addtrack callback fires synchronously; wrap in act() so state
|
|
125
|
+
// updates are flushed.
|
|
126
|
+
act(() => {
|
|
127
|
+
stream.addVideoTrack();
|
|
128
|
+
});
|
|
129
|
+
// The first-track transition bumps the key once (key 1).
|
|
130
|
+
expect(hook.current.remountKey).toBe(1);
|
|
131
|
+
|
|
132
|
+
// Then a short burst of extra remounts at 300 ms intervals (keys 2..4)
|
|
133
|
+
// while the native stream settles.
|
|
134
|
+
act(() => {
|
|
135
|
+
jest.advanceTimersByTime(300 * 4);
|
|
136
|
+
});
|
|
137
|
+
expect(hook.current.remountKey).toBe(4);
|
|
138
|
+
|
|
139
|
+
// The burst is bounded: more time passes without further remounts.
|
|
140
|
+
act(() => {
|
|
141
|
+
jest.advanceTimersByTime(300 * 10);
|
|
142
|
+
});
|
|
143
|
+
expect(hook.current.remountKey).toBe(4);
|
|
144
|
+
hook.unmount();
|
|
145
|
+
} finally {
|
|
146
|
+
jest.useRealTimers();
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('does not emit the burst for a stream that already has its track', () => {
|
|
151
|
+
jest.useFakeTimers();
|
|
152
|
+
try {
|
|
153
|
+
const hook = renderHook({ mediaStream: makeMediaStream(1) });
|
|
154
|
+
expect(hook.current.remountKey).toBe(0);
|
|
155
|
+
|
|
156
|
+
// No 0 → 1 transition ever happens, so no remount burst should fire.
|
|
157
|
+
act(() => {
|
|
158
|
+
jest.advanceTimersByTime(300 * 20);
|
|
159
|
+
});
|
|
160
|
+
expect(hook.current.remountKey).toBe(0);
|
|
108
161
|
hook.unmount();
|
|
109
162
|
} finally {
|
|
110
163
|
jest.useRealTimers();
|
|
@@ -117,26 +170,62 @@ describe('useLateTrackMediaStream', () => {
|
|
|
117
170
|
const first = makeMediaStream(0);
|
|
118
171
|
const second = makeMediaStream(1);
|
|
119
172
|
const hook = renderHook({ mediaStream: first });
|
|
120
|
-
expect(hook.current).toBe(0);
|
|
173
|
+
expect(hook.current.remountKey).toBe(0);
|
|
121
174
|
|
|
122
175
|
act(() => {
|
|
123
176
|
first.addVideoTrack();
|
|
124
177
|
});
|
|
125
|
-
expect(hook.current).toBe(1);
|
|
178
|
+
expect(hook.current.remountKey).toBe(1);
|
|
126
179
|
|
|
127
180
|
hook.rerender({ mediaStream: second });
|
|
128
|
-
|
|
181
|
+
// Switching to a stream that already has its track resets the epoch: no
|
|
182
|
+
// spurious remount burst for the already-attached second share.
|
|
183
|
+
expect(hook.current.remountKey).toBe(0);
|
|
129
184
|
|
|
130
|
-
// The old stream no longer drives the
|
|
185
|
+
// The old stream no longer drives the key.
|
|
131
186
|
act(() => {
|
|
132
187
|
first.addVideoTrack();
|
|
133
188
|
});
|
|
134
|
-
|
|
189
|
+
// Still no remount: the swap cleared the listener and the burst, so the
|
|
190
|
+
// stale stream's late track cannot bump the key.
|
|
191
|
+
expect(hook.current.remountKey).toBe(0);
|
|
192
|
+
|
|
193
|
+
act(() => {
|
|
194
|
+
second.addVideoTrack();
|
|
195
|
+
});
|
|
196
|
+
// A stream that already has a track gaining another is not a
|
|
197
|
+
// first-track transition: no spurious remount (pins justGotFirst to the
|
|
198
|
+
// 0 → 1 edge, not a plain count > prev).
|
|
199
|
+
expect(hook.current.remountKey).toBe(0);
|
|
200
|
+
hook.unmount();
|
|
201
|
+
} finally {
|
|
202
|
+
jest.useRealTimers();
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('resets the key when swapping to a stream whose track has not arrived yet', () => {
|
|
207
|
+
jest.useFakeTimers();
|
|
208
|
+
try {
|
|
209
|
+
const first = makeMediaStream(0);
|
|
210
|
+
const hook = renderHook({ mediaStream: first });
|
|
211
|
+
|
|
212
|
+
act(() => {
|
|
213
|
+
first.addVideoTrack();
|
|
214
|
+
});
|
|
215
|
+
expect(hook.current.remountKey).toBe(1);
|
|
216
|
+
|
|
217
|
+
// Swap to a stream whose track has not arrived yet: the epoch must
|
|
218
|
+
// reset so the new share's burst starts from 1 instead of carrying the
|
|
219
|
+
// first stream's key forward (reset-before-refresh ordering).
|
|
220
|
+
const second = makeMediaStream(0);
|
|
221
|
+
hook.rerender({ mediaStream: second });
|
|
222
|
+
expect(hook.current.remountKey).toBe(0);
|
|
135
223
|
|
|
224
|
+
// The new stream gains its track: the burst starts at key 1.
|
|
136
225
|
act(() => {
|
|
137
226
|
second.addVideoTrack();
|
|
138
227
|
});
|
|
139
|
-
expect(hook.current).toBe(
|
|
228
|
+
expect(hook.current.remountKey).toBe(1);
|
|
140
229
|
hook.unmount();
|
|
141
230
|
} finally {
|
|
142
231
|
jest.useRealTimers();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import type { Track } from 'livekit-client';
|
|
3
3
|
import type { MediaStream } from '@livekit/react-native-webrtc';
|
|
4
4
|
|
|
@@ -7,16 +7,42 @@ import type { MediaStream } from '@livekit/react-native-webrtc';
|
|
|
7
7
|
const asWebRtcStream = (track?: Track): MediaStream | undefined =>
|
|
8
8
|
track?.mediaStream as MediaStream | undefined;
|
|
9
9
|
|
|
10
|
+
// A single remount is not enough for the first share of a call: the JS stream
|
|
11
|
+
// reports its video track (SDP apply) a beat before the native stream has the
|
|
12
|
+
// track registered (first frame / dynacast), so the native one-shot `streamURL`
|
|
13
|
+
// lookup that a single remount triggers can still run empty. A short, bounded
|
|
14
|
+
// burst of remounts after the first track appears gives the native attach a few
|
|
15
|
+
// chances to land once the stream is ready. Each extra remount is a cheap
|
|
16
|
+
// native view recreation, and the burst only happens on the rare late-share
|
|
17
|
+
// path — an already-attached share never sees one.
|
|
18
|
+
//
|
|
19
|
+
// The burst is bounded and self-clearing: `RETRY_BURST_ATTEMPTS = 4` ticks at
|
|
20
|
+
// `RETRY_BURST_INTERVAL_MS = 300`; the first three ticks bump (300/600/900 ms
|
|
21
|
+
// after the transition bump, ~1.2 s window), and the fourth (1200 ms) is
|
|
22
|
+
// consumed by the interval-clear branch — so exactly 3 extra remounts land.
|
|
23
|
+
const RETRY_BURST_ATTEMPTS = 4;
|
|
24
|
+
const RETRY_BURST_INTERVAL_MS = 300;
|
|
25
|
+
|
|
26
|
+
export interface LateTrackMediaStream {
|
|
27
|
+
/**
|
|
28
|
+
* Changes when the stream gains its first video track and again on a short
|
|
29
|
+
* burst of retries immediately after, so the native view re-runs its
|
|
30
|
+
* one-shot `streamURL` attach a few times while the native stream settles.
|
|
31
|
+
*/
|
|
32
|
+
remountKey: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
10
35
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
36
|
+
* Tracks the video-track count on a track's media stream and derives a
|
|
37
|
+
* remount key from it.
|
|
13
38
|
*
|
|
14
39
|
* A screen share that starts after we have joined is attached to the native
|
|
15
40
|
* `RTCView` by a one-time `streamURL` lookup of the stream's video track. When
|
|
16
41
|
* that lookup runs before the stream carries its video track, iOS gives up (no
|
|
17
42
|
* retry) and the tile stays black until we leave and rejoin. Re-keying the
|
|
18
|
-
* `VideoTrack` with
|
|
19
|
-
* its video track
|
|
43
|
+
* `VideoTrack` with `remountKey` remounts the native view when the stream gains
|
|
44
|
+
* its video track — and again a few times over the next second or so — so the
|
|
45
|
+
* one-shot lookup re-runs until it can succeed.
|
|
20
46
|
*
|
|
21
47
|
* The poll is not redundant with the `addtrack` listener: on the first share,
|
|
22
48
|
* `addtrack` fires inside the native SDP-apply batch, before the room re-emits
|
|
@@ -26,36 +52,72 @@ const asWebRtcStream = (track?: Track): MediaStream | undefined =>
|
|
|
26
52
|
* Camera tiles don't need this: they remount on the track object itself
|
|
27
53
|
* (see `JamCallParticipant`), which is a different (renegotiation) case.
|
|
28
54
|
*/
|
|
29
|
-
export const useLateTrackMediaStream = (
|
|
55
|
+
export const useLateTrackMediaStream = (
|
|
56
|
+
track?: Track
|
|
57
|
+
): LateTrackMediaStream => {
|
|
30
58
|
const mediaStream = asWebRtcStream(track);
|
|
31
|
-
const [
|
|
32
|
-
|
|
33
|
-
)
|
|
59
|
+
const [remountKey, setRemountKey] = useState(0);
|
|
60
|
+
// Previous video-track count on the current stream, so the 0 → 1 transition
|
|
61
|
+
// (first track arriving) is detected inside the effect.
|
|
62
|
+
const prevCountRef = useRef(0);
|
|
34
63
|
|
|
35
64
|
useEffect(() => {
|
|
36
65
|
if (!mediaStream) {
|
|
37
|
-
setVideoTrackCount(0);
|
|
38
66
|
return;
|
|
39
67
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
refresh
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
setRemountKey(0);
|
|
69
|
+
prevCountRef.current = mediaStream.getVideoTracks().length;
|
|
70
|
+
|
|
71
|
+
let pollTimer: ReturnType<typeof setInterval> | undefined;
|
|
72
|
+
let burstTimer: ReturnType<typeof setInterval> | undefined;
|
|
73
|
+
|
|
74
|
+
const startBurst = () => {
|
|
75
|
+
// The first track just appeared: the view re-mounts once for it (key
|
|
76
|
+
// bumped by `refresh`'s `justGotFirst` branch, immediately before this
|
|
77
|
+
// call), then nudge a few extra remounts while the native stream
|
|
78
|
+
// catches up (it registers the track on its first frame, which can
|
|
79
|
+
// lag the JS-side SDP apply).
|
|
80
|
+
let extra = 0;
|
|
81
|
+
burstTimer = setInterval(() => {
|
|
82
|
+
if (++extra >= RETRY_BURST_ATTEMPTS) {
|
|
83
|
+
clearInterval(burstTimer!);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
setRemountKey((key) => key + 1);
|
|
87
|
+
}, RETRY_BURST_INTERVAL_MS);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const refresh = () => {
|
|
91
|
+
const count = mediaStream.getVideoTracks().length;
|
|
92
|
+
const justGotFirst = count > 0 && prevCountRef.current === 0;
|
|
93
|
+
prevCountRef.current = count;
|
|
94
|
+
if (justGotFirst) {
|
|
95
|
+
setRemountKey((key) => key + 1);
|
|
96
|
+
startBurst();
|
|
97
|
+
if (pollTimer) clearInterval(pollTimer);
|
|
51
98
|
}
|
|
52
|
-
}
|
|
99
|
+
};
|
|
100
|
+
refresh();
|
|
101
|
+
if (prevCountRef.current === 0) {
|
|
102
|
+
// 20 x 150 ms (~3 s) covers the first-share negotiation window; stop as
|
|
103
|
+
// soon as the stream carries its track so an already-attached share
|
|
104
|
+
// causes no further remounts.
|
|
105
|
+
let attempts = 0;
|
|
106
|
+
pollTimer = setInterval(() => {
|
|
107
|
+
refresh();
|
|
108
|
+
if (mediaStream.getVideoTracks().length > 0 || ++attempts >= 20) {
|
|
109
|
+
clearInterval(pollTimer!);
|
|
110
|
+
}
|
|
111
|
+
}, 150);
|
|
112
|
+
}
|
|
53
113
|
mediaStream.addEventListener('addtrack', refresh);
|
|
54
114
|
return () => {
|
|
55
|
-
clearInterval(
|
|
115
|
+
if (pollTimer) clearInterval(pollTimer);
|
|
116
|
+
if (burstTimer) clearInterval(burstTimer);
|
|
56
117
|
mediaStream.removeEventListener('addtrack', refresh);
|
|
118
|
+
prevCountRef.current = 0;
|
|
57
119
|
};
|
|
58
120
|
}, [mediaStream]);
|
|
59
121
|
|
|
60
|
-
return
|
|
122
|
+
return { remountKey };
|
|
61
123
|
};
|
|
@@ -230,7 +230,9 @@ export const navigateToTarget = (target: NavTarget) => {
|
|
|
230
230
|
}
|
|
231
231
|
break;
|
|
232
232
|
default:
|
|
233
|
-
|
|
233
|
+
// Exhaustiveness guard (mirrors the web navigator's): adding a
|
|
234
|
+
// NavTarget without a native mapping fails the typecheck here.
|
|
235
|
+
throw target satisfies never;
|
|
234
236
|
}
|
|
235
237
|
};
|
|
236
238
|
|
|
@@ -241,10 +243,18 @@ export const useNativeRouterAdapter = (): RouterAdapter =>
|
|
|
241
243
|
searchParams: new URLSearchParams(),
|
|
242
244
|
// Native has no URL bar to keep in sync, so there is no query to write.
|
|
243
245
|
setSearchParams: () => {},
|
|
244
|
-
hrefOf: () =>
|
|
246
|
+
hrefOf: (target: NavTarget): string => {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`hrefOf('${target.type}') has no native mapping — native targets navigate directly (navigateToTarget), they have no hrefs.`
|
|
249
|
+
);
|
|
250
|
+
},
|
|
245
251
|
match: () => null,
|
|
246
252
|
navigate: (target) => {
|
|
247
|
-
if (typeof target === 'string')
|
|
253
|
+
if (typeof target === 'string') {
|
|
254
|
+
throw new Error(
|
|
255
|
+
'navigate(string) has no native mapping — pass a NavTarget so navigateToTarget can route it.'
|
|
256
|
+
);
|
|
257
|
+
}
|
|
248
258
|
navigateToTarget(target);
|
|
249
259
|
},
|
|
250
260
|
back: () => {
|