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