{"version":3,"file":"AudioPlayerNotificationsPlugin.mjs","names":[],"sources":["../../../../../src/components/AudioPlayback/plugins/AudioPlayerNotificationsPlugin.ts"],"sourcesContent":["import type { AudioPlayerPlugin } from './AudioPlayerPlugin';\nimport { type AudioPlayerErrorCode } from '../AudioPlayer';\nimport type { AddNotification } from '../../Notifications/hooks/useNotificationApi';\nimport type { NotificationTargetPanel } from '../../Notifications/notificationTarget';\nimport type { StreamTFunction } from '../../../i18n/types';\n\nconst SEEK_NOT_SUPPORTED_NOTIFICATION_DEBOUNCE_INTERVAL_MS = 1000;\n\nexport const audioPlayerNotificationsPluginFactory = ({\n  addNotification,\n  panel = 'channel',\n  t,\n}: {\n  addNotification: AddNotification;\n  panel?: NotificationTargetPanel;\n  t: StreamTFunction;\n}): AudioPlayerPlugin => {\n  const errors: Record<AudioPlayerErrorCode, Error> = {\n    'failed-to-start': new Error(\n      t(\n        'audioPlayback.audioPlayerNotifications.failedPlayRecording.label',\n        'Failed to play the recording',\n      ),\n    ),\n    'not-playable': new Error(\n      t(\n        'audioPlayback.audioPlayerNotifications.recordingFormatNotSupported.label',\n        'Recording format is not supported and cannot be reproduced',\n      ),\n    ),\n    'seek-not-supported': new Error(\n      t(\n        'audioPlayback.audioPlayerNotifications.cannotSeekRecording.label',\n        'Cannot seek in the recording',\n      ),\n    ),\n  };\n  let lastSeekNotSupportedNotificationAt: number | undefined;\n\n  return {\n    id: 'AudioPlayerNotificationsPlugin',\n    onError: ({ errCode, error: e }) => {\n      if (errCode === 'seek-not-supported') {\n        const now = Date.now();\n\n        if (\n          typeof lastSeekNotSupportedNotificationAt === 'number' &&\n          now - lastSeekNotSupportedNotificationAt <\n            SEEK_NOT_SUPPORTED_NOTIFICATION_DEBOUNCE_INTERVAL_MS\n        ) {\n          return;\n        }\n\n        lastSeekNotSupportedNotificationAt = now;\n      }\n\n      const error =\n        (errCode && errors[errCode]) ??\n        e ??\n        new Error(\n          t('notification.audioPlaybackError', 'Error reproducing the recording'),\n        );\n\n      addNotification({\n        emitter: 'AudioPlayer',\n        error,\n        message: error.message,\n        severity: 'error',\n        targetPanels: [panel],\n        type: 'browser:audio:playback:error',\n      });\n    },\n  };\n};\n"],"mappings":";AAMA,IAAM,uDAAuD;AAE7D,IAAa,yCAAyC,EACpD,iBACA,QAAQ,WACR,QAKuB;CACvB,MAAM,SAA8C;EAClD,mBAAmB,IAAI,MACrB,EACE,oEACA,8BACF,CACF;EACA,gBAAgB,IAAI,MAClB,EACE,4EACA,4DACF,CACF;EACA,sBAAsB,IAAI,MACxB,EACE,oEACA,8BACF,CACF;CACF;CACA,IAAI;CAEJ,OAAO;EACL,IAAI;EACJ,UAAU,EAAE,SAAS,OAAO,QAAQ;GAClC,IAAI,YAAY,sBAAsB;IACpC,MAAM,MAAM,KAAK,IAAI;IAErB,IACE,OAAO,uCAAuC,YAC9C,MAAM,qCACJ,sDAEF;IAGF,qCAAqC;GACvC;GAEA,MAAM,SACH,WAAW,OAAO,aACnB,KACA,IAAI,MACF,EAAE,mCAAmC,iCAAiC,CACxE;GAEF,gBAAgB;IACd,SAAS;IACT;IACA,SAAS,MAAM;IACf,UAAU;IACV,cAAc,CAAC,KAAK;IACpB,MAAM;GACR,CAAC;EACH;CACF;AACF"}