@simba-dev/react-native-media-player 1.5.15 → 1.5.18

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simba-dev/react-native-media-player",
3
- "version": "1.5.15",
3
+ "version": "1.5.18",
4
4
  "description": "React Native video/audio player powered by libmpv — Picture-in-Picture, MediaSession, custom RN UI. **V16.0.8 patch release** (2026-09-14) — D-033 16 KB page-size alignment: add_link_options(\"-Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384\") in CMakeLists.txt + ndkVersion r27+ so libsimbaplayer_mpv.so's LOAD segments are aligned to 16 KB (Android 14+ 16 KB page-size requirement). Without this, libsimbaplayer_mpv.so shows \"LOAD segment not aligned\" in the Android App Compatibility dialog and Android refuses to load it — which cascades to \"Unknown error\" for libmpv.so, libc++_shared.so, libav*.so (all transitively loaded via libsimbaplayer_mpv.so's NEEDED list), and the app boots to a white screen. v1.5.7 pre-load attempt was insufficient because the libs themselves weren't loading at all. See CHANGELOG.md for details.",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -93,6 +93,27 @@ function fail(msg, details) {
93
93
  process.exit(1);
94
94
  }
95
95
 
96
+ /**
97
+ * Returns an Authorization header value if a GitHub token is available
98
+ * in the environment, else undefined (unauthenticated request).
99
+ *
100
+ * Recognized env vars (in priority order):
101
+ * - GH_TOKEN (gh CLI convention; recommended)
102
+ * - GITHUB_TOKEN (Actions convention; same value, different name)
103
+ * - RNMP_GH_TOKEN (lib-specific override; useful when GH_TOKEN is set
104
+ * for the gh CLI but you want to use a different
105
+ * token for this lib — e.g. a per-org PAT).
106
+ *
107
+ * Authenticated requests raise the API rate limit from 60/hr to
108
+ * 5000/hr per token. The token is sent only to api.github.com /
109
+ * objects.githubusercontent.com — never to the asset CDN (S3) which
110
+ * doesn't need auth.
111
+ */
112
+ function githubAuthHeader() {
113
+ const token = process.env.GH_TOKEN || process.env.GITHUB_TOKEN || process.env.RNMP_GH_TOKEN;
114
+ return token ? { Authorization: `Bearer ${token}` } : undefined;
115
+ }
116
+
96
117
  // ---------------------------------------------------------------------------
97
118
  // Step 1: Resolve package version
98
119
  // ---------------------------------------------------------------------------
