@openpeepshq/rn-components 0.14.1 → 0.16.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/buttonOverflow.test.tsx +8 -0
- package/src/components/conversations/ConversationParticipantsModal.tsx +1 -6
- package/src/components/icons/index.ts +2 -0
- package/src/components/jams/JamChatDrawer.test.tsx +263 -0
- package/src/components/jams/JamChatDrawer.tsx +117 -52
- package/src/components/jams/JamConference.tsx +5 -0
- package/src/components/jams/JamParticipantConference.tsx +7 -4
- package/src/components/jams/JamPeopleDrawer.test.tsx +216 -0
- package/src/components/jams/JamPeopleDrawer.tsx +32 -2
- package/src/components/jams/JamRoomIndicators.test.tsx +190 -38
- package/src/components/jams/JamRoomIndicators.tsx +62 -20
- package/src/components/jams/useTrackSubscriptionBump.test.ts +294 -0
- package/src/components/jams/useTrackSubscriptionBump.ts +44 -0
- 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/feed/events/EventsCalendar.test.tsx +33 -18
- 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/ShareMenu.test.tsx +217 -0
- package/src/components/post/pieces/ShareMenu.tsx +107 -61
- 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/VisibilitySheet.test.tsx +153 -0
- package/src/components/post/post-form/VisibilitySheet.tsx +6 -5
- package/src/components/profile/Avatar.test.tsx +147 -0
- package/src/components/profile/Avatar.tsx +26 -0
- package/src/components/profile/ProfileCard.test.tsx +165 -8
- package/src/components/profile/ProfileCard.tsx +63 -10
- package/src/components/profile/ProfileSelector.test.tsx +147 -5
- package/src/components/profile/ProfileSelector.tsx +64 -18
- package/src/pages/Notifications.tsx +3 -1
- package/src/pages/Welcome.test.tsx +166 -0
- package/src/pages/Welcome.tsx +50 -4
- package/src/pages/conversations/New.test.tsx +340 -0
- package/src/pages/conversations/New.tsx +35 -30
- package/src/pages/events/Index.tsx +4 -1
- package/src/pages/events/My.tsx +1 -1
- package/src/pages/groups/Show.tsx +1 -1
- package/src/theme/useThemeOpacity.test.ts +70 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useState, type PropsWithChildren } from 'react';
|
|
2
2
|
import { Pressable, Text, View } from 'react-native';
|
|
3
3
|
import { useLocalParticipant } from '@livekit/react-native';
|
|
4
4
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
@@ -14,7 +14,9 @@ import { ThemedText } from '../ui/themed-text';
|
|
|
14
14
|
import { useThemeOpacity } from '../../theme/useThemeOpacity';
|
|
15
15
|
import { useConnectionQuality } from './useParticipantConnection';
|
|
16
16
|
|
|
17
|
-
/** Red "recording" pill shown to every participant while egress is active.
|
|
17
|
+
/** Red "recording" pill shown to every participant while egress is active.
|
|
18
|
+
* Rendered inside `JamsBannerStack` (the stack is already inset from the
|
|
19
|
+
* screen edges), so it stacks with the other jam banners. */
|
|
18
20
|
export const JamRecordingIndicator = () => {
|
|
19
21
|
const { t } = useTranslation();
|
|
20
22
|
const { background } = useThemeOpacity();
|
|
@@ -29,7 +31,7 @@ export const JamRecordingIndicator = () => {
|
|
|
29
31
|
<View
|
|
30
32
|
pointerEvents="none"
|
|
31
33
|
style={background('destructive', 0.9)}
|
|
32
|
-
className="
|
|
34
|
+
className="self-start ml-4 flex-row items-center gap-2 rounded-full px-3 py-1"
|
|
33
35
|
>
|
|
34
36
|
<CircleIcon
|
|
35
37
|
size={12}
|
|
@@ -44,37 +46,75 @@ export const JamRecordingIndicator = () => {
|
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* the
|
|
50
|
-
*
|
|
51
|
-
*
|
|
49
|
+
* Shared stacking container for the jam's transient overlays (network
|
|
50
|
+
* banner, observer banner, recording pill). Each child sits directly below
|
|
51
|
+
* the previous visible one, so they can never overlap each other and any
|
|
52
|
+
* future banner is added in a single place. The container owns the top
|
|
53
|
+
* offset (safe-area inset + 16px, matching the original `top-4` below the
|
|
54
|
+
* safe area), the vertical spacing and the horizontal insets (`left-4
|
|
55
|
+
* right-4`) — so, like the web twin's base top offset and spacing, the
|
|
56
|
+
* banners inside need no side margins of their own; the recording pill
|
|
57
|
+
* keeps its top-left placement via `self-start`.
|
|
52
58
|
*/
|
|
53
|
-
export const
|
|
59
|
+
export const JamsBannerStack = ({ children }: PropsWithChildren) => {
|
|
60
|
+
const insets = useSafeAreaInsets();
|
|
61
|
+
return (
|
|
62
|
+
<View
|
|
63
|
+
pointerEvents="box-none"
|
|
64
|
+
style={{ top: insets.top + 16 }}
|
|
65
|
+
className="absolute left-4 right-4 z-50 gap-2"
|
|
66
|
+
>
|
|
67
|
+
{children}
|
|
68
|
+
</View>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Dismissible banner shown to participants while hidden external sessions
|
|
74
|
+
* (observer links, recording/RTMP egress) are connected. Rendered inside
|
|
75
|
+
* `JamsBannerStack` (below the network banner). Toasts keep priority over
|
|
76
|
+
* the transparency signal, which is lower priority than user feedback. The
|
|
77
|
+
* Participants list keeps the presence visible after dismissal.
|
|
78
|
+
*/
|
|
79
|
+
export const JamObserverBanner = () => {
|
|
54
80
|
const { t } = useTranslation();
|
|
55
81
|
const { background } = useThemeOpacity();
|
|
56
|
-
const insets = useSafeAreaInsets();
|
|
57
82
|
const sessions = useJamExternalSessions();
|
|
83
|
+
const [dismissed, setDismissed] = useState(false);
|
|
58
84
|
|
|
59
|
-
|
|
85
|
+
// Dismissal is session-scoped: once acknowledged, it stays out of the way
|
|
86
|
+
// for the duration of the visit, and a new batch of sessions does not
|
|
87
|
+
// re-surface it.
|
|
88
|
+
if (sessions <= 0 || dismissed) return null;
|
|
60
89
|
|
|
61
90
|
// NativeWind v4 can't apply `/N` opacity to CSS-variable colors (e.g.
|
|
62
|
-
// `bg-
|
|
91
|
+
// `bg-surface-2/90`), so the banner background uses an inline rgba style.
|
|
63
92
|
return (
|
|
64
93
|
<View
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
className="z-50 flex-row items-center gap-2 rounded-full px-3 py-1"
|
|
94
|
+
style={background('surface-2', 0.9)}
|
|
95
|
+
className="flex-row items-center gap-2 rounded-lg border border-border px-4 py-2"
|
|
68
96
|
>
|
|
69
|
-
<EyeOnIcon size={16} className="text-
|
|
70
|
-
<ThemedText className="text-sm
|
|
71
|
-
{t('jams.observers.
|
|
97
|
+
<EyeOnIcon size={16} className="text-foreground" />
|
|
98
|
+
<ThemedText className="flex-1 text-sm text-foreground">
|
|
99
|
+
{t('jams.observers.connected', { count: sessions })}
|
|
72
100
|
</ThemedText>
|
|
101
|
+
<Pressable
|
|
102
|
+
accessibilityLabel={t('jams.observers.dismiss')}
|
|
103
|
+
accessibilityRole="button"
|
|
104
|
+
className="size-10 shrink-0 items-center justify-center"
|
|
105
|
+
onPress={() => setDismissed(true)}
|
|
106
|
+
>
|
|
107
|
+
<XIcon size={16} className="text-muted-foreground" />
|
|
108
|
+
</Pressable>
|
|
73
109
|
</View>
|
|
74
110
|
);
|
|
75
111
|
};
|
|
76
112
|
|
|
77
|
-
/**
|
|
113
|
+
/**
|
|
114
|
+
* Dismissable banner shown when the local connection quality degrades.
|
|
115
|
+
* Rendered inside `JamsBannerStack` so it stacks with the other jam banners
|
|
116
|
+
* instead of positioning itself.
|
|
117
|
+
*/
|
|
78
118
|
export const JamNetworkQuality = () => {
|
|
79
119
|
const { t } = useTranslation();
|
|
80
120
|
const { background } = useThemeOpacity();
|
|
@@ -92,7 +132,7 @@ export const JamNetworkQuality = () => {
|
|
|
92
132
|
// `bg-accent/90`), so the banner background uses an inline rgba style.
|
|
93
133
|
<View
|
|
94
134
|
style={background('accent', 0.9)}
|
|
95
|
-
className="
|
|
135
|
+
className="flex-row items-center gap-3 rounded-lg px-4 py-2"
|
|
96
136
|
>
|
|
97
137
|
<ThemedText className="flex-1 text-sm text-accent-foreground">
|
|
98
138
|
{/* Raw `Text` (not `ThemedText`) for the bold status label: nesting
|
|
@@ -104,6 +144,8 @@ export const JamNetworkQuality = () => {
|
|
|
104
144
|
</ThemedText>
|
|
105
145
|
<Pressable
|
|
106
146
|
accessibilityLabel={t('jams.network.dismiss')}
|
|
147
|
+
accessibilityRole="button"
|
|
148
|
+
className="size-10 shrink-0 items-center justify-center"
|
|
107
149
|
onPress={() => setDismissed(true)}
|
|
108
150
|
>
|
|
109
151
|
<XIcon size={16} className="text-accent-foreground" />
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useTrackSubscriptionBump: re-renders the caller when a remote video track
|
|
3
|
+
* is (un)subscribed, which lets a mid-Jam camera re-read `publication.track`
|
|
4
|
+
* instead of staying on the avatar/blank fallback until rejoin (#1808).
|
|
5
|
+
*
|
|
6
|
+
* Only the room surface is stubbed: a fake Room captures the listeners
|
|
7
|
+
* registered via `on` and removes them on `off`, the same way the real
|
|
8
|
+
* room's event emitter would. The hook runs as real code against the real
|
|
9
|
+
* `livekit-client` constants.
|
|
10
|
+
*
|
|
11
|
+
* The second describe block mounts the real `JamConference` (with the
|
|
12
|
+
* sibling components and the livekit/react-native surface stubbed) to pin
|
|
13
|
+
* the wiring: the bump is applied once in the shared parent, so both the
|
|
14
|
+
* participant and the observer `useTracks` consumers are covered.
|
|
15
|
+
*/
|
|
16
|
+
import React, { act } from 'react';
|
|
17
|
+
import TestRenderer from 'react-test-renderer';
|
|
18
|
+
import { RoomEvent, Track } from 'livekit-client';
|
|
19
|
+
import { useTrackSubscriptionBump } from './useTrackSubscriptionBump';
|
|
20
|
+
|
|
21
|
+
const makeRoom = () => {
|
|
22
|
+
const listeners = new Map<string, Array<(track: Track) => void>>();
|
|
23
|
+
return {
|
|
24
|
+
on(event: string, cb: (track: Track) => void) {
|
|
25
|
+
if (!listeners.has(event)) listeners.set(event, []);
|
|
26
|
+
listeners.get(event)!.push(cb);
|
|
27
|
+
return this;
|
|
28
|
+
},
|
|
29
|
+
off(event: string, cb: (track: Track) => void) {
|
|
30
|
+
listeners.set(
|
|
31
|
+
event,
|
|
32
|
+
(listeners.get(event) ?? []).filter((l) => l !== cb)
|
|
33
|
+
);
|
|
34
|
+
return this;
|
|
35
|
+
},
|
|
36
|
+
fire(event: string, track: Track) {
|
|
37
|
+
listeners.get(event)?.forEach((cb) => cb(track));
|
|
38
|
+
},
|
|
39
|
+
listenerCount(event: string) {
|
|
40
|
+
return listeners.get(event)?.length ?? 0;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type Room = ReturnType<typeof makeRoom>;
|
|
46
|
+
|
|
47
|
+
const videoTrack = { kind: Track.Kind.Video } as unknown as Track;
|
|
48
|
+
const audioTrack = { kind: Track.Kind.Audio } as unknown as Track;
|
|
49
|
+
|
|
50
|
+
const renderProbe = (initialRoom: Room) => {
|
|
51
|
+
let room = initialRoom;
|
|
52
|
+
let renders = 0;
|
|
53
|
+
const Probe = () => {
|
|
54
|
+
useTrackSubscriptionBump(
|
|
55
|
+
room as unknown as Parameters<typeof useTrackSubscriptionBump>[0]
|
|
56
|
+
);
|
|
57
|
+
renders += 1;
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
let renderer!: TestRenderer.ReactTestRenderer;
|
|
61
|
+
act(() => {
|
|
62
|
+
renderer = TestRenderer.create(React.createElement(Probe));
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
get renders() {
|
|
66
|
+
return renders;
|
|
67
|
+
},
|
|
68
|
+
rerender(nextRoom: Room) {
|
|
69
|
+
room = nextRoom;
|
|
70
|
+
act(() => {
|
|
71
|
+
renderer.update(React.createElement(Probe));
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
unmount() {
|
|
75
|
+
act(() => {
|
|
76
|
+
renderer.unmount();
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
describe('useTrackSubscriptionBump', () => {
|
|
83
|
+
it('re-renders on a remote video TrackSubscribed', () => {
|
|
84
|
+
const room = makeRoom();
|
|
85
|
+
const probe = renderProbe(room);
|
|
86
|
+
const initial = probe.renders;
|
|
87
|
+
|
|
88
|
+
act(() => {
|
|
89
|
+
room.fire(RoomEvent.TrackSubscribed, videoTrack);
|
|
90
|
+
});
|
|
91
|
+
expect(probe.renders).toBe(initial + 1);
|
|
92
|
+
probe.unmount();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('re-renders on a remote video TrackUnsubscribed', () => {
|
|
96
|
+
const room = makeRoom();
|
|
97
|
+
const probe = renderProbe(room);
|
|
98
|
+
const initial = probe.renders;
|
|
99
|
+
|
|
100
|
+
act(() => {
|
|
101
|
+
room.fire(RoomEvent.TrackUnsubscribed, videoTrack);
|
|
102
|
+
});
|
|
103
|
+
expect(probe.renders).toBe(initial + 1);
|
|
104
|
+
probe.unmount();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('coalesces a same-sid track swap (TrackUnsubscribed followed by TrackSubscribed) into exactly one re-render', () => {
|
|
108
|
+
const room = makeRoom();
|
|
109
|
+
const probe = renderProbe(room);
|
|
110
|
+
const initial = probe.renders;
|
|
111
|
+
|
|
112
|
+
// The order RemoteTrackPublication.setTrack emits on a same-sid swap:
|
|
113
|
+
// the old track unsubscribes, the new track subscribes, no status event.
|
|
114
|
+
act(() => {
|
|
115
|
+
room.fire(RoomEvent.TrackUnsubscribed, videoTrack);
|
|
116
|
+
room.fire(RoomEvent.TrackSubscribed, videoTrack);
|
|
117
|
+
});
|
|
118
|
+
// The coalesced pair must not double-bump per swap: exactly one
|
|
119
|
+
// re-render, so the tile neither double-remounts nor misses the swap.
|
|
120
|
+
expect(probe.renders).toBe(initial + 1);
|
|
121
|
+
|
|
122
|
+
// A second swap bumps again — the tile never sticks on the fallback.
|
|
123
|
+
act(() => {
|
|
124
|
+
room.fire(RoomEvent.TrackUnsubscribed, videoTrack);
|
|
125
|
+
room.fire(RoomEvent.TrackSubscribed, videoTrack);
|
|
126
|
+
});
|
|
127
|
+
expect(probe.renders).toBe(initial + 2);
|
|
128
|
+
probe.unmount();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('ignores audio tracks, so joins do not re-render the conference', () => {
|
|
132
|
+
const room = makeRoom();
|
|
133
|
+
const probe = renderProbe(room);
|
|
134
|
+
const initial = probe.renders;
|
|
135
|
+
|
|
136
|
+
act(() => {
|
|
137
|
+
room.fire(RoomEvent.TrackSubscribed, audioTrack);
|
|
138
|
+
room.fire(RoomEvent.TrackUnsubscribed, audioTrack);
|
|
139
|
+
});
|
|
140
|
+
expect(probe.renders).toBe(initial);
|
|
141
|
+
probe.unmount();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('removes both listeners on unmount', () => {
|
|
145
|
+
const room = makeRoom();
|
|
146
|
+
const probe = renderProbe(room);
|
|
147
|
+
expect(room.listenerCount(RoomEvent.TrackSubscribed)).toBe(1);
|
|
148
|
+
expect(room.listenerCount(RoomEvent.TrackUnsubscribed)).toBe(1);
|
|
149
|
+
|
|
150
|
+
probe.unmount();
|
|
151
|
+
expect(room.listenerCount(RoomEvent.TrackSubscribed)).toBe(0);
|
|
152
|
+
expect(room.listenerCount(RoomEvent.TrackUnsubscribed)).toBe(0);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('re-registers on the new room when the room instance changes', () => {
|
|
156
|
+
const first = makeRoom();
|
|
157
|
+
const second = makeRoom();
|
|
158
|
+
const probe = renderProbe(first);
|
|
159
|
+
|
|
160
|
+
probe.rerender(second);
|
|
161
|
+
expect(first.listenerCount(RoomEvent.TrackSubscribed)).toBe(0);
|
|
162
|
+
expect(first.listenerCount(RoomEvent.TrackUnsubscribed)).toBe(0);
|
|
163
|
+
expect(second.listenerCount(RoomEvent.TrackSubscribed)).toBe(1);
|
|
164
|
+
expect(second.listenerCount(RoomEvent.TrackUnsubscribed)).toBe(1);
|
|
165
|
+
|
|
166
|
+
// Only the current room drives re-renders.
|
|
167
|
+
const initial = probe.renders;
|
|
168
|
+
act(() => {
|
|
169
|
+
first.fire(RoomEvent.TrackSubscribed, videoTrack);
|
|
170
|
+
});
|
|
171
|
+
expect(probe.renders).toBe(initial);
|
|
172
|
+
|
|
173
|
+
act(() => {
|
|
174
|
+
second.fire(RoomEvent.TrackSubscribed, videoTrack);
|
|
175
|
+
});
|
|
176
|
+
expect(probe.renders).toBe(initial + 1);
|
|
177
|
+
probe.unmount();
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
// JamConference wiring: the bump is applied once in the shared parent, so
|
|
183
|
+
// both the participant and the observer useTracks consumers are covered
|
|
184
|
+
// (#1808). Sibling components and the livekit/react-native surface are
|
|
185
|
+
// stubbed; the real JamConference + useTrackSubscriptionBump run against the
|
|
186
|
+
// real livekit-client constants.
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
let mockIsObserver = false;
|
|
190
|
+
let mockConferenceRoom!: ReturnType<typeof makeRoom>;
|
|
191
|
+
let mockParticipantRenders = 0;
|
|
192
|
+
let mockVideoLayoutRenders = 0;
|
|
193
|
+
|
|
194
|
+
jest.mock('react-native', () => {
|
|
195
|
+
const passthrough = (name: string) => (props: { children?: unknown }) =>
|
|
196
|
+
require('react').createElement(name, null, props.children);
|
|
197
|
+
return {
|
|
198
|
+
View: passthrough('View'),
|
|
199
|
+
Pressable: passthrough('Pressable'),
|
|
200
|
+
ScrollView: passthrough('ScrollView'),
|
|
201
|
+
StyleSheet: { absoluteFill: {} },
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
jest.mock('@livekit/react-native', () => ({
|
|
206
|
+
isTrackReference: (track: unknown) =>
|
|
207
|
+
!!track && (track as { publication?: unknown }).publication !== undefined,
|
|
208
|
+
useRoomContext: () => mockConferenceRoom,
|
|
209
|
+
useTracks: () => [],
|
|
210
|
+
}));
|
|
211
|
+
|
|
212
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
213
|
+
JamEventsProvider: ({ children }: { children: unknown }) =>
|
|
214
|
+
require('react').createElement('JamEventsProvider', null, children),
|
|
215
|
+
useDropLateAudio: () => undefined,
|
|
216
|
+
useJamObserver: () => mockIsObserver,
|
|
217
|
+
}));
|
|
218
|
+
|
|
219
|
+
jest.mock('./JamParticipantConference', () => ({
|
|
220
|
+
JamParticipantConference: () => {
|
|
221
|
+
mockParticipantRenders += 1;
|
|
222
|
+
return null;
|
|
223
|
+
},
|
|
224
|
+
}));
|
|
225
|
+
|
|
226
|
+
jest.mock('./JamObserverShell', () => ({
|
|
227
|
+
JamObserverShell: ({ children }: { children: unknown }) =>
|
|
228
|
+
require('react').createElement('JamObserverShell', null, children),
|
|
229
|
+
}));
|
|
230
|
+
|
|
231
|
+
jest.mock('./JamVideoLayout', () => ({
|
|
232
|
+
JamVideoLayout: () => {
|
|
233
|
+
mockVideoLayoutRenders += 1;
|
|
234
|
+
return null;
|
|
235
|
+
},
|
|
236
|
+
}));
|
|
237
|
+
|
|
238
|
+
const { JamConference } = require('./JamConference');
|
|
239
|
+
|
|
240
|
+
const renderConference = (
|
|
241
|
+
isObserver: boolean,
|
|
242
|
+
room: ReturnType<typeof makeRoom>
|
|
243
|
+
) => {
|
|
244
|
+
mockIsObserver = isObserver;
|
|
245
|
+
mockConferenceRoom = room;
|
|
246
|
+
let renderer!: TestRenderer.ReactTestRenderer;
|
|
247
|
+
act(() => {
|
|
248
|
+
renderer = TestRenderer.create(React.createElement(JamConference));
|
|
249
|
+
});
|
|
250
|
+
return {
|
|
251
|
+
unmount() {
|
|
252
|
+
act(() => {
|
|
253
|
+
renderer.unmount();
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
describe('JamConference wiring', () => {
|
|
260
|
+
it('registers the track-swap bump once for an observer (observer path)', () => {
|
|
261
|
+
const room = makeRoom();
|
|
262
|
+
const conference = renderConference(true, room);
|
|
263
|
+
// One listener pair, from the shared JamConference parent — the observer
|
|
264
|
+
// useTracks consumer is covered without a second registration.
|
|
265
|
+
expect(room.listenerCount(RoomEvent.TrackSubscribed)).toBe(1);
|
|
266
|
+
expect(room.listenerCount(RoomEvent.TrackUnsubscribed)).toBe(1);
|
|
267
|
+
|
|
268
|
+
const before = mockVideoLayoutRenders;
|
|
269
|
+
act(() => {
|
|
270
|
+
room.fire(RoomEvent.TrackSubscribed, videoTrack);
|
|
271
|
+
});
|
|
272
|
+
expect(mockVideoLayoutRenders).toBe(before + 1);
|
|
273
|
+
|
|
274
|
+
conference.unmount();
|
|
275
|
+
expect(room.listenerCount(RoomEvent.TrackSubscribed)).toBe(0);
|
|
276
|
+
expect(room.listenerCount(RoomEvent.TrackUnsubscribed)).toBe(0);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('registers the track-swap bump once for a participant (participant path)', () => {
|
|
280
|
+
const room = makeRoom();
|
|
281
|
+
const conference = renderConference(false, room);
|
|
282
|
+
expect(room.listenerCount(RoomEvent.TrackSubscribed)).toBe(1);
|
|
283
|
+
expect(room.listenerCount(RoomEvent.TrackUnsubscribed)).toBe(1);
|
|
284
|
+
|
|
285
|
+
const before = mockParticipantRenders;
|
|
286
|
+
act(() => {
|
|
287
|
+
room.fire(RoomEvent.TrackSubscribed, videoTrack);
|
|
288
|
+
});
|
|
289
|
+
expect(mockParticipantRenders).toBe(before + 1);
|
|
290
|
+
|
|
291
|
+
conference.unmount();
|
|
292
|
+
expect(room.listenerCount(RoomEvent.TrackSubscribed)).toBe(0);
|
|
293
|
+
});
|
|
294
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useEffect, useReducer } from 'react';
|
|
2
|
+
import { RoomEvent, Track, type Room } from 'livekit-client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Re-renders the caller each time a remote video track is (un)subscribed, so
|
|
6
|
+
* tiles re-read the mutated `publication.track` and the #1903 track-epoch
|
|
7
|
+
* remount re-attaches the stream to the native RTCView (#1808).
|
|
8
|
+
*
|
|
9
|
+
* `useTracks`'s `trackReferencesObservable` already re-emits for most
|
|
10
|
+
* transitions (`TrackPublished/Unpublished`, `TrackMuted/Unmuted`,
|
|
11
|
+
* `TrackSubscriptionStatusChanged`, participant connect/disconnect), which
|
|
12
|
+
* covers a first mid-Jam camera publish and an off→on republish (the
|
|
13
|
+
* placeholder→reference swap fires `TrackPublished`; the
|
|
14
|
+
* Desired→Subscribed attach fires `TrackSubscriptionStatusChanged`). The one
|
|
15
|
+
* swap it misses is a track object replaced under the *same* `trackSid` while
|
|
16
|
+
* the subscription status stays `Subscribed` (publisher-side restart /
|
|
17
|
+
* device switch): `RemoteTrackPublication.setTrack` emits
|
|
18
|
+
* `TrackEvent.Subscribed`/`Unsubscribed` (room `TrackSubscribed` /
|
|
19
|
+
* `TrackUnsubscribed`) in that case, but no status event. This bump is the
|
|
20
|
+
* re-render that lets the tiles react to that gap.
|
|
21
|
+
*
|
|
22
|
+
* Audio tracks are ignored: neither `useTracks` call selects them, so no
|
|
23
|
+
* derived tile output depends on their subscriptions. (Screen share needs no
|
|
24
|
+
* bump either — it is video, so a screen-share `TrackSubscribed` is handled
|
|
25
|
+
* by the same listener.) Ignoring audio also keeps a join from re-rendering
|
|
26
|
+
* the whole conference.
|
|
27
|
+
*/
|
|
28
|
+
export const useTrackSubscriptionBump = (room: Room) => {
|
|
29
|
+
const [, bump] = useReducer((count: number) => count + 1, 0);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const onSubscriptionChanged = (track: Track) => {
|
|
32
|
+
if (track.kind !== Track.Kind.Video) return;
|
|
33
|
+
bump();
|
|
34
|
+
};
|
|
35
|
+
room
|
|
36
|
+
.on(RoomEvent.TrackSubscribed, onSubscriptionChanged)
|
|
37
|
+
.on(RoomEvent.TrackUnsubscribed, onSubscriptionChanged);
|
|
38
|
+
return () => {
|
|
39
|
+
room
|
|
40
|
+
.off(RoomEvent.TrackSubscribed, onSubscriptionChanged)
|
|
41
|
+
.off(RoomEvent.TrackUnsubscribed, onSubscriptionChanged);
|
|
42
|
+
};
|
|
43
|
+
}, [room]);
|
|
44
|
+
};
|
|
@@ -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: () => {
|