straight_to_video 0.0.6 → 0.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57371915cd38c1ecac814d16a43244275216661f31b639a80022685672984e22
4
- data.tar.gz: bb04ab7274edbb61031a270c8f650872b0b2338a7a1fc93a54948c8f3a3fcd04
3
+ metadata.gz: 7412c0ad6de37671f90aad3c474a2dfc2f846e656de524248791ec318ad598b7
4
+ data.tar.gz: 4032432057ff6b71831f3e509e4300f34a8f662c70b977923ec60edfce2d15ae
5
5
  SHA512:
6
- metadata.gz: 92b3e2d474ba435ac6679c26755a9d62bb5388cd3fbb984fc6b31506287b4ced1be3a7c3621efdaf1812a9feae7f60287caa9e91e3601731c60c0a450e4d8824
7
- data.tar.gz: 550b54b8fb004e7b6fea54282f00053fe47fd4bdefd20a5e87817c91495756adfe38c40d72888de883b0fbc049ad9615eb3f4f1783b05d01d92fc418356645cb
6
+ metadata.gz: 6c1d31ff446323e0304df7abfa4d02d7a52b883149a97f810753b55944447e5001a9ec810fa37525a8a0e5be7662c552df5c70d740d82b8ba367389c2d86d1ac
7
+ data.tar.gz: d8244161a7cd07734f24f7bf24037131db2c7ccaceb54e89330474edc575d00c32d82b24317ae24561e9bd42f1191b06d986c19ae770e829f81ef973598cc330
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.7
4
+
5
+ - guard against a race condition for forms that subscribe to change events but don't disable submission while optimize is already underway
6
+
3
7
  ## 0.0.6
4
8
 
5
9
  - fix iOS Safari Stimulus controller hang by making `seeked` waits robust
@@ -1,4 +1,4 @@
1
- // straight-to-video@0.0.6 vendored by the straight_to_video gem
1
+ // straight-to-video@0.0.7 vendored by the straight_to_video gem
2
2
  // straight-to-video - https://github.com/searlsco/straight-to-video
3
3
 
4
4
  // ----- External imports -----
@@ -233,7 +233,11 @@ async function encodeVideo ({ file, srcMeta, onProgress }) {
233
233
  v.addEventListener('loadedmetadata', onLoaded)
234
234
  v.addEventListener('error', onError)
235
235
  v.src = url
236
- try { v.load() } catch (_) {}
236
+ try {
237
+ v.load()
238
+ } catch (err) {
239
+ console.warn('straight-to-video: video.load() threw; continuing without explicit load()', err)
240
+ }
237
241
  })
238
242
  const canvas = document.createElement('canvas'); canvas.width = targetWidth; canvas.height = targetHeight
239
243
  const ctx = canvas.getContext('2d', { alpha: false })
