@simba-dev/react-native-media-player 2.0.1 → 2.1.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/README.md +317 -560
- package/android/src/main/cpp/main.cpp +117 -17
- package/android/src/main/java/com/simba/player/PipManager.kt +13 -0
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +177 -6
- package/android/src/main/java/com/simba/player/mpv/PipAutoEnterPolicy.kt +54 -0
- package/package.json +11 -2
- package/android/src/test/java/com/simba/player/PipActionReceiverTest.kt +0 -123
- package/android/src/test/java/com/simba/player/PipManagerTest.kt +0 -281
- package/android/src/test/java/com/simba/player/TestApplication.kt +0 -26
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleNullInstanceTest.kt +0 -117
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleTest.kt +0 -212
- package/android/src/test/java/com/simba/player/mpv/MpvRenderViewRegistryTest.kt +0 -120
- package/android/src/test/java/com/simba/player/mpv/MpvRenderViewTest.kt +0 -249
- package/scripts/override_react_methods.js +0 -184
- package/scripts/override_react_methods.py +0 -150
- package/src/bridge/__tests__/MpvPlayerModule.test.ts +0 -163
- package/src/bridge/__tests__/debugMode.test.ts +0 -138
- package/src/bridge/__tests__/errorContract.test.ts +0 -175
- package/src/bridge/__tests__/loadAndPlay.startPosition.test.tsx +0 -142
- package/src/components/__tests__/PlayerProvider.performance.test.tsx +0 -242
- package/src/components/__tests__/PlayerProvider.progressContext.test.tsx +0 -194
- package/src/components/__tests__/PlayerProvider.test.tsx +0 -558
- package/src/components/__tests__/PlayerRoot.test.tsx +0 -71
- package/src/components/__tests__/SimbaVideo.test.tsx +0 -164
- package/src/hooks/__tests__/resolveStreamType.test.ts +0 -159
- package/src/hooks/__tests__/useLaunchPlayback.test.tsx +0 -278
- package/src/hooks/__tests__/useResumeThumbnail.test.ts +0 -154
- package/src/stores/__tests__/playerQueueSelectionStore.test.ts +0 -73
- package/src/stores/__tests__/playerQueueStore.test.ts +0 -171
- package/src/types/__tests__/config.test.ts +0 -188
- package/src/types/__tests__/player.pipAnswer.test.tsx +0 -87
- package/src/types/__tests__/player.pipArity.test.tsx +0 -74
- package/src/types/__tests__/player.test.tsx +0 -1365
- package/src/types/__tests__/playerLoading.test.ts +0 -170
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Contract tests for `<SimbaVideo>`.
|
|
3
|
-
*
|
|
4
|
-
* These pin the promise the component makes to a consumer: it is an ordinary
|
|
5
|
-
* React Native view that React Native lays out, and every prop on it either
|
|
6
|
-
* reaches the native view or has a stated default.
|
|
7
|
-
*
|
|
8
|
-
* The native component is mocked as a host element ('SimbaVideoView') and
|
|
9
|
-
* located by testID. RNTL 14 has no `getByType` - only semantic queries - and
|
|
10
|
-
* a testID lookup that succeeds is itself the proof that matters: the view is
|
|
11
|
-
* reachable *through the React tree*. That is the whole regression this
|
|
12
|
-
* component exists to fix. The old picture was mounted by Kotlin at
|
|
13
|
-
* `android.R.id.content`, a sibling of the React root, so no React query could
|
|
14
|
-
* ever have found it.
|
|
15
|
-
*/
|
|
16
|
-
import React from 'react';
|
|
17
|
-
import { render, screen } from '@testing-library/react-native';
|
|
18
|
-
|
|
19
|
-
import { SimbaVideo, type SimbaVideoProps } from '../SimbaVideo';
|
|
20
|
-
|
|
21
|
-
jest.mock('../../specs/SimbaVideoViewNativeComponent', () => ({
|
|
22
|
-
__esModule: true,
|
|
23
|
-
default: 'SimbaVideoView',
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
const TEST_ID = 'native-video';
|
|
27
|
-
|
|
28
|
-
// `jest.setup.ts` already installs `getNativePtr: fn(() => 0)` on
|
|
29
|
-
// NativeModules.MpvPlayerModule.
|
|
30
|
-
const bridge = () =>
|
|
31
|
-
require('react-native').NativeModules.MpvPlayerModule as {
|
|
32
|
-
getNativePtr: jest.Mock;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/** Render and return the props that actually cross into the native view. */
|
|
36
|
-
async function renderNative(
|
|
37
|
-
props: Partial<SimbaVideoProps> = {},
|
|
38
|
-
): Promise<Record<string, unknown>> {
|
|
39
|
-
await render(<SimbaVideo testID={TEST_ID} {...props} />);
|
|
40
|
-
return screen.getByTestId(TEST_ID).props as Record<string, unknown>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
describe('SimbaVideo', () => {
|
|
44
|
-
beforeEach(() => {
|
|
45
|
-
jest.clearAllMocks();
|
|
46
|
-
bridge().getNativePtr.mockReturnValue(0);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('renders a real native view reachable through the React tree', async () => {
|
|
50
|
-
// If this test needs changing, the surface is no longer in the tree.
|
|
51
|
-
await render(<SimbaVideo testID={TEST_ID} />);
|
|
52
|
-
|
|
53
|
-
expect(screen.getByTestId(TEST_ID)).toBeTruthy();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('nativePtr', () => {
|
|
57
|
-
it('resolves the handle from the bridge when the prop is absent', async () => {
|
|
58
|
-
bridge().getNativePtr.mockReturnValue(4242);
|
|
59
|
-
|
|
60
|
-
const p = await renderNative();
|
|
61
|
-
|
|
62
|
-
expect(p.nativePtr).toBe(4242);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('prefers an explicit prop and does not consult the bridge', async () => {
|
|
66
|
-
// An app managing more than one engine passes its own handle. Silently
|
|
67
|
-
// preferring the singleton would bind the wrong engine with no error.
|
|
68
|
-
const p = await renderNative({ nativePtr: 99 });
|
|
69
|
-
|
|
70
|
-
expect(p.nativePtr).toBe(99);
|
|
71
|
-
expect(bridge().getNativePtr).not.toHaveBeenCalled();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('passes the handle through unrounded', async () => {
|
|
75
|
-
// mpv handles are 64-bit. An Int32 round-trip would hand mpv a pointer
|
|
76
|
-
// to nothing, and the symptom would be "video never appears" rather
|
|
77
|
-
// than a type error.
|
|
78
|
-
const big = 9007199254740991; // > Number.MAX_SAFE_INTEGER
|
|
79
|
-
const p = await renderNative({ nativePtr: big });
|
|
80
|
-
|
|
81
|
-
expect(p.nativePtr).toBe(big);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('resizeMode maps onto mpv video-zoom', () => {
|
|
86
|
-
it('contain is the default and maps to 0 (fit, letterboxed)', async () => {
|
|
87
|
-
expect((await renderNative()).resizeMode).toBe('0');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('contain → 0 when asked for explicitly', async () => {
|
|
91
|
-
expect((await renderNative({ resizeMode: 'contain' })).resizeMode).toBe('0');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('cover → 1 (fill, cropping, aspect preserved)', async () => {
|
|
95
|
-
expect((await renderNative({ resizeMode: 'cover' })).resizeMode).toBe('1');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('stretch → 2 (fill, aspect ignored)', async () => {
|
|
99
|
-
expect((await renderNative({ resizeMode: 'stretch' })).resizeMode).toBe('2');
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('falls back to fit for an unrecognised mode', async () => {
|
|
103
|
-
// mpv would reject an unknown video-zoom value; a wrong-but-valid
|
|
104
|
-
// letterbox is recoverable, a rejected property is not.
|
|
105
|
-
const p = await renderNative({ resizeMode: 'bogus' as never });
|
|
106
|
-
expect(p.resizeMode).toBe('0');
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe('defaults', () => {
|
|
111
|
-
it('applies stated defaults for every prop that reaches native', async () => {
|
|
112
|
-
// A native view defaulting to "unset" while Kotlin defaults to
|
|
113
|
-
// something else is how a prop ends up looking accepted while doing
|
|
114
|
-
// nothing.
|
|
115
|
-
const p = await renderNative();
|
|
116
|
-
|
|
117
|
-
expect(p.paused).toBe(false);
|
|
118
|
-
expect(p.muted).toBe(false);
|
|
119
|
-
expect(p.volume).toBe(100);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('honours explicit values over defaults', async () => {
|
|
123
|
-
const p = await renderNative({ paused: true, muted: true, volume: 35 });
|
|
124
|
-
|
|
125
|
-
expect(p.paused).toBe(true);
|
|
126
|
-
expect(p.muted).toBe(true);
|
|
127
|
-
expect(p.volume).toBe(35);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
describe('layout', () => {
|
|
132
|
-
it('carries a full-bleed default style', async () => {
|
|
133
|
-
// A caller who forgets a style must not get a zero-height surface.
|
|
134
|
-
// That renders no frames and reports no error anywhere - the exact
|
|
135
|
-
// failure this project keeps having to chase.
|
|
136
|
-
const style = (await renderNative()).style as Array<
|
|
137
|
-
Record<string, unknown>
|
|
138
|
-
>;
|
|
139
|
-
|
|
140
|
-
expect(style[0]).toMatchObject({
|
|
141
|
-
position: 'absolute',
|
|
142
|
-
top: 0,
|
|
143
|
-
left: 0,
|
|
144
|
-
right: 0,
|
|
145
|
-
bottom: 0,
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('lets the caller override the default style', async () => {
|
|
150
|
-
const style = (await renderNative({ style: { flex: 1 } }))
|
|
151
|
-
.style as Array<Record<string, unknown>>;
|
|
152
|
-
|
|
153
|
-
expect(style[1]).toEqual({ flex: 1 });
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('forwards unknown props through to the native view', async () => {
|
|
158
|
-
await render(
|
|
159
|
-
<SimbaVideo testID={TEST_ID} accessibilityLabel="Video" />,
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
expect(screen.getByTestId(TEST_ID).props.accessibilityLabel).toBe('Video');
|
|
163
|
-
});
|
|
164
|
-
});
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `resolveStreamType` decides which lane a launch opens, and therefore
|
|
3
|
-
* which PLAYER WINDOW opens — not just which badge renders.
|
|
4
|
-
*
|
|
5
|
-
* ## The defect this pins
|
|
6
|
-
*
|
|
7
|
-
* Two tabulation errors in the same switch:
|
|
8
|
-
*
|
|
9
|
-
* - `'episode'` sat in the video list. A podcast episode is an AUDIO
|
|
10
|
-
* lane in this app; the seam maps `bridgeOpts.type` straight to the
|
|
11
|
-
* lane, so a podcast episode opened the video window.
|
|
12
|
-
* - `'archive-video'` was absent entirely, so it fell through to the
|
|
13
|
-
* default and opened the AUDIO player.
|
|
14
|
-
*
|
|
15
|
-
* The second is the worse of the two, and the reason the fallback needs
|
|
16
|
-
* its own scrutiny: a RECOGNISED kind falling into the default is worse
|
|
17
|
-
* than an unrecognised one, because the default reads as a deliberate
|
|
18
|
-
* choice rather than a gap in a table.
|
|
19
|
-
*
|
|
20
|
-
* `MediaKind` in the consumer is the authority here; this table is a
|
|
21
|
-
* hand-maintained mirror of it and drifts silently when either side moves.
|
|
22
|
-
* These tests are what make the drift visible.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import {
|
|
26
|
-
resolveStreamType,
|
|
27
|
-
CONTENT_KIND_LANES,
|
|
28
|
-
type ContentKind,
|
|
29
|
-
} from '../useOpenWithResume';
|
|
30
|
-
|
|
31
|
-
/** Mirrors the consumer's `MediaKind` union. */
|
|
32
|
-
const CONSUMER_MEDIA_KINDS = [
|
|
33
|
-
'audio',
|
|
34
|
-
'music',
|
|
35
|
-
'podcast',
|
|
36
|
-
'audiobook',
|
|
37
|
-
'radio',
|
|
38
|
-
'video',
|
|
39
|
-
'movie',
|
|
40
|
-
'live-tv',
|
|
41
|
-
'archive-audio',
|
|
42
|
-
'archive-video',
|
|
43
|
-
] as const;
|
|
44
|
-
|
|
45
|
-
/** The kinds that must NOT open the video window. */
|
|
46
|
-
const AUDIO_LANES = [
|
|
47
|
-
'audio',
|
|
48
|
-
'music',
|
|
49
|
-
'podcast',
|
|
50
|
-
'audiobook',
|
|
51
|
-
'radio',
|
|
52
|
-
'episode',
|
|
53
|
-
'archive-audio',
|
|
54
|
-
] as const;
|
|
55
|
-
|
|
56
|
-
const VIDEO_LANES = [
|
|
57
|
-
'video',
|
|
58
|
-
'movie',
|
|
59
|
-
'live-tv',
|
|
60
|
-
'video-file',
|
|
61
|
-
'archive-video',
|
|
62
|
-
] as const;
|
|
63
|
-
|
|
64
|
-
describe('resolveStreamType', () => {
|
|
65
|
-
it.each(AUDIO_LANES)("routes '%s' to the audio lane", kind => {
|
|
66
|
-
expect(resolveStreamType(kind)).toBe('audio');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it.each(VIDEO_LANES)("routes '%s' to the video lane", kind => {
|
|
70
|
-
expect(resolveStreamType(kind)).toBe('video');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('treats a podcast episode as audio, not video', () => {
|
|
74
|
-
// The regression. 'episode' was in the video list.
|
|
75
|
-
expect(resolveStreamType('episode')).toBe('audio');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('routes archive-video to video rather than the audio default', () => {
|
|
79
|
-
// The worse regression: absent from the table entirely, so a known
|
|
80
|
-
// video kind opened the audio player.
|
|
81
|
-
expect(resolveStreamType('archive-video')).toBe('video');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('falls back to audio for an unrecognised kind', () => {
|
|
85
|
-
// Deliberately unchanged: an unknown file is genuinely more likely to
|
|
86
|
-
// be audio-only, and the audio player still plays it.
|
|
87
|
-
expect(resolveStreamType('something-unknown')).toBe('audio');
|
|
88
|
-
expect(resolveStreamType('')).toBe('audio');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('covers every MediaKind the consumer defines', () => {
|
|
92
|
-
// The mirror has to stay in step with the consumer's union. This is
|
|
93
|
-
// the assertion that fails when either side adds a kind.
|
|
94
|
-
const unclassified = CONSUMER_MEDIA_KINDS.filter(
|
|
95
|
-
kind =>
|
|
96
|
-
!AUDIO_LANES.includes(kind as never) && !VIDEO_LANES.includes(kind as never),
|
|
97
|
-
);
|
|
98
|
-
expect(unclassified).toEqual([]);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('never returns the input for a lane spelling (passthrough is not a branch)', () => {
|
|
102
|
-
// 'video' and 'audio' are in both the passthrough and the table; the
|
|
103
|
-
// table is now authoritative, so there is no way for the two to drift.
|
|
104
|
-
for (const kind of CONSUMER_MEDIA_KINDS) {
|
|
105
|
-
expect(['audio', 'video']).toContain(resolveStreamType(kind as ContentKind));
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* These assert the TABLE, not the return value.
|
|
112
|
-
*
|
|
113
|
-
* A return-value test cannot see a kind dropped from the table when the
|
|
114
|
-
* fallback happens to agree with the expected answer: remove 'episode'
|
|
115
|
-
* from the audio entries and `resolveStreamType('episode')` still returns
|
|
116
|
-
* 'audio' via the default. That mutation was actually run, and it passed
|
|
117
|
-
* a value-only suite — which is why the map is exported and these
|
|
118
|
-
* assertions exist.
|
|
119
|
-
*/
|
|
120
|
-
describe('CONTENT_KIND_LANES — the table itself', () => {
|
|
121
|
-
it("tabulates 'episode' as AUDIO explicitly", () => {
|
|
122
|
-
// Not merely "resolves to audio" — PRESENT in the table as audio.
|
|
123
|
-
expect(CONTENT_KIND_LANES.episode).toBe('audio');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("tabulates 'archive-video' as VIDEO explicitly", () => {
|
|
127
|
-
// Absent before: it took the audio default and opened the audio player.
|
|
128
|
-
expect(CONTENT_KIND_LANES['archive-video']).toBe('video');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('is not the "video list minus audio" accident it was', () => {
|
|
132
|
-
// Guards the specific regression shape: a kind present but in the
|
|
133
|
-
// wrong lane. Both of these are one character away from correct.
|
|
134
|
-
expect(CONTENT_KIND_LANES.episode).not.toBe('video');
|
|
135
|
-
expect(CONTENT_KIND_LANES['archive-audio']).toBe('audio');
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('covers every kind the lib claims to accept', () => {
|
|
139
|
-
const declared = [
|
|
140
|
-
...AUDIO_LANES,
|
|
141
|
-
...VIDEO_LANES,
|
|
142
|
-
];
|
|
143
|
-
const missing = declared.filter(kind => !(kind in CONTENT_KIND_LANES));
|
|
144
|
-
expect(missing).toEqual([]);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('assigns every table entry a real lane', () => {
|
|
148
|
-
for (const [kind, lane] of Object.entries(CONTENT_KIND_LANES)) {
|
|
149
|
-
expect(['audio', 'video']).toContain(lane);
|
|
150
|
-
expect(resolveStreamType(kind as ContentKind)).toBe(lane);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('is frozen so a consumer cannot mutate the shared table', () => {
|
|
155
|
-
// A writable export would let one consumer's fix corrupt every other
|
|
156
|
-
// consumer's routing.
|
|
157
|
-
expect(Object.isFrozen(CONTENT_KIND_LANES)).toBe(true);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for `useLaunchPlayback`.
|
|
3
|
-
*
|
|
4
|
-
* ## Why these exist
|
|
5
|
-
*
|
|
6
|
-
* Before 1.8.0, the load lifecycle lived inside `<PlayerRoot>`'s render
|
|
7
|
-
* body, so every re-render fired another `loadFile` — and
|
|
8
|
-
* `<PlayerProvider>` re-renders ~1 Hz off the position poll. The hook
|
|
9
|
-
* exists to guarantee a payload is loaded exactly once.
|
|
10
|
-
*
|
|
11
|
-
* ## What these pin
|
|
12
|
-
*
|
|
13
|
-
* - The payload is loaded EXACTLY ONCE per launch identity.
|
|
14
|
-
* - `startPositionMs` is authored in ms; mpv's `start` option is in
|
|
15
|
-
* seconds. A silent unit error here starts the file at the wrong place
|
|
16
|
-
* with no error anywhere.
|
|
17
|
-
* - A `null` payload is a no-op, not a `loadFile(null)`.
|
|
18
|
-
* - The title is applied BEFORE the load, because mpv reads
|
|
19
|
-
* `force-media-title` at load time.
|
|
20
|
-
*
|
|
21
|
-
* ## V21 F5
|
|
22
|
-
*
|
|
23
|
-
* This hook was one half of the two-Activity launch contract: the other
|
|
24
|
-
* half was a one-shot native queue (`getLaunchParams`) that only the
|
|
25
|
-
* deleted `PlayerActivity` ever filled. Both are gone, so this is now the
|
|
26
|
-
* public in-window launch primitive — a consumer passes the payload and
|
|
27
|
-
* the hook loads it into whatever surface it already has mounted.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
import React from 'react';
|
|
31
|
-
import { NativeModules, Text } from 'react-native';
|
|
32
|
-
import { render, waitFor } from '@testing-library/react-native';
|
|
33
|
-
import { useLaunchPlayback } from '../useLaunchPlayback';
|
|
34
|
-
import { PlayerProvider } from '../../components/PlayerProvider';
|
|
35
|
-
import type { LaunchParams } from '../../bridge/MpvPlayerModule';
|
|
36
|
-
|
|
37
|
-
const bridge = () =>
|
|
38
|
-
NativeModules.MpvPlayerModule as unknown as Record<string, jest.Mock>;
|
|
39
|
-
|
|
40
|
-
function clearBridgeMocks() {
|
|
41
|
-
for (const key of Object.keys(bridge())) {
|
|
42
|
-
const fn = bridge()[key];
|
|
43
|
-
if (typeof fn?.mockClear === 'function') fn.mockClear();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const PARAMS: LaunchParams = {
|
|
48
|
-
uri: 'https://example.test/movie.mp4',
|
|
49
|
-
title: 'Movie',
|
|
50
|
-
type: 'video',
|
|
51
|
-
startPositionMs: 0,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
describe('useLaunchPlayback', () => {
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
clearBridgeMocks();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
function Harness({params}: {params: LaunchParams | null}) {
|
|
60
|
-
useLaunchPlayback(params);
|
|
61
|
-
return <Text>harness</Text>;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
it('loads the URI and starts playback', async () => {
|
|
65
|
-
render(<Harness params={PARAMS} />);
|
|
66
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
67
|
-
expect(bridge().loadFile).toHaveBeenCalledWith(PARAMS.uri);
|
|
68
|
-
expect(bridge().play).toHaveBeenCalledTimes(1);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('does NOT re-fire when the payload object identity changes', async () => {
|
|
72
|
-
// The 1 Hz position poll re-renders consumers constantly. A
|
|
73
|
-
// fresh object literal for the same media must not reload.
|
|
74
|
-
// RNTL 14: `render` is async, so `rerender` must be awaited off
|
|
75
|
-
// the resolved value.
|
|
76
|
-
const {rerender} = await render(<Harness params={{...PARAMS}} />);
|
|
77
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
78
|
-
|
|
79
|
-
await rerender(<Harness params={{...PARAMS}} />);
|
|
80
|
-
await rerender(<Harness params={{...PARAMS}} />);
|
|
81
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('loads again when the URI actually changes', async () => {
|
|
85
|
-
const {rerender} = await render(<Harness params={PARAMS} />);
|
|
86
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
87
|
-
|
|
88
|
-
await rerender(
|
|
89
|
-
<Harness params={{...PARAMS, uri: 'https://example.test/next.mp4'}} />,
|
|
90
|
-
);
|
|
91
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(2));
|
|
92
|
-
expect(bridge().loadFile).toHaveBeenLastCalledWith(
|
|
93
|
-
'https://example.test/next.mp4',
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// ── requestId: re-launching the SAME media must load again ───────────
|
|
98
|
-
//
|
|
99
|
-
// `uri` + `startPositionMs` is not a unique identity for a launch. It was
|
|
100
|
-
// sound only because every launch used to start a fresh `PlayerActivity` —
|
|
101
|
-
// a new React root, so this hook mounted fresh and always fired.
|
|
102
|
-
//
|
|
103
|
-
// The moment playback is loaded into an already-open window, this hook
|
|
104
|
-
// stays mounted across launches and that guarantee disappears. The
|
|
105
|
-
// everyday action that breaks is "back out of a film, tap it again": same
|
|
106
|
-
// URI, resume policy hands back the same position, same key, no load, and
|
|
107
|
-
// the user presses play and nothing happens.
|
|
108
|
-
|
|
109
|
-
it('loads again for the SAME uri and position when requestId differs', async () => {
|
|
110
|
-
const {rerender} = await render(
|
|
111
|
-
<Harness params={{...PARAMS, requestId: 'session-1'}} />,
|
|
112
|
-
);
|
|
113
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
114
|
-
|
|
115
|
-
await rerender(<Harness params={{...PARAMS, requestId: 'session-2'}} />);
|
|
116
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(2));
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('does NOT re-fire when requestId is present but unchanged', async () => {
|
|
120
|
-
// The 1 Hz position poll still re-renders consumers constantly; a new
|
|
121
|
-
// object literal for the same launch must not reload.
|
|
122
|
-
const {rerender} = await render(
|
|
123
|
-
<Harness params={{...PARAMS, requestId: 'session-1'}} />,
|
|
124
|
-
);
|
|
125
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
126
|
-
|
|
127
|
-
await rerender(<Harness params={{...PARAMS, requestId: 'session-1'}} />);
|
|
128
|
-
await rerender(<Harness params={{...PARAMS, requestId: 'session-1'}} />);
|
|
129
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('converts startPositionMs from milliseconds to seconds for mpv\'s start option', async () => {
|
|
133
|
-
render(<Harness params={{...PARAMS, startPositionMs: 90_000}} />);
|
|
134
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
135
|
-
expect(bridge().setProperty).toHaveBeenCalledWith('options/start', '90.000');
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('never seeks at load time — mpv refuses a seek before the file is open', async () => {
|
|
139
|
-
// The defect this pins: `loadFile` + `seekAbsolute` in the same tick.
|
|
140
|
-
// mpv refuses the seek (playback is not initialised yet) and the
|
|
141
|
-
// refusal is silent, so the resume played from 0:00.
|
|
142
|
-
render(<Harness params={PARAMS} />);
|
|
143
|
-
await waitFor(() => expect(bridge().play).toHaveBeenCalledTimes(1));
|
|
144
|
-
expect(bridge().seekAbsolute).not.toHaveBeenCalled();
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('is a no-op for a null payload', async () => {
|
|
148
|
-
render(<Harness params={null} />);
|
|
149
|
-
await waitFor(() => expect(bridge().loadFile).not.toHaveBeenCalled());
|
|
150
|
-
expect(bridge().play).not.toHaveBeenCalled();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('is a no-op for an undefined payload', async () => {
|
|
154
|
-
render(<Harness params={undefined} />);
|
|
155
|
-
await waitFor(() => expect(bridge().loadFile).not.toHaveBeenCalled());
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// ── v1.9.3: the title the launch payload always carried ──────────────
|
|
159
|
-
//
|
|
160
|
-
// `LaunchParams.title` has always existed and has always come straight
|
|
161
|
-
// from the host app's `openPlayer({uri, title})`. This hook — the ONE
|
|
162
|
-
// place that actually loads the file — read `uri` and
|
|
163
|
-
// `startPositionMs` and discarded it. With `media-title` also unobserved,
|
|
164
|
-
// `PlayerState.title` stayed at the DEFAULT_STATE placeholder and every
|
|
165
|
-
// player header rendered the literal string "Simba Player".
|
|
166
|
-
//
|
|
167
|
-
// This is the path the app actually takes (`openPlayer` → activity →
|
|
168
|
-
// launch params → this hook), which is why it is the assertion that
|
|
169
|
-
// matters, not just the one on `commands.loadFile`.
|
|
170
|
-
|
|
171
|
-
it('applies the launch title as mpv force-media-title before loading', async () => {
|
|
172
|
-
render(<Harness params={{...PARAMS, title: 'Overrun!'}} />);
|
|
173
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
174
|
-
expect(bridge().setProperty).toHaveBeenCalledWith(
|
|
175
|
-
'force-media-title',
|
|
176
|
-
'Overrun!',
|
|
177
|
-
);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('sets the title BEFORE the load — mpv reads the option at load time', async () => {
|
|
181
|
-
const order: string[] = [];
|
|
182
|
-
bridge().setProperty.mockImplementation((name: string) => {
|
|
183
|
-
order.push(`setProperty:${name}`);
|
|
184
|
-
});
|
|
185
|
-
bridge().loadFile.mockImplementation(() => {
|
|
186
|
-
order.push('loadFile');
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
render(<Harness params={{...PARAMS, title: 'Overrun!'}} />);
|
|
190
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
191
|
-
expect(order).toEqual([
|
|
192
|
-
'setProperty:force-media-title',
|
|
193
|
-
'setProperty:options/start',
|
|
194
|
-
'loadFile',
|
|
195
|
-
]);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('trims the launch title', async () => {
|
|
199
|
-
render(<Harness params={{...PARAMS, title: ' Overrun! '}} />);
|
|
200
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
201
|
-
expect(bridge().setProperty).toHaveBeenCalledWith(
|
|
202
|
-
'force-media-title',
|
|
203
|
-
'Overrun!',
|
|
204
|
-
);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it('omits the option when the title is blank — mpv keeps deriving its own', async () => {
|
|
208
|
-
// Writing an empty `force-media-title` would BLANK the header, which
|
|
209
|
-
// is worse than the derived fallback it replaced.
|
|
210
|
-
render(<Harness params={{...PARAMS, title: ' '}} />);
|
|
211
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
212
|
-
expect(bridge().setProperty).not.toHaveBeenCalledWith(
|
|
213
|
-
'force-media-title',
|
|
214
|
-
expect.anything(),
|
|
215
|
-
);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('still loads the file when the title write is rejected', async () => {
|
|
219
|
-
// A rejected option must never cost the user their video.
|
|
220
|
-
bridge().setProperty.mockImplementationOnce(() => {
|
|
221
|
-
throw new Error('property rejected');
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
render(<Harness params={{...PARAMS, title: 'Overrun!'}} />);
|
|
225
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
226
|
-
expect(bridge().play).toHaveBeenCalledTimes(1);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
describe('in-window launch (V21 F5)', () => {
|
|
231
|
-
beforeEach(() => {
|
|
232
|
-
clearBridgeMocks();
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* The contract that replaced `<SimbaPlayerRoot headless>`.
|
|
237
|
-
*
|
|
238
|
-
* Video no longer starts an Activity, so a consumer drives the load
|
|
239
|
-
* from its own tree and keeps its own UI. This pins the two halves of
|
|
240
|
-
* the regression the `headless` flag used to guard: the module's own
|
|
241
|
-
* player UI must NOT take over the screen, and the payload must load
|
|
242
|
-
* exactly ONCE — two hook instances both firing would load the media
|
|
243
|
-
* twice per launch.
|
|
244
|
-
*/
|
|
245
|
-
function ConsumerChrome() {
|
|
246
|
-
useLaunchPlayback(PARAMS);
|
|
247
|
-
return <Text>consumer-chrome</Text>;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
it('loads the payload exactly once and keeps the consumer UI', async () => {
|
|
251
|
-
// RNTL 14: `render` returns a Promise, so its queries must be
|
|
252
|
-
// awaited off the resolved value — destructuring the Promise
|
|
253
|
-
// itself yields `undefined` for every query.
|
|
254
|
-
const {queryByText, getByText} = await render(
|
|
255
|
-
<PlayerProvider>
|
|
256
|
-
<ConsumerChrome />
|
|
257
|
-
</PlayerProvider>,
|
|
258
|
-
);
|
|
259
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
260
|
-
expect(bridge().loadFile).toHaveBeenCalledWith(PARAMS.uri);
|
|
261
|
-
expect(getByText('consumer-chrome')).toBeTruthy();
|
|
262
|
-
expect(queryByText('Simba Player')).toBeNull();
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it('never reads the deleted one-shot launch-params queue', async () => {
|
|
266
|
-
// V21 F5: `getLaunchParams` / `isCurrentActivityPlayer` no longer
|
|
267
|
-
// exist. A consumer that mounted the module's root no longer had a
|
|
268
|
-
// queue to consume, so it must not be consulted for anything.
|
|
269
|
-
await render(
|
|
270
|
-
<PlayerProvider>
|
|
271
|
-
<ConsumerChrome />
|
|
272
|
-
</PlayerProvider>,
|
|
273
|
-
);
|
|
274
|
-
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
275
|
-
expect(bridge().getLaunchParams).toBeUndefined();
|
|
276
|
-
expect(bridge().isCurrentActivityPlayer).toBeUndefined();
|
|
277
|
-
});
|
|
278
|
-
});
|