начало чата
All checks were successful
Deploy / deploy (push) Successful in 3m47s

This commit is contained in:
2026-04-16 02:21:54 +06:00
parent 9f39ee6430
commit 0915d3c64d
26 changed files with 1592 additions and 1112 deletions

View File

@@ -2,7 +2,6 @@ import type { types } from 'mediasoup'
import type { Server as SocketServer } from 'socket.io'
import type {
ChadClient,
Namespace,
SomeSocket,
} from '../types/webrtc.ts'
import { consola } from 'consola'
@@ -10,8 +9,6 @@ import prisma from '../prisma/client.ts'
import { socketToClient } from '../utils/socket-to-client.ts'
export default async function (io: SocketServer, router: types.Router) {
const namespace: Namespace = io.of('/webrtc')
const audioLevelObserver = await router.createAudioLevelObserver({
maxEntries: 10,
threshold: -80,
@@ -21,7 +18,7 @@ export default async function (io: SocketServer, router: types.Router) {
const activeSpeakerObserver = await router.createActiveSpeakerObserver()
audioLevelObserver.on('volumes', async (volumes: types.AudioLevelObserverVolume[]) => {
namespace.emit('speakingPeers', volumes.map(({ producer, volume }) => {
io.emit('speakingPeers', volumes.map(({ producer, volume }) => {
const { socketId } = producer.appData as { socketId: ChadClient['socketId'] }
return {
@@ -32,17 +29,17 @@ export default async function (io: SocketServer, router: types.Router) {
})
audioLevelObserver.on('silence', () => {
namespace.emit('speakingPeers', [])
namespace.emit('activeSpeaker', undefined)
io.emit('speakingPeers', [])
io.emit('activeSpeaker', undefined)
})
activeSpeakerObserver.on('dominantspeaker', ({ producer }) => {
const { socketId } = producer.appData as { socketId: ChadClient['socketId'] }
namespace.emit('activeSpeaker', socketId)
io.emit('activeSpeaker', socketId)
})
namespace.on('connection', async (socket) => {
io.on('connection', async (socket) => {
consola.info('[WebRtc]', 'Client connected', socket.id)
socket.data.joined = false
@@ -350,7 +347,7 @@ export default async function (io: SocketServer, router: types.Router) {
cb(socketToClient(socket))
namespace.emit('clientChanged', socket.id, socketToClient(socket))
io.emit('clientChanged', socket.id, socketToClient(socket))
})
socket.on('disconnect', () => {
@@ -367,7 +364,7 @@ export default async function (io: SocketServer, router: types.Router) {
})
async function getJoinedSockets(excludeId?: string) {
const sockets = await namespace.fetchSockets()
const sockets = await io.fetchSockets()
return sockets.filter(socket => socket.data.joined && (excludeId ? excludeId !== socket.id : true))
}