Files
ComfyUI_frontend/src/services/audioService.ts
Christian Byrne 27ab355f9c [refactor] Improve updates/notifications domain organization (#5590)
* [refactor] Move update-related functionality to platform/updates domain

Reorganizes release management, version compatibility, and notification functionality
following Domain-Driven Design principles, mirroring VSCode's architecture pattern.

- Move releaseService.ts to platform/updates/common/
- Move releaseStore.ts to platform/updates/common/
- Move versionCompatibilityStore.ts to platform/updates/common/
- Move useFrontendVersionMismatchWarning.ts to platform/updates/common/
- Move toastStore.ts to platform/updates/common/
- Move ReleaseNotificationToast.vue to platform/updates/components/
- Move WhatsNewPopup.vue to platform/updates/components/
- Update 25+ import paths across codebase and tests

This creates a cohesive "updates" domain containing all functionality related to
software updates, version checking, release notifications, and user communication
about application state changes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix imports

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-15 04:34:37 -07:00

85 lines
2.1 KiB
TypeScript

import { register } from 'extendable-media-recorder'
import { connect } from 'extendable-media-recorder-wav-encoder'
import { useToastStore } from '@/platform/updates/common/toastStore'
import { api } from '@/scripts/api'
export interface AudioRecordingError {
type: 'permission' | 'not_supported' | 'encoder' | 'recording' | 'unknown'
message: string
originalError?: unknown
}
let isEncoderRegistered: boolean = false
export const useAudioService = () => {
const handleError = (
type: AudioRecordingError['type'],
message: string,
originalError?: unknown
) => {
console.error(`Audio Service Error (${type}):`, message, originalError)
}
const stopAllTracks = (currentStream: MediaStream | null) => {
if (currentStream) {
currentStream.getTracks().forEach((track) => {
track.stop()
})
currentStream = null
}
}
const registerWavEncoder = async (): Promise<void> => {
if (isEncoderRegistered) {
return
}
try {
await register(await connect())
isEncoderRegistered = true
} catch (err) {
if (
err instanceof Error &&
err.message.includes('already an encoder stored')
) {
isEncoderRegistered = true
} else {
handleError('encoder', 'Failed to register WAV encoder', err)
}
}
}
const convertBlobToFileAndSubmit = async (blob: Blob): Promise<string> => {
const name = `recording-${Date.now()}.wav`
const file = new File([blob], name, { type: blob.type || 'audio/wav' })
const body = new FormData()
body.append('image', file)
body.append('subfolder', 'audio')
body.append('type', 'temp')
const resp = await api.fetchApi('/upload/image', {
method: 'POST',
body
})
if (resp.status !== 200) {
const err = `Error uploading temp file: ${resp.status} - ${resp.statusText}`
useToastStore().addAlert(err)
throw new Error(err)
}
const tempAudio = await resp.json()
return `audio/${tempAudio.name} [temp]`
}
return {
// Methods
convertBlobToFileAndSubmit,
registerWavEncoder,
stopAllTracks
}
}