@aochuang/common 1.0.142 → 1.0.144

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.
@@ -65,7 +65,7 @@ export default class VoicePlayerAAC {
65
65
  this._timer = setInterval(() => {
66
66
  if (!this._play) return
67
67
  const currPosition = this.$audio.currentTime
68
- this.options.onPlaying?.({
68
+ this.options.onPlaying && this.options.onPlaying({
69
69
  currPosition,
70
70
  totalPosition
71
71
  })
@@ -76,7 +76,7 @@ export default class VoicePlayerAAC {
76
76
  }, 100)
77
77
  }
78
78
  this.$audio.onplay = () => {
79
- this.options.onPlay?.()
79
+ this.options.onPlay && this.options.onPlay()
80
80
  }
81
81
 
82
82
  this.$audio.onended = () => {
@@ -91,11 +91,11 @@ export default class VoicePlayerAAC {
91
91
 
92
92
  this.$audio.addEventListener('stop', () => {
93
93
  clearInterval(this._timer)
94
- this.options.onEnded?.()
94
+ this.options.onEnded && this.options.onEnded()
95
95
  })
96
96
 
97
97
  this.$audio.addEventListener('error', () => {
98
- this.options.onError?.({
98
+ this.options.onError && this.options.onError({
99
99
  type: 'aac',
100
100
  url: this._url,
101
101
  message: this.$audio.error || '未知音频错误'
@@ -146,7 +146,7 @@ export default class VoicePlayerAAC {
146
146
  if (!url) {
147
147
  this.stop()
148
148
  }
149
- cb?.({ status: 'success' })
149
+ cb && cb({ status: 'success' })
150
150
  }
151
151
 
152
152
  start() {
@@ -193,7 +193,7 @@ export default class VoicePlayerAAC {
193
193
  this.$audio.addEventListener('playing', () => this.isPlaying = true)
194
194
  this.$audio.addEventListener('pause', () => this.isPlaying = false)
195
195
  this.mediaSource.addEventListener('sourceerror', (e) => {
196
- this.options.onError?.({ type: 'mse', url: this._url, message: e })
196
+ this.options.onError && this.options.onError({ type: 'mse', url: this._url, message: e })
197
197
  })
198
198
  this.mediaSource.addEventListener('sourceopen', async () => {
199
199
  if (!this._play) return
@@ -230,7 +230,7 @@ export default class VoicePlayerAAC {
230
230
  if (bufferStart < cleanEnd && cleanEnd <= bufferEnd) {
231
231
  try {
232
232
  await this.safeRemoveBuffer(this.sourceBuffer, bufferStart, cleanEnd)
233
- } catch {
233
+ } catch (e) {
234
234
  // 清理失败时跳过本次清理,后续追加失败会走 appendBufferSafe 的配额兜底。
235
235
  }
236
236
  }
@@ -246,7 +246,7 @@ export default class VoicePlayerAAC {
246
246
  this.mediaSource.endOfStream()
247
247
  }
248
248
  }
249
- } catch {
249
+ } catch (e) {
250
250
  // 当前分片加载失败时停止本轮追加,下一轮缓冲检查会继续尝试。
251
251
  } finally {
252
252
  this.loadNextSegment = false
@@ -262,7 +262,7 @@ export default class VoicePlayerAAC {
262
262
  }, 500)
263
263
 
264
264
  } catch (e) {
265
- this.options.onError?.({ type: 'mse', url: this._url, message: e })
265
+ this.options.onError && this.options.onError({ type: 'mse', url: this._url, message: e })
266
266
  }
267
267
  }, { once: true })
268
268
  this.$audio.play().catch(() => {})
@@ -297,7 +297,7 @@ export default class VoicePlayerAAC {
297
297
  })
298
298
  }
299
299
  } catch (err) {
300
- this.options.onError?.({ type: 'global', url: this._url, message: err })
300
+ this.options.onError && this.options.onError({ type: 'global', url: this._url, message: err })
301
301
  }
302
302
  }).finally(() => {
303
303
  this.downloading = false
@@ -321,7 +321,7 @@ export default class VoicePlayerAAC {
321
321
  // 兜底:强制清空所有缓冲
322
322
  try {
323
323
  sourceBuffer.remove(0, sourceBuffer.buffered.end(0))
324
- } catch {}
324
+ } catch (e) {}
325
325
  return false
326
326
  }
327
327
  }
@@ -379,7 +379,7 @@ export default class VoicePlayerAAC {
379
379
  }
380
380
  const [start, end] = this.getBufferedRange()
381
381
  return [start, end]
382
- } catch {
382
+ } catch (e) {
383
383
  return [0, 0]
384
384
  } finally {
385
385
  this.isPreloading = false
@@ -426,7 +426,7 @@ export default class VoicePlayerAAC {
426
426
  }
427
427
 
428
428
  } catch (err) {
429
- this.options.onError?.({ type: 'mse', url: this._url, message: err })
429
+ this.options.onError && this.options.onError({ type: 'mse', url: this._url, message: err })
430
430
  } finally {
431
431
  // 延迟释放锁,确保缓冲完全加载
432
432
  setTimeout(() => {
@@ -529,14 +529,14 @@ export default class VoicePlayerAAC {
529
529
 
530
530
  stop (callback) {
531
531
  if (!this._play) {
532
- callback?.()
532
+ callback && callback()
533
533
  return
534
534
  }
535
535
  this._play = false
536
536
  this.$audio.pause()
537
537
  this.$audio.currentTime = 0
538
538
  this.$audio.dispatchEvent(new Event('stop'))
539
- callback?.()
539
+ callback && callback()
540
540
  }
541
541
 
542
542
  destroy() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/common",
3
- "version": "1.0.142",
3
+ "version": "1.0.144",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
package/utils/util.js CHANGED
@@ -221,6 +221,9 @@ export function createThrottleRequest (requestFn, idField = 'id') {
221
221
  let loadMap = {}
222
222
  let timer = null
223
223
  return (id) => {
224
+ if (cacheMap[id]) {
225
+ return cacheMap[id]
226
+ }
224
227
  const ps = createPromise()
225
228
  cacheMap[id] = ps
226
229
  loadMap[id] = true
@@ -231,12 +234,15 @@ export function createThrottleRequest (requestFn, idField = 'id') {
231
234
  requestFn(keys).then(rs => {
232
235
  if (rs && rs.length) {
233
236
  rs.forEach(v => {
234
- cacheMap[v[idField]]._execed = true
235
- cacheMap[v[idField]].resolve(v)
237
+ const cacheId = v[idField]
238
+ if (cacheMap[cacheId]) {
239
+ cacheMap[cacheId]._execed = true
240
+ cacheMap[cacheId].resolve(v)
241
+ }
236
242
  })
237
243
  }
238
244
  keys.forEach(id => {
239
- if (!cacheMap[id]._execed) {
245
+ if (cacheMap[id] && !cacheMap[id]._execed) {
240
246
  // 如果没有返回表示没有找到数据
241
247
  cacheMap[id].reject(new Error('未找到数据'))
242
248
  }
@@ -244,8 +250,10 @@ export function createThrottleRequest (requestFn, idField = 'id') {
244
250
  return rs
245
251
  }, err => {
246
252
  keys.forEach(id => {
247
- cacheMap[id]._execed = true
248
- cacheMap[id].reject(err)
253
+ if (cacheMap[id]) {
254
+ cacheMap[id]._execed = true
255
+ cacheMap[id].reject(err)
256
+ }
249
257
  })
250
258
  }).finally(() => {
251
259
  cacheMap = {}
@@ -424,4 +432,4 @@ export const retryRequest = (() => {
424
432
  }
425
433
  }
426
434
  }
427
- })()
435
+ })()