import { getVersion } from '@tauri-apps/api/app' import { computedAsync, createGlobalState } from '@vueuse/core' import { useClients } from '~/composables/use-clients' export const useApp = createGlobalState(() => { const { clients } = useClients() const mediasoup = useMediasoup() const signaling = useSignaling() const toast = useToast() const ready = ref(false) const inputMuted = ref(false) const outputMuted = ref(false) const previousInputMuted = ref(inputMuted.value) const isTauri = computed(() => '__TAURI_INTERNALS__' in window) const commitSha = __COMMIT_SHA__ const version = computedAsync(() => isTauri.value ? getVersion() : 'web', '-') watch(inputMuted, async (inputMuted) => { if (inputMuted) { await mediasoup.pauseProducer('microphone') } else { if (outputMuted.value) { outputMuted.value = false } await mediasoup.resumeProducer('microphone') } const toastText = inputMuted ? 'Microphone muted' : 'Microphone activated' toast.add({ severity: 'info', summary: toastText, closable: false, life: 1000 }) }) watch(outputMuted, async (outputMuted) => { if (outputMuted) { previousInputMuted.value = inputMuted.value muteInput() } else { inputMuted.value = previousInputMuted.value } const updatedMe = await signaling.socket.value?.emitWithAck('updateClient', { outputMuted, }) const toastText = outputMuted ? 'Sound muted' : 'Sound resumed' toast.add({ severity: 'info', summary: toastText, closable: false, life: 1000 }) }) function muteInput() { inputMuted.value = true } function unmuteInput() { inputMuted.value = false } function toggleInput() { if (inputMuted.value) unmuteInput() else muteInput() } function muteOutput() { outputMuted.value = true } function unmuteOutput() { outputMuted.value = false } function toggleOutput() { if (outputMuted.value) unmuteOutput() else muteOutput() } return { ready, clients, inputMuted, muteInput, unmuteInput, toggleInput, outputMuted, muteOutput, unmuteOutput, toggleOutput, version, isTauri, commitSha, } })