mirror of
https://github.com/SrIzan10/hctv.git
synced 2026-06-06 00:56:56 +00:00
feat: srt support and auth
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { prisma } from '@hctv/db';
|
||||
import { NextRequest } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json();
|
||||
|
||||
const parsed = schema.safeParse(body);
|
||||
|
||||
if (!parsed.success) {
|
||||
console.log('Parsing error:', parsed.error);
|
||||
return new Response('Invalid request', { status: 400 });
|
||||
}
|
||||
console.log('Parsed data:', parsed.data);
|
||||
const { action, protocol, path, password } = parsed.data;
|
||||
|
||||
// if (action !== 'publish') return new Response('Action not allowed', { status: 403 });
|
||||
if (action === 'publish' && protocol !== 'srt') {
|
||||
const key = await prisma.streamKey.findFirst({
|
||||
where: {
|
||||
key: password,
|
||||
},
|
||||
include: {
|
||||
channel: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!key) {
|
||||
return new Response('Invalid stream key', { status: 403 });
|
||||
}
|
||||
console.log('Stream key valid for channel:', key.channel.name);
|
||||
}
|
||||
|
||||
return new Response('Request processed', { status: 200 });
|
||||
|
||||
}
|
||||
|
||||
const schema = z.object({
|
||||
user: z.string(),
|
||||
password: z.string(),
|
||||
token: z.string(),
|
||||
ip: z.string(),
|
||||
action: z.enum(['publish', 'read', 'playback', 'api', 'metrics', 'pprof']),
|
||||
path: z.string(),
|
||||
protocol: z.enum(['rtsp', 'rtmp', 'hls', 'webrtc', 'srt']),
|
||||
id: z.string().nullable(),
|
||||
query: z.string(),
|
||||
});
|
||||
@@ -3,7 +3,7 @@
|
||||
import StreamPlayer from '../StreamPlayer/StreamPlayer';
|
||||
import UserInfoCard from '../UserInfoCard/UserInfoCard';
|
||||
import ChatPanel from '../ChatPanel/ChatPanel';
|
||||
import type { StreamInfo, User, Channel } from '@hctv/db';
|
||||
import type { StreamInfo, Channel } from '@hctv/db';
|
||||
import { useIsMobile } from '@/lib/hooks/useMobile';
|
||||
|
||||
export default function LiveStream(props: Props) {
|
||||
|
||||
@@ -49,4 +49,11 @@ services:
|
||||
echo "testing nginx config..."
|
||||
/usr/local/nginx/sbin/nginx -t
|
||||
|
||||
/usr/local/nginx/sbin/nginx -g 'daemon off;'
|
||||
/usr/local/nginx/sbin/nginx -g 'daemon off;'
|
||||
mediamtx:
|
||||
image: bluenviron/mediamtx:latest
|
||||
ports:
|
||||
- 8890:8890/udp
|
||||
- 8891:8888
|
||||
volumes:
|
||||
- ./mediamtx.yml:/mediamtx.yml
|
||||
11
dev/mediamtx.yml
Normal file
11
dev/mediamtx.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
paths:
|
||||
all:
|
||||
source: publisher
|
||||
|
||||
srt: yes
|
||||
srtAddress: :8890
|
||||
|
||||
hls: yes
|
||||
|
||||
authMethod: http
|
||||
authHTTPAddress: http://192.168.1.47:3000/api/mediamtx/publish
|
||||
Reference in New Issue
Block a user