Compare commits
9 Commits
12ce381abd
...
v0.2.22
| Author | SHA1 | Date | |
|---|---|---|---|
| 0922fc4f41 | |||
| 9fc8f954e3 | |||
| a645885cf2 | |||
| 4c8a0e791c | |||
| fbdceb2e55 | |||
| aeaea47609 | |||
| f4fd752448 | |||
| 595354b7f0 | |||
|
|
d08b011596 |
Binary file not shown.
@@ -6,18 +6,28 @@
|
||||
'bg-surface-800': expanded,
|
||||
}"
|
||||
>
|
||||
<div class="p-3 flex items-center gap-3" @click="toggleExpand">
|
||||
<PrimeAvatar size="small">
|
||||
<template #icon>
|
||||
<User :size="20" />
|
||||
</template>
|
||||
</PrimeAvatar>
|
||||
<div class="p-3" @click="toggleExpand">
|
||||
<div class="flex items-center gap-3">
|
||||
<PrimeAvatar
|
||||
size="small"
|
||||
class="shrink-0"
|
||||
:class="{
|
||||
'outline-1 outline-primary outline-offset-2': speaking,
|
||||
}"
|
||||
>
|
||||
<template #icon>
|
||||
<User :size="20" />
|
||||
</template>
|
||||
</PrimeAvatar>
|
||||
|
||||
<div class="flex-1 overflow-hidden text-sm leading-5 font-medium text-color whitespace-nowrap overflow-ellipsis">
|
||||
{{ client.displayName || client.username }}
|
||||
<p class="flex-1 text-sm leading-5 font-medium text-color truncate w-0">
|
||||
{{ client.displayName || client.username }}
|
||||
</p>
|
||||
|
||||
<Component :is="expanded ? ChevronUp : ChevronDown" v-if="!isMe" :size="20" class="text-muted-color" />
|
||||
</div>
|
||||
|
||||
<div class="flex align-center gap-1">
|
||||
<div v-if="hasBadges" class="flex justify-end align-center gap-1 mt-2">
|
||||
<PrimeBadge v-if="!!shareConsumer" v-tooltip.top="'Watch'" severity="success" value="Streaming" size="small" @click.stop="watchStream" />
|
||||
|
||||
<PrimeBadge v-if="premuted" severity="danger" value="Muted" size="small" />
|
||||
@@ -26,8 +36,6 @@
|
||||
|
||||
<PrimeBadge v-if="isMe" severity="secondary" value="You" size="small" class="shrink-0" />
|
||||
</div>
|
||||
|
||||
<Component :is="expanded ? ChevronUp : ChevronDown" v-if="!isMe" :size="20" class="text-muted-color" />
|
||||
</div>
|
||||
|
||||
<CollapseTransition v-if="!isMe">
|
||||
@@ -61,7 +69,7 @@ const props = defineProps<{
|
||||
}>()
|
||||
|
||||
const { outputMuted } = useApp()
|
||||
const { consumers: allConsumers, micProducer } = useMediasoup()
|
||||
const { consumers: allConsumers, micProducer, speakingClients } = useMediasoup()
|
||||
const { me } = useClients()
|
||||
const { show } = useFullscreenVideo()
|
||||
|
||||
@@ -94,6 +102,10 @@ const audioTrack = computed(() => {
|
||||
return audioConsumer.value?.track
|
||||
})
|
||||
|
||||
const speaking = computed(() => {
|
||||
return speakingClients.value.find(speaker => speaker.clientId === props.client.socketId)
|
||||
})
|
||||
|
||||
const audioConsumerPaused = ref(false)
|
||||
|
||||
const inputMuted = computed(() => {
|
||||
@@ -103,6 +115,14 @@ const inputMuted = computed(() => {
|
||||
return premuted.value || audioConsumerPaused.value
|
||||
})
|
||||
|
||||
const hasBadges = computed(() => {
|
||||
return !!shareConsumer.value
|
||||
|| premuted.value
|
||||
|| inputMuted.value
|
||||
|| props.client.outputMuted
|
||||
|| isMe.value
|
||||
})
|
||||
|
||||
watch(allConsumers, () => {
|
||||
audioConsumerPaused.value = audioConsumer.value?.paused ?? false
|
||||
})
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { SpeakingClient } from '#shared/types'
|
||||
import type { MediaKind, ProducerOptions } from 'mediasoup-client/types'
|
||||
import { createSharedComposable } from '@vueuse/core'
|
||||
import * as mediasoupClient from 'mediasoup-client'
|
||||
import { shallowRef } from 'vue'
|
||||
import { useDevices } from '~/composables/use-devices'
|
||||
import { usePreferences } from '~/composables/use-preferences'
|
||||
import { useSignaling } from '~/composables/use-signaling'
|
||||
@@ -40,6 +42,8 @@ export const useMediasoup = createSharedComposable(() => {
|
||||
const consumers = shallowRef<Map<string, mediasoupClient.types.Consumer>>(new Map())
|
||||
const producers = shallowRef<Map<string, mediasoupClient.types.Producer>>(new Map())
|
||||
|
||||
const speakingClients = shallowRef<SpeakingClient[]>([])
|
||||
|
||||
watch(signaling.socket, (socket) => {
|
||||
if (!socket)
|
||||
return
|
||||
@@ -227,6 +231,10 @@ export const useMediasoup = createSharedComposable(() => {
|
||||
|
||||
triggerRef(consumers)
|
||||
})
|
||||
|
||||
socket.on('speakingPeers', (value: SpeakingClient[]) => {
|
||||
speakingClients.value = value
|
||||
})
|
||||
}, { immediate: true, flush: 'sync' })
|
||||
|
||||
async function enableProducer(type: ProducerType, options: ProducerOptions) {
|
||||
@@ -317,7 +325,7 @@ export const useMediasoup = createSharedComposable(() => {
|
||||
if (!device.value)
|
||||
return
|
||||
|
||||
const stream = await getShareStream()
|
||||
const stream = await getShareStream(preferences.shareFps.value)
|
||||
|
||||
const track = stream.getVideoTracks()[0]
|
||||
|
||||
@@ -327,7 +335,7 @@ export const useMediasoup = createSharedComposable(() => {
|
||||
await enableProducer('share', {
|
||||
track,
|
||||
codec: device.value.rtpCapabilities.codecs?.find(
|
||||
c => c.mimeType.toLowerCase() === 'video/h264',
|
||||
c => c.mimeType.toLowerCase() === 'video/AV1',
|
||||
),
|
||||
codecOptions: {
|
||||
videoGoogleStartBitrate: 1000,
|
||||
@@ -424,6 +432,7 @@ export const useMediasoup = createSharedComposable(() => {
|
||||
init,
|
||||
consumers,
|
||||
producers,
|
||||
speakingClients,
|
||||
sendTransport,
|
||||
recvTransport,
|
||||
rtpCapabilities,
|
||||
|
||||
@@ -19,6 +19,8 @@ export const usePreferences = createGlobalState(() => {
|
||||
const noiseSuppression = useLocalStorage('NOISE_SUPPRESSION', true)
|
||||
const echoCancellation = useLocalStorage('ECHO_CANCELLATION', true)
|
||||
|
||||
const shareFps = useLocalStorage('SHARE_FPS', 30)
|
||||
|
||||
const toggleInputHotkey = ref<SyncedPreferences['toggleInputHotkey']>('')
|
||||
const toggleOutputHotkey = ref<SyncedPreferences['toggleOutputHotkey']>('')
|
||||
|
||||
@@ -57,6 +59,7 @@ export const usePreferences = createGlobalState(() => {
|
||||
autoGainControl,
|
||||
noiseSuppression,
|
||||
echoCancellation,
|
||||
shareFps,
|
||||
toggleInputHotkey,
|
||||
toggleOutputHotkey,
|
||||
inputDeviceExist,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="grid grid-cols-[1fr_1.25fr] gap-2 p-2 h-screen grid-rows-[auto_1fr]">
|
||||
<div class="grid grid-cols-[1fr_1.25fr] gap-2 p-2 h-screen grid-rows-[auto_1fr] max-w-full">
|
||||
<div
|
||||
class="flex items-center justify-between gap-2 rounded-xl p-3 bg-surface-950"
|
||||
>
|
||||
|
||||
@@ -47,6 +47,18 @@
|
||||
<!-- <label for="outputDevice">Output device</label> -->
|
||||
<!-- </PrimeFloatLabel> -->
|
||||
|
||||
<PrimeDivider align="left">
|
||||
Video
|
||||
</PrimeDivider>
|
||||
|
||||
<div>
|
||||
<div class="text-sm mb-2">
|
||||
Share FPS
|
||||
</div>
|
||||
|
||||
<PrimeSelectButton v-model="shareFps" :options="[5, 30, 60]" fluid size="small" />
|
||||
</div>
|
||||
|
||||
<template v-if="isTauri">
|
||||
<PrimeDivider align="left">
|
||||
Hotkeys
|
||||
@@ -117,6 +129,7 @@ const {
|
||||
toggleOutputHotkey,
|
||||
inputDeviceExist,
|
||||
outputDeviceExist,
|
||||
shareFps,
|
||||
} = usePreferences()
|
||||
|
||||
const setupToggleInputHotkey = (event: KeyboardEvent) => setupHotkey(event, toggleInputHotkey)
|
||||
|
||||
@@ -8,3 +8,8 @@ export interface ChadClient {
|
||||
}
|
||||
|
||||
export type UpdatedClient = Omit<ChadClient, 'socketId' | 'userId' | 'isMe'>
|
||||
|
||||
export interface SpeakingClient {
|
||||
clientId: ChadClient['socketId']
|
||||
volume: number
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
||||
"productName": "chad",
|
||||
"version": "0.2.19",
|
||||
"version": "0.2.22",
|
||||
"identifier": "xyz.koptilnya.chad",
|
||||
"build": {
|
||||
"frontendDist": "../.output/public",
|
||||
|
||||
@@ -22,8 +22,8 @@ export default fp<Partial<ServerOptions>>(
|
||||
await fastify.io.close()
|
||||
})
|
||||
|
||||
fastify.ready(() => {
|
||||
registerWebrtcSocket(fastify.io, fastify.mediasoupRouter)
|
||||
fastify.ready(async () => {
|
||||
await registerWebrtcSocket(fastify.io, fastify.mediasoupRouter)
|
||||
})
|
||||
},
|
||||
{ name: 'socket-io', dependencies: ['mediasoup-worker', 'mediasoup-router'] },
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { types } from 'mediasoup'
|
||||
import type { Server as SocketServer } from 'socket.io'
|
||||
import type {
|
||||
ChadClient,
|
||||
Namespace,
|
||||
SomeSocket,
|
||||
} from '../types/webrtc.ts'
|
||||
@@ -8,9 +9,39 @@ import { consola } from 'consola'
|
||||
import prisma from '../prisma/client.ts'
|
||||
import { socketToClient } from '../utils/socket-to-client.ts'
|
||||
|
||||
export default function (io: SocketServer, router: types.Router) {
|
||||
export default async function (io: SocketServer, router: types.Router) {
|
||||
const namespace: Namespace = io.of('/webrtc')
|
||||
|
||||
const audioLevelObserver = await router.createAudioLevelObserver({
|
||||
maxEntries: 10,
|
||||
threshold: -80,
|
||||
interval: 800,
|
||||
})
|
||||
|
||||
const activeSpeakerObserver = await router.createActiveSpeakerObserver()
|
||||
|
||||
audioLevelObserver.on('volumes', async (volumes: types.AudioLevelObserverVolume[]) => {
|
||||
namespace.emit('speakingPeers', volumes.map(({ producer, volume }) => {
|
||||
const { socketId } = producer.appData as { socketId: ChadClient['socketId'] }
|
||||
|
||||
return {
|
||||
clientId: socketId,
|
||||
volume,
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
audioLevelObserver.on('silence', () => {
|
||||
namespace.emit('speakingPeers', [])
|
||||
namespace.emit('activeSpeaker', undefined)
|
||||
})
|
||||
|
||||
activeSpeakerObserver.on('dominantspeaker', ({ producer }) => {
|
||||
const { socketId } = producer.appData as { socketId: ChadClient['socketId'] }
|
||||
|
||||
namespace.emit('activeSpeaker', socketId)
|
||||
})
|
||||
|
||||
namespace.on('connection', async (socket) => {
|
||||
consola.info('[WebRtc]', 'Client connected', socket.id)
|
||||
|
||||
@@ -182,8 +213,8 @@ export default function (io: SocketServer, router: types.Router) {
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: Add into the AudioLevelObserver and ActiveSpeakerObserver.
|
||||
// https://github.com/versatica/mediasoup-demo/blob/v3/server/lib/Room.js#L1276
|
||||
await audioLevelObserver.addProducer({ producerId: producer.id })
|
||||
await activeSpeakerObserver.addProducer({ producerId: producer.id })
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
|
||||
@@ -118,6 +118,8 @@ export interface ServerToClientEvents {
|
||||
consumerResumed: (arg: { consumerId: string }) => void
|
||||
consumerScore: (arg: { consumerId: string, score: types.ConsumerScore }) => void
|
||||
clientChanged: (clientId: ChadClient['socketId'], client: ChadClient) => void
|
||||
speakingPeers: (arg: { clientId: ChadClient['socketId'], volume: types.AudioLevelObserverVolume['volume'] }[]) => void
|
||||
activeSpeaker: (clientId?: ChadClient['socketId']) => void
|
||||
}
|
||||
|
||||
export interface InterServerEvent {}
|
||||
|
||||
Reference in New Issue
Block a user