@openpeepshq/rn-components 0.16.0 → 0.18.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/jams/JamChatDrawer.test.tsx +113 -41
- package/src/components/jams/JamChatDrawer.tsx +23 -20
- package/src/components/jams/JamFooter.toast.test.tsx +253 -0
- package/src/components/jams/JamFooter.tsx +66 -2
- package/src/components/jams/JamParticipantConference.tsx +4 -0
- 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/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
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression tests for the waiting-room join toast on the native surface.
|
|
3
|
+
*
|
|
4
|
+
* The shared hook (useJamFooterControls) fires `showToast` when someone joins;
|
|
5
|
+
* the only code that turns that into a user-visible toast lives here in the
|
|
6
|
+
* native footer — `useThemedToastConfig` (which must expose an `info` entry
|
|
7
|
+
* built from the theme palette, else a missing/wrong `type` would render an
|
|
8
|
+
* unstyled default toast or nothing) and `useFooterControls().showToast`
|
|
9
|
+
* (which must route to `Toast.show({ type: 'info', ... })`).
|
|
10
|
+
*
|
|
11
|
+
* Only react-native, livekit, i18n and the heavy footer siblings are stubbed.
|
|
12
|
+
* `useThemedToastConfig` runs against the real `mapColors` so the expected hex
|
|
13
|
+
* values are the ones the app actually ships. `useJamFooterControls` is stubbed
|
|
14
|
+
* to echo back the args object, so `useFooterControls()` returns the real
|
|
15
|
+
* `showToast` closure the footer built — exactly the code under test — without
|
|
16
|
+
* loading the hook's full React dependency graph.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const React = require('react');
|
|
20
|
+
const ReactTestRenderer = require('react-test-renderer');
|
|
21
|
+
|
|
22
|
+
const { mapColors } = require('../../theme/defaults');
|
|
23
|
+
|
|
24
|
+
const toastShowMock = jest.fn();
|
|
25
|
+
let mockIsDark = false;
|
|
26
|
+
|
|
27
|
+
const tMock = (key: string, opts?: Record<string, unknown>) =>
|
|
28
|
+
key.replace(/\{\{(\w+)\}\}/g, (_m: string, n: string) =>
|
|
29
|
+
String(opts?.[n] ?? '')
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
jest.mock('react-native', () => ({
|
|
33
|
+
View: (props: { style?: unknown; className?: string; children?: unknown }) =>
|
|
34
|
+
React.createElement(
|
|
35
|
+
'View',
|
|
36
|
+
{ style: props.style, className: props.className },
|
|
37
|
+
props.children
|
|
38
|
+
),
|
|
39
|
+
Text: (props: { children?: unknown }) =>
|
|
40
|
+
React.createElement('Text', null, props.children),
|
|
41
|
+
Pressable: (props: { children?: unknown }) =>
|
|
42
|
+
React.createElement('Pressable', null, props.children),
|
|
43
|
+
Alert: { alert: jest.fn() },
|
|
44
|
+
StyleSheet: { create: (s: unknown) => s },
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
jest.mock('react-native-toast-message', () => ({
|
|
48
|
+
__esModule: true,
|
|
49
|
+
default: { show: toastShowMock },
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
jest.mock('@livekit/react-native', () => ({
|
|
53
|
+
useRoomContext: () => ({}),
|
|
54
|
+
useParticipants: () => [],
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
jest.mock('react-i18next', () => ({
|
|
58
|
+
useTranslation: () => ({ t: tMock }),
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
62
|
+
// Echo back the args object so useFooterControls() returns the real
|
|
63
|
+
// showToast closure the footer built (the code under test).
|
|
64
|
+
useJamFooterControls: (args: unknown) => args,
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
jest.mock('../../theme/OpenPeepsThemeProvider', () => ({
|
|
68
|
+
useOpenPeepsTheme: () => ({
|
|
69
|
+
isDark: mockIsDark,
|
|
70
|
+
colors: mapColors(mockIsDark),
|
|
71
|
+
buttonRadius: '9999px',
|
|
72
|
+
refresh: () => {},
|
|
73
|
+
}),
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
jest.mock('../../theme/useThemeOpacity', () => ({
|
|
77
|
+
useThemeOpacity: () => ({ background: () => ({}) }),
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
jest.mock('./JamDeviceSelectors', () => ({
|
|
81
|
+
JamAudioOutputSelector: () => React.createElement('JamAudioOutputSelector'),
|
|
82
|
+
JamCameraSelector: () => React.createElement('JamCameraSelector'),
|
|
83
|
+
JamMicSelector: () => React.createElement('JamMicSelector'),
|
|
84
|
+
}));
|
|
85
|
+
jest.mock('./JamReactionMenu', () => ({
|
|
86
|
+
JamReactionMenu: () => React.createElement('JamReactionMenu'),
|
|
87
|
+
}));
|
|
88
|
+
jest.mock('./JamToolbarButton', () => ({
|
|
89
|
+
JamToolbarButton: ({ children }: { children?: unknown }) =>
|
|
90
|
+
React.createElement('JamToolbarButton', null, children),
|
|
91
|
+
toneIconClass: { default: '', active: '' },
|
|
92
|
+
}));
|
|
93
|
+
jest.mock('./LeaveCloseButton', () => ({
|
|
94
|
+
LeaveCloseButton: () => React.createElement('LeaveCloseButton'),
|
|
95
|
+
}));
|
|
96
|
+
jest.mock('../icons/index', () => ({
|
|
97
|
+
CircleEllipsisIcon: () => React.createElement('i'),
|
|
98
|
+
CircleStopIcon: () => React.createElement('i'),
|
|
99
|
+
DiscIcon: () => React.createElement('i'),
|
|
100
|
+
HandIcon: () => React.createElement('i'),
|
|
101
|
+
InfoIcon: () => React.createElement('i'),
|
|
102
|
+
LaughIcon: () => React.createElement('i'),
|
|
103
|
+
MessageSquareTextIcon: () => React.createElement('i'),
|
|
104
|
+
UsersRoundIcon: () => React.createElement('i'),
|
|
105
|
+
}));
|
|
106
|
+
jest.mock('../ui/themed-text', () => ({
|
|
107
|
+
ThemedText: (props: {
|
|
108
|
+
children?: unknown;
|
|
109
|
+
className?: string;
|
|
110
|
+
style?: unknown;
|
|
111
|
+
}) =>
|
|
112
|
+
React.createElement(
|
|
113
|
+
'ThemedText',
|
|
114
|
+
{
|
|
115
|
+
className: props.className,
|
|
116
|
+
style: props.style,
|
|
117
|
+
},
|
|
118
|
+
props.children
|
|
119
|
+
),
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
const { useThemedToastConfig, useFooterControls } = require('./JamFooter');
|
|
123
|
+
|
|
124
|
+
/** Capture the value a hook returns by rendering a component that calls it. */
|
|
125
|
+
const captureHook = <T,>(fn: () => T): T => {
|
|
126
|
+
let value!: T;
|
|
127
|
+
const Capture = () => {
|
|
128
|
+
value = fn();
|
|
129
|
+
return null;
|
|
130
|
+
};
|
|
131
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
132
|
+
ReactTestRenderer.act(() => {
|
|
133
|
+
tree = ReactTestRenderer.create(
|
|
134
|
+
React.createElement(Capture as () => unknown)
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
ReactTestRenderer.act(() => {
|
|
138
|
+
tree.unmount();
|
|
139
|
+
});
|
|
140
|
+
return value;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/** Render a toast-layout element and return its root View's props. */
|
|
144
|
+
const renderToastBody = (
|
|
145
|
+
layout: (p: { text1?: string }) => unknown,
|
|
146
|
+
text1: string
|
|
147
|
+
) => {
|
|
148
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
149
|
+
ReactTestRenderer.act(() => {
|
|
150
|
+
tree = ReactTestRenderer.create(React.createElement(layout, { text1 }));
|
|
151
|
+
});
|
|
152
|
+
// Read props while the tree is still mounted (instances go stale after
|
|
153
|
+
// unmount); do this outside the create-act, as the repo's existing
|
|
154
|
+
// react-test-renderer tests do.
|
|
155
|
+
const props = {
|
|
156
|
+
className: tree.root.findByType('View').props.className,
|
|
157
|
+
style: tree.root.findByType('View').props.style,
|
|
158
|
+
};
|
|
159
|
+
ReactTestRenderer.act(() => {
|
|
160
|
+
tree.unmount();
|
|
161
|
+
});
|
|
162
|
+
return props;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
describe('useThemedToastConfig', () => {
|
|
166
|
+
it('exposes an info entry built from the theme tokens (light)', () => {
|
|
167
|
+
mockIsDark = false;
|
|
168
|
+
const config = captureHook(useThemedToastConfig);
|
|
169
|
+
|
|
170
|
+
expect(config.info).toBeDefined();
|
|
171
|
+
// Missing `info` from the config is the regression this pins: without it
|
|
172
|
+
// `Toast.show({ type: 'info' })` would fall back to an unstyled default.
|
|
173
|
+
const props = renderToastBody(
|
|
174
|
+
config.info as (p: { text1?: string }) => unknown,
|
|
175
|
+
'1 person joined the waiting room'
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// Shipped light palette: info = card background + foreground text.
|
|
179
|
+
expect(props.style).toEqual([
|
|
180
|
+
expect.objectContaining({ borderWidth: 1 }),
|
|
181
|
+
{ backgroundColor: '#ffffff', borderColor: '#0a0a0b' },
|
|
182
|
+
]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('keeps success on the primary palette (distinct from info)', () => {
|
|
186
|
+
mockIsDark = false;
|
|
187
|
+
const config = captureHook(useThemedToastConfig);
|
|
188
|
+
|
|
189
|
+
const props = renderToastBody(
|
|
190
|
+
config.success as (p: { text1?: string }) => unknown,
|
|
191
|
+
'recording saved'
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// success = primary background + primary-foreground text (light).
|
|
195
|
+
expect(props.style).toEqual([
|
|
196
|
+
expect.objectContaining({ borderWidth: 1 }),
|
|
197
|
+
{ backgroundColor: '#16161a', borderColor: '#fafafa' },
|
|
198
|
+
]);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('adapts the info palette to the dark theme', () => {
|
|
202
|
+
mockIsDark = true;
|
|
203
|
+
const config = captureHook(useThemedToastConfig);
|
|
204
|
+
|
|
205
|
+
const props = renderToastBody(
|
|
206
|
+
config.info as (p: { text1?: string }) => unknown,
|
|
207
|
+
'someone joined'
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
// Shipped dark palette: card = #0a0a0f, foreground = #fafafa.
|
|
211
|
+
expect(props.style).toEqual([
|
|
212
|
+
expect.objectContaining({ borderWidth: 1 }),
|
|
213
|
+
{ backgroundColor: '#0a0a0f', borderColor: '#fafafa' },
|
|
214
|
+
]);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('keeps error on the destructive palette (distinct from info)', () => {
|
|
218
|
+
mockIsDark = false;
|
|
219
|
+
const config = captureHook(useThemedToastConfig);
|
|
220
|
+
|
|
221
|
+
const props = renderToastBody(
|
|
222
|
+
config.error as (p: { text1?: string }) => unknown,
|
|
223
|
+
'recording failed'
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
// error = destructive background + destructive-foreground text (light).
|
|
227
|
+
expect(props.style).toEqual([
|
|
228
|
+
expect.objectContaining({ borderWidth: 1 }),
|
|
229
|
+
{ backgroundColor: '#ef4444', borderColor: '#fafafa' },
|
|
230
|
+
]);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe('useFooterControls().showToast (native)', () => {
|
|
235
|
+
it('routes a waiting-room join to Toast.show with type info', () => {
|
|
236
|
+
mockIsDark = false;
|
|
237
|
+
const result: { showToast: (text1: string) => void } =
|
|
238
|
+
captureHook(useFooterControls);
|
|
239
|
+
|
|
240
|
+
expect(typeof result.showToast).toBe('function');
|
|
241
|
+
|
|
242
|
+
toastShowMock.mockClear();
|
|
243
|
+
ReactTestRenderer.act(() => {
|
|
244
|
+
result.showToast('2 people joined the waiting room');
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(toastShowMock).toHaveBeenCalledTimes(1);
|
|
248
|
+
expect(toastShowMock).toHaveBeenCalledWith({
|
|
249
|
+
type: 'info',
|
|
250
|
+
text1: '2 people joined the waiting room',
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
2
|
import { Alert, Pressable, View } from 'react-native';
|
|
3
3
|
import { useParticipants, useRoomContext } from '@livekit/react-native';
|
|
4
|
-
import Toast
|
|
4
|
+
import Toast, {
|
|
5
|
+
type ToastConfig,
|
|
6
|
+
type ToastConfigParams,
|
|
7
|
+
} from 'react-native-toast-message';
|
|
5
8
|
import { useTranslation } from 'react-i18next';
|
|
6
9
|
import { useJamFooterControls } from '@openpeepshq/react';
|
|
7
10
|
import {
|
|
@@ -15,6 +18,7 @@ import {
|
|
|
15
18
|
UsersRoundIcon,
|
|
16
19
|
} from '../icons/index';
|
|
17
20
|
import { ThemedText } from '../ui/themed-text';
|
|
21
|
+
import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
|
|
18
22
|
import {
|
|
19
23
|
JamAudioOutputSelector,
|
|
20
24
|
JamCameraSelector,
|
|
@@ -26,6 +30,58 @@ import { JamToolbarButton, toneIconClass } from './JamToolbarButton';
|
|
|
26
30
|
import { LeaveCloseButton } from './LeaveCloseButton';
|
|
27
31
|
import { useThemeOpacity } from '../../theme/useThemeOpacity';
|
|
28
32
|
|
|
33
|
+
/** Themed toast body; the library default colors sit off the app palette. */
|
|
34
|
+
const TOAST_BODY = {
|
|
35
|
+
borderWidth: 1,
|
|
36
|
+
borderRadius: 8,
|
|
37
|
+
paddingHorizontal: 16,
|
|
38
|
+
paddingVertical: 10,
|
|
39
|
+
maxWidth: '90%' as const,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const ThemedToast = ({
|
|
43
|
+
text1,
|
|
44
|
+
bg,
|
|
45
|
+
fg,
|
|
46
|
+
}: {
|
|
47
|
+
text1?: string;
|
|
48
|
+
bg: string;
|
|
49
|
+
fg: string;
|
|
50
|
+
}) => (
|
|
51
|
+
<View style={[TOAST_BODY, { backgroundColor: bg, borderColor: fg }]}>
|
|
52
|
+
<ThemedText style={{ color: fg }} className="text-sm font-medium">
|
|
53
|
+
{text1}
|
|
54
|
+
</ThemedText>
|
|
55
|
+
</View>
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
/** Toast layouts mapped to theme tokens (success, error/destructive, info/primary). */
|
|
59
|
+
export const useThemedToastConfig = (): ToastConfig => {
|
|
60
|
+
const { colors } = useOpenPeepsTheme();
|
|
61
|
+
return useMemo(
|
|
62
|
+
() => ({
|
|
63
|
+
success: ({ text1 }: ToastConfigParams<Record<string, never>>) => (
|
|
64
|
+
<ThemedToast
|
|
65
|
+
text1={text1}
|
|
66
|
+
bg={colors.primary}
|
|
67
|
+
fg={colors['primary-foreground']}
|
|
68
|
+
/>
|
|
69
|
+
),
|
|
70
|
+
error: ({ text1 }: ToastConfigParams<Record<string, never>>) => (
|
|
71
|
+
<ThemedToast
|
|
72
|
+
text1={text1}
|
|
73
|
+
bg={colors.destructive}
|
|
74
|
+
fg={colors['destructive-foreground']}
|
|
75
|
+
/>
|
|
76
|
+
),
|
|
77
|
+
info: ({ text1 }: ToastConfigParams<Record<string, never>>) => (
|
|
78
|
+
<ThemedToast text1={text1} bg={colors.card} fg={colors.foreground} />
|
|
79
|
+
),
|
|
80
|
+
}),
|
|
81
|
+
[colors]
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
29
85
|
export interface JamFooterProps {
|
|
30
86
|
chatOpen: boolean;
|
|
31
87
|
onToggleChat: () => void;
|
|
@@ -45,6 +101,13 @@ export const useFooterControls = () => {
|
|
|
45
101
|
const room = useRoomContext();
|
|
46
102
|
const participants = useParticipants();
|
|
47
103
|
|
|
104
|
+
// Stable identity: the footer controls hook lists showToast in an effect
|
|
105
|
+
// deps array, and an inline lambda would tear that effect down every render.
|
|
106
|
+
// Waiting-room joins are neutral info on native.
|
|
107
|
+
const showToast = useCallback((text1: string) => {
|
|
108
|
+
Toast.show({ type: 'info', text1 });
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
48
111
|
const confirmStopRecording = () =>
|
|
49
112
|
new Promise<boolean>((resolve) => {
|
|
50
113
|
Alert.alert('', t('jams.recording.stopConfirm'), [
|
|
@@ -67,6 +130,7 @@ export const useFooterControls = () => {
|
|
|
67
130
|
confirmStopRecording,
|
|
68
131
|
onSuccess: (text1) => Toast.show({ type: 'success', text1 }),
|
|
69
132
|
onError: (text1) => Toast.show({ type: 'error', text1 }),
|
|
133
|
+
showToast,
|
|
70
134
|
});
|
|
71
135
|
};
|
|
72
136
|
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useRoomContext,
|
|
8
8
|
useTracks,
|
|
9
9
|
} from '@livekit/react-native';
|
|
10
|
+
import Toast from 'react-native-toast-message';
|
|
10
11
|
import { Track } from 'livekit-client';
|
|
11
12
|
import { truncateText } from '@openpeepshq/common';
|
|
12
13
|
import {
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
JamsBannerStack,
|
|
30
31
|
} from './JamRoomIndicators';
|
|
31
32
|
import { JamVideoLayout } from './JamVideoLayout';
|
|
33
|
+
import { useThemedToastConfig } from './JamFooter';
|
|
32
34
|
|
|
33
35
|
type Drawer = 'chat' | 'people' | 'details' | null;
|
|
34
36
|
|
|
@@ -39,6 +41,7 @@ const JamParticipantConferenceInner = () => {
|
|
|
39
41
|
const [drawer, setDrawer] = useState<Drawer>(null);
|
|
40
42
|
const [settings, updateSettings] = useJamLocalSettings();
|
|
41
43
|
const remoteParticipants = useRemoteParticipants();
|
|
44
|
+
const toastConfig = useThemedToastConfig();
|
|
42
45
|
|
|
43
46
|
const tracks = useTracks(
|
|
44
47
|
[
|
|
@@ -100,6 +103,7 @@ const JamParticipantConferenceInner = () => {
|
|
|
100
103
|
<JamObserverBanner />
|
|
101
104
|
<JamRecordingIndicator />
|
|
102
105
|
</JamsBannerStack>
|
|
106
|
+
<Toast config={toastConfig} />
|
|
103
107
|
<View className="relative min-h-0 w-full flex-1 overflow-hidden p-2">
|
|
104
108
|
<View className="min-h-0 flex-1 overflow-hidden">
|
|
105
109
|
<View className="shrink-0 flex-row items-center">
|
|
@@ -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();
|