131 lines
2.8 KiB
TypeScript
131 lines
2.8 KiB
TypeScript
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 isTauri = computed(() => '__TAURI_INTERNALS__' in window)
|
|
const commitSha = __COMMIT_SHA__
|
|
const version = computedAsync(() => {
|
|
if (import.meta.dev) {
|
|
return 'dev'
|
|
}
|
|
else if (isTauri.value) {
|
|
return getVersion()
|
|
}
|
|
else {
|
|
return 'web'
|
|
}
|
|
}, '-')
|
|
|
|
const inputMuted = computed(() => {
|
|
return !!mediasoup.micProducer.value?.paused
|
|
})
|
|
const previousInputMuted = ref(inputMuted.value)
|
|
|
|
const outputMuted = ref(false)
|
|
|
|
const sharingEnabled = computed(() => {
|
|
return !!mediasoup.shareProducer.value
|
|
})
|
|
|
|
async function muteInput() {
|
|
if (inputMuted.value)
|
|
return
|
|
|
|
await mediasoup.pauseProducer('microphone')
|
|
|
|
toast.add({ severity: 'info', summary: 'Microphone muted', closable: false, life: 1000 })
|
|
}
|
|
|
|
async function unmuteInput() {
|
|
if (!inputMuted.value)
|
|
return
|
|
|
|
if (outputMuted.value) {
|
|
await unmuteOutput()
|
|
}
|
|
|
|
await mediasoup.resumeProducer('microphone')
|
|
|
|
toast.add({ severity: 'info', summary: 'Microphone activated', closable: false, life: 1000 })
|
|
}
|
|
|
|
async function toggleInput() {
|
|
if (inputMuted.value)
|
|
await unmuteInput()
|
|
else
|
|
await muteInput()
|
|
}
|
|
|
|
async function muteOutput() {
|
|
if (outputMuted.value)
|
|
return
|
|
|
|
outputMuted.value = true
|
|
|
|
previousInputMuted.value = inputMuted.value
|
|
|
|
await muteInput()
|
|
|
|
await signaling.socket.value?.emitWithAck('updateClient', {
|
|
outputMuted: true,
|
|
})
|
|
|
|
toast.add({ severity: 'info', summary: 'Sound muted', closable: false, life: 1000 })
|
|
}
|
|
|
|
async function unmuteOutput() {
|
|
outputMuted.value = false
|
|
|
|
if (!previousInputMuted.value)
|
|
await unmuteInput()
|
|
|
|
await signaling.socket.value?.emitWithAck('updateClient', {
|
|
outputMuted: false,
|
|
})
|
|
|
|
toast.add({ severity: 'info', summary: 'Sound resumed', closable: false, life: 1000 })
|
|
}
|
|
|
|
async function toggleOutput() {
|
|
if (outputMuted.value)
|
|
await unmuteOutput()
|
|
else
|
|
await muteOutput()
|
|
}
|
|
|
|
async function toggleShare() {
|
|
if (!mediasoup.shareProducer.value) {
|
|
await mediasoup.enableShare()
|
|
}
|
|
else {
|
|
await mediasoup.disableProducer('share')
|
|
}
|
|
}
|
|
|
|
return {
|
|
ready,
|
|
clients,
|
|
inputMuted,
|
|
muteInput,
|
|
unmuteInput,
|
|
toggleInput,
|
|
outputMuted,
|
|
muteOutput,
|
|
unmuteOutput,
|
|
toggleOutput,
|
|
version,
|
|
isTauri,
|
|
commitSha,
|
|
toggleShare,
|
|
sharingEnabled,
|
|
}
|
|
})
|