7 Commits

Author SHA1 Message Date
0922fc4f41 новый-старый clientrow
All checks were successful
Deploy / publish-web (push) Successful in 41s
2026-01-29 23:19:31 +06:00
9fc8f954e3 новый-старый clientrow 2026-01-29 23:18:47 +06:00
a645885cf2 client volumes
All checks were successful
Deploy / publish-web (push) Successful in 1m31s
2026-01-29 22:05:05 +06:00
4c8a0e791c client volumes 2026-01-29 22:04:40 +06:00
fbdceb2e55 client volumes 2026-01-29 21:59:41 +06:00
aeaea47609 client volumes and dominant client
All checks were successful
Deploy / deploy (push) Successful in 33s
2026-01-29 21:40:56 +06:00
f4fd752448 client volumes and dominant client
All checks were successful
Deploy / deploy (push) Successful in 34s
2026-01-29 21:34:46 +06:00
10 changed files with 92 additions and 24 deletions

View File

@@ -17,6 +17,7 @@ declare module 'vue' {
PrimeFloatLabel: typeof import('primevue/floatlabel')['default']
PrimeInputText: typeof import('primevue/inputtext')['default']
PrimePassword: typeof import('primevue/password')['default']
PrimeProgressBar: typeof import('primevue/progressbar')['default']
PrimeScrollPanel: typeof import('primevue/scrollpanel')['default']
PrimeSelect: typeof import('primevue/select')['default']
PrimeSelectButton: typeof import('primevue/selectbutton')['default']

View File

@@ -6,18 +6,28 @@
'bg-surface-800': expanded,
}"
>
<div class="p-3 flex items-center gap-3" @click="toggleExpand">
<PrimeAvatar size="small">
<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">
<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
})

View File

@@ -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) {
@@ -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,

View File

@@ -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"
>

View File

@@ -52,11 +52,11 @@
</PrimeDivider>
<div>
<div class="flex justify-between text-sm mb-3">
<span>FPS</span>
<span>{{ shareFps }}</span>
<div class="text-sm mb-2">
Share FPS
</div>
<PrimeSlider v-model="shareFps" class="mx-[10px]" :min="30" :max="60" :step="5" />
<PrimeSelectButton v-model="shareFps" :options="[5, 30, 60]" fluid size="small" />
</div>
<template v-if="isTauri">

View File

@@ -8,3 +8,8 @@ export interface ChadClient {
}
export type UpdatedClient = Omit<ChadClient, 'socketId' | 'userId' | 'isMe'>
export interface SpeakingClient {
clientId: ChadClient['socketId']
volume: number
}

View File

@@ -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",

View File

@@ -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'] },

View File

@@ -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) {

View File

@@ -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 {}