Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba12d413dc | ||
|
|
f525d1afe5 | ||
|
|
75fe5b0b8c |
@@ -1,47 +0,0 @@
|
|||||||
import { createServer as createHttpServer } from 'node:http'
|
|
||||||
import { consola } from 'consola'
|
|
||||||
import cors from 'cors'
|
|
||||||
import express from 'express'
|
|
||||||
import * as mediasoup from 'mediasoup'
|
|
||||||
import { Server as SocketServer } from 'socket.io'
|
|
||||||
import { webrtcSocket } from './sockets'
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
const app = express()
|
|
||||||
|
|
||||||
app.use(cors())
|
|
||||||
|
|
||||||
const server = createHttpServer(app)
|
|
||||||
|
|
||||||
const worker = await mediasoup.createWorker()
|
|
||||||
worker.on('died', () => {
|
|
||||||
consola.error('[Mediasoup]', 'Worker died, exiting...')
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
const router = await worker.createRouter({
|
|
||||||
mediaCodecs: [
|
|
||||||
{
|
|
||||||
kind: 'audio',
|
|
||||||
mimeType: 'audio/opus',
|
|
||||||
clockRate: 48000,
|
|
||||||
channels: 2,
|
|
||||||
parameters: { useinbandfec: 1, stereo: 1 },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
const io = new SocketServer(server, {
|
|
||||||
path: '/chad/ws',
|
|
||||||
cors: {
|
|
||||||
origin: process.env.CORS_ORIGIN || '*',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
webrtcSocket(io, router)
|
|
||||||
|
|
||||||
server.listen(process.env.PORT || 4000, () => {
|
|
||||||
consola.success('[Server]', 'Server started!')
|
|
||||||
})
|
|
||||||
})()
|
|
||||||
@@ -17,6 +17,9 @@ export default fp(async (fastify) => {
|
|||||||
try {
|
try {
|
||||||
const sessionId = auth.readSessionCookie(req.headers.cookie ?? '')
|
const sessionId = auth.readSessionCookie(req.headers.cookie ?? '')
|
||||||
|
|
||||||
|
if (!sessionId)
|
||||||
|
return
|
||||||
|
|
||||||
const { session, user } = await auth.validateSession(sessionId ?? '')
|
const { session, user } = await auth.validateSession(sessionId ?? '')
|
||||||
|
|
||||||
if (session && session.fresh) {
|
if (session && session.fresh) {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import type { FastifyInstance } from 'fastify'
|
import type { FastifyInstance } from 'fastify'
|
||||||
import type { RegisterOptions } from 'fastify/types/register.js'
|
|
||||||
import bcrypt from 'bcrypt'
|
import bcrypt from 'bcrypt'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { auth } from '../auth/lucia.ts'
|
import { auth } from '../auth/lucia.ts'
|
||||||
@@ -71,8 +70,6 @@ export default function (fastify: FastifyInstance) {
|
|||||||
const session = await auth.createSession(user.id, {})
|
const session = await auth.createSession(user.id, {})
|
||||||
const cookie = auth.createSessionCookie(session.id)
|
const cookie = auth.createSessionCookie(session.id)
|
||||||
|
|
||||||
cookie.attributes.secure = false
|
|
||||||
|
|
||||||
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
|
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -119,7 +116,3 @@ export default function (fastify: FastifyInstance) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const autoConfig: RegisterOptions = {
|
|
||||||
prefix: '/chad',
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -23,13 +23,14 @@ fastify.register(FastifyAutoLoad, {
|
|||||||
|
|
||||||
fastify.register(FastifyAutoLoad, {
|
fastify.register(FastifyAutoLoad, {
|
||||||
dir: join(__dirname, 'routes'),
|
dir: join(__dirname, 'routes'),
|
||||||
|
options: { prefix: 'chad' },
|
||||||
})
|
})
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
const port = process.env.PORT ? Number(process.env.PORT) : 4000
|
const port = process.env.PORT ? Number(process.env.PORT) : 4000
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fastify.listen({ port })
|
await fastify.listen({ port, host: '0.0.0.0' })
|
||||||
|
|
||||||
await prisma.$connect()
|
await prisma.$connect()
|
||||||
fastify.log.info('Testing DB Connection. OK')
|
fastify.log.info('Testing DB Connection. OK')
|
||||||
|
|||||||
Reference in New Issue
Block a user