@@ -138,12 +159,16 @@ if (SKIP_DOWNLOAD) {
138
159
  /**
139
160
  * Performs an HTTPS GET, follows up to 5 redirects, and streams the
140
161
  * response body into the writable `dest` (file path or Writable stream).
162
+ * Optional `headers` (e.g. { Authorization: 'Bearer ...' }) are attached
163
+ * to the FIRST request only — redirects go to S3/fastly which doesn't
164
+ * accept the GitHub auth header anyway.
141
165
  * Resolves with { statusCode, headers } on success; rejects on network
142
166
  * error or non-2xx final status.
143
167
  */
144
- function httpsGetStream(url, dest, redirectsLeft = 5) {
168
+ function httpsGetStream(url, dest, options = {}, redirectsLeft = 5) {
169
+ const { headers = {}, extraRedirects = 0 } = options;
145
170
  return new Promise((resolve, reject) => {
146
- const req = https.get(url, (res) => {
171
+ const req = https.get(url, { headers }, (res) => {
147
172
  // Handle redirects — GitHub Releases redirect download URLs to
148
173
  // S3-backed object storage.
149
174
  if ([301, 302, 303, 307, 308].includes(res.statusCode)) {
@@ -151,7 +176,7 @@ function httpsGetStream(url, dest, redirectsLeft = 5) {
151
176
  const next = res.headers.location;
152
177
  if (!next) return reject(new Error(`Redirect from ${url} with no Location header`));
153
178
  if (redirectsLeft <= 0) return reject(new Error(`Too many redirects starting from ${url}`));
154
- return resolve(httpsGetStream(next, dest, redirectsLeft - 1));
179
+ return resolve(httpsGetStream(next, dest, { extraRedirects: extraRedirects + 1 }, redirectsLeft - 1));
155
180
  }
156
181
  if (res.statusCode !== 200) {
157
182
  res.resume();
@@ -169,26 +194,28 @@ function httpsGetStream(url, dest, redirectsLeft = 5) {
169
194
  });
170
195
  });
171
196
  req.on('error', reject);
172
- req.setTimeout(60_000, () => {
173
- req.destroy(new Error(`Request timed out after 60s: ${url}`));
197
+ req.setTimeout(120_000, () => {
198
+ req.destroy(new Error(`Request timed out after 120s: ${url}`));
174
199
  });
175
200
  });
176
201
  }
177
202
 
178
203
  /**
179
204
  * Performs an HTTPS GET and resolves with the response body as a string.
180
- * Used for small JSON / sha256 responses (GitHub API + companion .sha256
181
- * file). Rejects on non-2xx.
205
+ * Used for small JSON / sha256 responses. Rejects on non-2xx.
206
+ * Same redirect handling as httpsGetStream; `headers` apply to the first
207
+ * request only.
182
208
  */
183
- function httpsGetText(url, redirectsLeft = 5) {
209
+ function httpsGetText(url, options = {}, redirectsLeft = 5) {
210
+ const { headers = {}, extraRedirects = 0 } = options;
184
211
  return new Promise((resolve, reject) => {
185
- const req = https.get(url, (res) => {
212
+ const req = https.get(url, { headers }, (res) => {
186
213
  if ([301, 302, 303, 307, 308].includes(res.statusCode)) {
187
214
  res.resume();
188
215
  const next = res.headers.location;
189
216
  if (!next) return reject(new Error(`Redirect from ${url} with no Location header`));
190
217
  if (redirectsLeft <= 0) return reject(new Error(`Too many redirects starting from ${url}`));
191
- return resolve(httpsGetText(next, redirectsLeft - 1));
218
+ return resolve(httpsGetText(next, { extraRedirects: extraRedirects + 1 }, redirectsLeft - 1));
192
219
  }
193
220
  if (res.statusCode !== 200) {
194
221
  res.resume();
@@ -201,8 +228,8 @@ function httpsGetText(url, redirectsLeft = 5) {
201
228
  res.on('error', reject);
202
229
  });
203
230
  req.on('error', reject);
204
- req.setTimeout(30_000, () => {
205
- req.destroy(new Error(`Request timed out after 30s: ${url}`));
231
+ req.setTimeout(60_000, () => {
232
+ req.destroy(new Error(`Request timed out after 60s: ${url}`));
206
233
  });
207
234
  });
208
235
  }
@@ -212,65 +239,77 @@ function httpsGetText(url, redirectsLeft = 5) {
212
239
  // ---------------------------------------------------------------------------
213
240
 
214
241
  async function findRelease() {
215
- // GitHub's release-by-tag API: GET /repos/{owner}/{repo}/releases/tags/{tag}
242
+ // GitHub release assets follow a stable, predictable URL pattern:
243
+ // https://github.com/<owner>/<repo>/releases/download/<tag>/<asset>
244
+ //
245
+ // Constructing the URL directly (instead of looking it up via the
246
+ // GitHub Releases API) bypasses the API rate limit entirely — the
247
+ // asset CDN doesn't have the same 60/hr cap as api.github.com, and
248
+ // asset URLs are deterministic per (repo, tag, asset-name) triple.
249
+ //
250
+ // If the URL 404s, fall back to the API for a richer error message
251
+ // (so we can tell apart "release missing" vs "asset missing" vs
252
+ // "auth needed" instead of a generic 404).
253
+ const downloadUrl = `${RELEASE_BASE}/releases/download/${tag}/${ASSET_BASENAME}`;
254
+ debug(`Constructed asset URL: ${downloadUrl}`);
255
+ return downloadUrl;
256
+ }
257
+
258
+ /**
259
+ * Optional API-based diagnostic. Called only when the direct asset
260
+ * download 404s, to produce a more helpful error message (distinguish
261
+ * "release missing" from "asset missing" from "wrong repo").
262
+ */
263
+ async function diagnoseRelease404(downloadErr) {
216
264
  const apiUrl = `https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/tags/${tag}`;
217
- debug(`Looking up release via ${apiUrl}`);
218
- let body;
265
+ const authHeader = githubAuthHeader();
266
+ debug(`Diagnosing 404 via ${apiUrl} (auth=${authHeader ? 'yes' : 'no'})`);
219
267
  try {
220
- body = await httpsGetText(apiUrl);
221
- } catch (e) {
222
- // Improve the most common failure: 404 = release not found yet.
223
- if (/HTTP 404/.test(e.message)) {
268
+ const body = await httpsGetText(apiUrl, { headers: authHeader || {} });
269
+ const release = JSON.parse(body);
270
+ const assets = (release.assets || []).map((a) => a.name);
271
+ const assetList = assets.length ? assets.join(', ') : '(none)';
272
+ fail(
273
+ `GitHub release ${tag} exists but does NOT contain the expected asset "${ASSET_BASENAME}".\n` +
274
+ `Assets found in this release: ${assetList}\n\n` +
275
+ `Possible causes:\n` +
276
+ ` (a) The release was published before the postinstall pattern was added (pre-v1.5.14).\n` +
277
+ ` Upgrade to a version whose release has ${ASSET_BASENAME} + ${ASSET_BASENAME}${SHA_SUFFIX}.\n` +
278
+ ` (b) The release.yml workflow's upload step failed. Check the latest release run at\n` +
279
+ ` https://github.com/${REPO_OWNER}/${REPO_NAME}/actions/workflows/release.yml.\n` +
280
+ ` (c) You're consuming from a fork or mirror. Set RNMP_RELEASE_BASE.\n\n` +
281
+ `Underlying error: ${downloadErr}`
282
+ );
283
+ } catch (apiErr) {
284
+ if (/HTTP 404/.test(apiErr.message)) {
224
285
  fail(
225
- `GitHub release ${tag} does not exist yet.\n` +
226
- `This means the release was either never published, OR was published but the\n` +
227
- `tag/asset is on a different repo (fork, mirror). Check:\n` +
286
+ `GitHub release ${tag} does not exist on ${RELEASE_BASE}.\n` +
287
+ `This means the release was never published, OR was published but the tag is on\n` +
288
+ `a different repo (fork, mirror). Check:\n` +
228
289
  ` - ${RELEASE_BASE}/releases/tag/${tag}\n\n` +
229
290
  `If you're consuming from a fork or private mirror, set RNMP_RELEASE_BASE to\n` +
230
- `the base URL of your mirror (e.g. https://your-mirror.example.com/owner/repo).`
291
+ `the base URL of your mirror (e.g. https://your-mirror.example.com/owner/repo).\n\n` +
292
+ `Underlying error: ${downloadErr}`
231
293
  );
232
294
  }
233
- if (/HTTP 403/.test(e.message)) {
295
+ if (/HTTP 403/.test(apiErr.message)) {
234
296
  fail(
235
- `GitHub API returned 403 (rate limit or auth required) for ${apiUrl}.\n` +
236
- `Unauthenticated requests are limited to 60/hour per IP. If this is happening\n` +
237
- `during CI, either:\n` +
238
- ` - Wait a few minutes and retry.\n` +
239
- ` - Use an authenticated request via the GH_TOKEN env var (NOT implemented yet).\n` +
240
- ` - Pre-stage the binaries via a different mechanism (mount, cache, manual\n` +
241
- ` copy) and set SKIP_DOWNLOAD_NATIVE=1.\n\n` +
242
- `Underlying error: ${e.message}`
297
+ `Both the direct asset URL AND the GitHub API returned errors.\n` +
298
+ ` Asset URL error: ${downloadErr}\n` +
299
+ ` API error: ${apiErr.message}\n\n` +
300
+ `The API 403 is likely the 60/hr unauthenticated rate limit (api.github.com).\n` +
301
+ `Set GH_TOKEN (or GITHUB_TOKEN) to a personal access token to raise the limit\n` +
302
+ `to 5000/hr. Authenticated requests use the token ONLY against api.github.com —\n` +
303
+ `never against the asset CDN, which doesn't need auth.`
243
304
  );
244
305
  }
245
- throw e;
246
- }
247
- let release;
248
- try {
249
- release = JSON.parse(body);
250
- } catch (e) {
251
- fail(`Failed to parse GitHub API response for tag ${tag}. ` +
252
- `This usually means the response was an error page (e.g. rate limit). ` +
253
- `Response starts with: ${body.slice(0, 200)}`);
254
- }
255
- const assets = (release.assets || []).map((a) => a.name);
256
- debug(`Release ${tag} has ${assets.length} assets: ${assets.join(', ')}`);
257
- const expectedAsset = ASSET_BASENAME;
258
- if (!assets.includes(expectedAsset)) {
259
306
  fail(
260
- `GitHub release ${tag} does not contain the expected asset "${expectedAsset}".\n` +
261
- `Assets found: ${assets.length ? assets.join(', ') : '(none)'}\n\n` +
262
- `This usually means one of:\n` +
263
- ` (a) The release was published before the postinstall pattern was added (pre-v1.5.14).\n` +
264
- ` The fix is to upgrade to a version that has the postinstall + matching asset\n` +
265
- ` (check ${RELEASE_BASE}/releases/tag/${tag}).\n` +
266
- ` (b) The release.yml workflow's upload step failed silently. Check the latest release\n` +
267
- ` workflow run at https://github.com/${REPO_OWNER}/${REPO_NAME}/actions/workflows/release.yml.\n` +
268
- ` (c) You're installing from a fork or local checkout that doesn't have a GitHub Release\n` +
269
- ` for this version. Set RNMP_RELEASE_BASE to your fork's release URL.`
307
+ `Direct asset URL 404ed and the API diagnostic also failed:\n` +
308
+ ` Asset URL: ${downloadErr}\n` +
309
+ ` API: ${apiErr.message}\n\n` +
310
+ `Try setting GH_TOKEN / GITHUB_TOKEN to a personal access token, or wait and retry.`
270
311
  );
271
312
  }
272
- const asset = release.assets.find((a) => a.name === expectedAsset);
273
- return asset.browser_download_url;
274
313
  }
275
314
 
276
315
  // ---------------------------------------------------------------------------
@@ -286,16 +325,27 @@ async function downloadAndExtract() {
286
325
  const shaPath = path.join(tmpDir, ASSET_BASENAME + SHA_SUFFIX);
287
326
 
288
327
  try {
289
- // 1) Download the tarball
328
+ // 1) Download the tarball via the direct asset URL. The asset CDN
329
+ // (S3-backed) has much higher rate limits than api.github.com,
330
+ // so we avoid the API lookup for the common path.
290
331
  debug(`Downloading ${downloadUrl} -> ${tarPath}`);
291
- await httpsGetStream(downloadUrl, tarPath);
332
+ try {
333
+ await httpsGetStream(downloadUrl, tarPath);
334
+ } catch (e) {
335
+ // If the direct URL 404s, fall back to the API for a richer
336
+ // error message that distinguishes "release missing" vs
337
+ // "asset missing" vs "rate-limited".
338
+ if (/HTTP 404/.test(e.message)) {
339
+ await diagnoseRelease404(e.message);
340
+ }
341
+ throw e;
342
+ }
292
343
  const tarSize = fs.statSync(tarPath).size;
293
344
  log(`Downloaded ${(tarSize / 1024 / 1024).toFixed(1)} MB tarball.`);
294
345
 
295
346
  // 2) Download the companion .sha256 file from the same release.
296
347
  // GitHub's asset URLs are deterministic — we can swap the filename
297
- // in the URL. If that fails (e.g. CDN doesn't expose it), fall
298
- // back to the GitHub API's `digest` field on the asset object.
348
+ // in the URL. The asset CDN doesn't need auth.
299
349
  const shaUrl = downloadUrl.replace(/\/[^/]+$/, `/${ASSET_BASENAME}${SHA_SUFFIX}`);
300
350
  debug(`Downloading ${shaUrl} -> ${shaPath}`);
301
351
  let expectedSha;