куча говна
All checks were successful
Deploy / deploy (push) Successful in 4m32s

This commit is contained in:
Никита Круглицкий
2025-10-20 00:10:13 +06:00
parent 31460598ba
commit ec67be8aa6
50 changed files with 1616 additions and 1011 deletions

View File

@@ -1,4 +1,4 @@
import type { ChadClient, RemoteClient } from '#shared/types'
import type { ChadClient } from '#shared/types'
import { createSharedComposable } from '@vueuse/core'
import * as mediasoupClient from 'mediasoup-client'
import { usePreferences } from '~/composables/use-preferences'
@@ -23,6 +23,7 @@ export const useMediasoup = createSharedComposable(() => {
const signaling = useSignaling()
const { addClient, removeClient } = useClients()
const preferences = usePreferences()
const { me } = useAuth()
const device = shallowRef<mediasoupClient.Device>()
const rtpCapabilities = shallowRef<mediasoupClient.types.RtpCapabilities>()
@@ -40,7 +41,7 @@ export const useMediasoup = createSharedComposable(() => {
if (!socket)
return
socket.on('connect', async () => {
socket.on('authenticated', async () => {
if (!signaling.socket.value)
return
@@ -123,9 +124,8 @@ export const useMediasoup = createSharedComposable(() => {
}
const joinedClients = (await signaling.socket.value.emitWithAck('join', {
username: preferences.username.value,
rtpCapabilities: rtpCapabilities.value,
})).map(transformClient)
}))
addClient(...joinedClients)
@@ -135,7 +135,7 @@ export const useMediasoup = createSharedComposable(() => {
})
socket.on('newPeer', (client) => {
addClient(transformClient(client))
addClient(client)
})
socket.on('peerClosed', (id) => {
@@ -188,15 +188,25 @@ export const useMediasoup = createSharedComposable(() => {
)
socket.on('disconnect', () => {
device.value = undefined
rtpCapabilities.value = undefined
sendTransport.value?.close()
sendTransport.value = undefined
recvTransport.value?.close()
recvTransport.value = undefined
micProducer.value = undefined
webcamProducer.value = undefined
shareProducer.value = undefined
consumers.value = new Map()
producers.value = new Map()
})
}, { immediate: true, flush: 'sync' })
function getClientConsumers(clientId: ChadClient['id']) {
function getClientConsumers(clientId: ChadClient['socketId']) {
return consumers.value.values().filter(consumer => consumer.appData.clientId === clientId)
}
@@ -298,27 +308,6 @@ export const useMediasoup = createSharedComposable(() => {
signaling.connect()
}
function transformClient(client: RemoteClient): ChadClient {
return {
...client,
isMe: client.id === signaling.socket.value!.id,
}
}
function dispose() {
device.value = undefined
rtpCapabilities.value = undefined
sendTransport.value = undefined
recvTransport.value = undefined
micProducer.value = undefined
webcamProducer.value = undefined
shareProducer.value = undefined
consumers.value = new Map()
producers.value = new Map()
}
return {
init,
consumers,