@@ -244,9 +248,7 @@ async function encodeVideo ({ file, srcMeta, onProgress }) {
244
248
  const drawTime = i === 0
245
249
  ? Math.min(Math.max(0, t + (step * 0.5)), Math.max(0.000001, durationCfr - 0.000001))
246
250
  : targetTime
247
- if (i === 0) {}
248
251
  await seekOnce(v, drawTime)
249
- if (i === 0) {}
250
252
  const budgetMs = Math.min(34, Math.max(17, Math.round(step * 1000)))
251
253
  const presented = await waitForFrameReady(v, budgetMs)
252
254
  if (!presented && i === 0) {
@@ -261,7 +263,11 @@ async function encodeVideo ({ file, srcMeta, onProgress }) {
261
263
  vf.close()
262
264
 
263
265
  if (typeof onProgress === 'function') {
264
- try { onProgress(Math.min(1, (i + 1) / frames)) } catch (_) {}
266
+ try {
267
+ onProgress(Math.min(1, (i + 1) / frames))
268
+ } catch (err) {
269
+ console.warn('straight-to-video: onProgress callback threw; ignoring error', err)
270
+ }
265
271
  }
266
272
  }
267
273
  await ve.flush()
@@ -352,8 +358,11 @@ function registerStraightToVideoController (app, opts = {}) {
352
358
  }
353
359
 
354
360
  async _processFileInput (fileInput) {
355
- const ua = typeof navigator !== 'undefined' && navigator.userAgent ? navigator.userAgent : ''
356
- const isIos = /iP(hone|ad|od)/.test(ua)
361
+ if (!this._pendingProcesses) this._pendingProcesses = new WeakMap()
362
+ const existing = this._pendingProcesses.get(fileInput)
363
+ if (existing) return existing
364
+
365
+ const job = (async () => {
357
366
  this._markFlag(fileInput, 'processing')
358
367
  fileInput.disabled = true
359
368
  try {
@@ -372,6 +381,13 @@ function registerStraightToVideoController (app, opts = {}) {
372
381
  fileInput.disabled = false
373
382
  this._unmarkFlag(fileInput, 'processing')
374
383
  }
384
+ })()
385
+
386
+ this._pendingProcesses.set(fileInput, job)
387
+ job.finally(() => {
388
+ if (this._pendingProcesses?.get(fileInput) === job) this._pendingProcesses.delete(fileInput)
389
+ })
390
+ return job
375
391
  }
376
392
 
377
393
  _fire (el, name, detail = {}) {
data/index.html CHANGED
@@ -200,7 +200,14 @@
200
200
 
201
201
  // Single‑button flow: open picker then auto‑submit
202
202
  tryBtn.addEventListener('click', () => {
203
- if (fileEl.showPicker) { try { fileEl.showPicker(); return } catch (_) {} }
203
+ if (fileEl.showPicker) {
204
+ try {
205
+ fileEl.showPicker()
206
+ return
207
+ } catch (err) {
208
+ console.warn('straight-to-video demo: file input showPicker() failed; falling back to click()', err)
209
+ }
210
+ }
204
211
  fileEl.click()
205
212
  })
206
213
 
@@ -211,7 +218,11 @@
211
218
  sizes.classList.remove('hidden')
212
219
  p.classList.remove('hidden')
213
220
  pct && (pct.textContent = '0%')
214
- try { form.requestSubmit() } catch (_) {}
221
+ try {
222
+ form.requestSubmit()
223
+ } catch (err) {
224
+ console.warn('straight-to-video demo: form.requestSubmit() failed; user may need to submit manually', err)
225
+ }
215
226
  })
216
227
 
217
228
  // Mirror controller events into the UI
data/index.js CHANGED
@@ -232,7 +232,11 @@ async function encodeVideo ({ file, srcMeta, onProgress }) {
232
232
  v.addEventListener('loadedmetadata', onLoaded)
233
233
  v.addEventListener('error', onError)
234
234
  v.src = url
235
- try { v.load() } catch (_) {}
235
+ try {
236
+ v.load()
237
+ } catch (err) {
238
+ console.warn('straight-to-video: video.load() threw; continuing without explicit load()', err)
239
+ }
236
240
  })
237
241
  const canvas = document.createElement('canvas'); canvas.width = targetWidth; canvas.height = targetHeight
238
242
  const ctx = canvas.getContext('2d', { alpha: false })
@@ -243,9 +247,7 @@ async function encodeVideo ({ file, srcMeta, onProgress }) {
243
247
  const drawTime = i === 0
244
248
  ? Math.min(Math.max(0, t + (step * 0.5)), Math.max(0.000001, durationCfr - 0.000001))
245
249
  : targetTime
246
- if (i === 0) {}
247
250
  await seekOnce(v, drawTime)
248
- if (i === 0) {}
249
251
  const budgetMs = Math.min(34, Math.max(17, Math.round(step * 1000)))
250
252
  const presented = await waitForFrameReady(v, budgetMs)
251
253
  if (!presented && i === 0) {
@@ -260,7 +262,11 @@ async function encodeVideo ({ file, srcMeta, onProgress }) {
260
262
  vf.close()
261
263
 
262
264
  if (typeof onProgress === 'function') {
263
- try { onProgress(Math.min(1, (i + 1) / frames)) } catch (_) {}
265
+ try {
266
+ onProgress(Math.min(1, (i + 1) / frames))
267
+ } catch (err) {
268
+ console.warn('straight-to-video: onProgress callback threw; ignoring error', err)
269
+ }
264
270
  }
265
271
  }
266
272
  await ve.flush()
@@ -351,8 +357,11 @@ function registerStraightToVideoController (app, opts = {}) {
351
357
  }
352
358
 
353
359
  async _processFileInput (fileInput) {
354
- const ua = typeof navigator !== 'undefined' && navigator.userAgent ? navigator.userAgent : ''
355
- const isIos = /iP(hone|ad|od)/.test(ua)
360
+ if (!this._pendingProcesses) this._pendingProcesses = new WeakMap()
361
+ const existing = this._pendingProcesses.get(fileInput)
362
+ if (existing) return existing
363
+
364
+ const job = (async () => {
356
365
  this._markFlag(fileInput, 'processing')
357
366
  fileInput.disabled = true
358
367
  try {
@@ -371,6 +380,13 @@ function registerStraightToVideoController (app, opts = {}) {
371
380
  fileInput.disabled = false
372
381
  this._unmarkFlag(fileInput, 'processing')
373
382
  }
383
+ })()
384
+
385
+ this._pendingProcesses.set(fileInput, job)
386
+ job.finally(() => {
387
+ if (this._pendingProcesses?.get(fileInput) === job) this._pendingProcesses.delete(fileInput)
388
+ })
389
+ return job
374
390
  }
375
391
 
376
392
  _fire (el, name, detail = {}) {
@@ -1,3 +1,3 @@
1
1
  module StraightToVideo
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "straight-to-video",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "straight-to-video",
9
- "version": "0.0.6",
9
+ "version": "0.0.7",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "mediabunny": "^1.24.4"
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "straight-to-video",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Browser-based, hardware-accelerated video upload optimization",
5
5
  "type": "module",
6
6
  "exports": {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: straight_to_video
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls