wwf
3 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
app/components/base/audio-btn/audio.ts
@@ -2,7 +2,7 @@
import { textToAudioStream } from '@/service/share'
declare global {
  // eslint-disable-next-line ts/consistent-type-definitions
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
  interface Window {
    ManagedMediaSource: any
  }
@@ -21,9 +21,9 @@
  isLoadData = false
  url: string
  isPublic: boolean
  callback: ((event: string) => void) | null
  callback: ((event: string) => {}) | null
  constructor(streamUrl: string, isPublic: boolean, msgId: string | undefined, msgContent: string | null | undefined, voice: string | undefined, callback: ((event: string) => void) | null) {
  constructor(streamUrl: string, isPublic: boolean, msgId: string | undefined, msgContent: string | null | undefined, voice: string | undefined, callback: ((event: string) => {}) | null) {
    this.audioContext = new AudioContext()
    this.msgId = msgId
    this.msgContent = msgContent
@@ -68,7 +68,7 @@
    })
  }
  public setCallback(callback: ((event: string) => void) | null) {
  public setCallback(callback: ((event: string) => {}) | null) {
    this.callback = callback
    if (callback) {
      this.audio.addEventListener('ended', () => {
@@ -125,7 +125,7 @@
        this.receiveAudioData(value)
      }
    }
    catch {
    catch (error) {
      this.isLoadData = false
      this.callback && this.callback('error')
    }
@@ -211,6 +211,10 @@
    this.audioContext.suspend()
  }
  private cancer() {
  }
  private receiveAudioData(unit8Array: Uint8Array) {
    if (!unit8Array) {
      this.finishStream()