работаем бля работаем

This commit is contained in:
2026-05-09 03:21:44 +06:00
parent f845777bac
commit 0b148c6a7d
169 changed files with 15816 additions and 1005 deletions

View File

@@ -1,10 +1,9 @@
import type { FastifyInstance } from 'fastify'
import type { ServerOptions } from 'socket.io'
import type { MessageSelect } from '../prisma/generated-client/models/Message.ts'
import fp from 'fastify-plugin'
import { Server } from 'socket.io'
import registerChatSocket from '../socket/chat.ts'
import registerWebrtcSocket from '../socket/webrtc.ts'
import registerChatSocket from './socket/chat/index.ts'
import registerWebrtcSocket from './socket/webrtc/index.ts'
declare module 'fastify' {
interface FastifyInstance {
@@ -24,12 +23,26 @@ export default fp<Partial<ServerOptions>>(
await fastify.io.close()
})
await registerWebrtcSocket(fastify.io, fastify.mediasoupRouter, fastify.prisma)
await registerChatSocket(fastify.io)
fastify.io.use(async (socket, next) => {
const sessionId = fastify.lucia.readSessionCookie(socket.handshake.headers.cookie ?? '')
fastify.bus.on('chat:new-message', async (message: MessageSelect) => {
fastify.io.emit('chat:new-message', message)
if (!sessionId) {
return next(fastify.httpErrors.unauthorized())
}
const { user } = await fastify.lucia.validateSession(sessionId)
if (!user) {
return next(fastify.httpErrors.unauthorized())
}
socket.data.user = user
next()
})
await registerWebrtcSocket(fastify)
await registerChatSocket(fastify)
},
{ name: 'socket-io', dependencies: ['mediasoup-worker', 'mediasoup-router', 'prisma', 'event-bus'] },
)