mirror of
https://github.com/SrIzan10/hctv.git
synced 2026-06-06 00:56:56 +00:00
fix: set next public after build time
This commit is contained in:
@@ -53,6 +53,7 @@ import { ChannelSelect } from '@/components/app/ChannelSelect/ChannelSelect';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import { useConfirm } from '@omit/react-confirm-dialog';
|
||||
import { MEDIAMTX_INGEST_ROUTE } from '@/lib/env';
|
||||
|
||||
interface ChannelSettingsClientProps {
|
||||
channel: Channel & {
|
||||
@@ -136,7 +137,7 @@ export default function ChannelSettingsClient({
|
||||
toast.error('Stream key not available');
|
||||
return '';
|
||||
}
|
||||
return `srt://${process.env.NEXT_PUBLIC_MEDIAMTX_INGEST_ROUTE}?streamid=publish:${channel.name}:thisusernameislongonpurposesoyoudontaccidentallyleakyourstreamkey:${streamKey}&pkt_size=1316`;
|
||||
return `srt://${MEDIAMTX_INGEST_ROUTE}?streamid=publish:${channel.name}:thisusernameislongonpurposesoyoudontaccidentallyleakyourstreamkey:${streamKey}&pkt_size=1316`;
|
||||
};
|
||||
|
||||
const copyStreamUrl = async () => {
|
||||
|
||||
@@ -2,8 +2,22 @@ import { NuqsAdapter } from 'nuqs/adapters/next/app';
|
||||
import './globals.css';
|
||||
|
||||
export default function Layout({ children }: { children: React.ReactNode }) {
|
||||
const publicEnv = Object.keys(process.env).reduce((acc, key) => {
|
||||
if (key.startsWith('NEXT_PUBLIC_')) {
|
||||
acc[key] = process.env[key];
|
||||
}
|
||||
return acc;
|
||||
}, {} as Record<string, string | undefined>);
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `window.__ENV = ${JSON.stringify(publicEnv)}`,
|
||||
}}
|
||||
/>
|
||||
</head>
|
||||
<NuqsAdapter>
|
||||
<body>
|
||||
<main>{children}</main>
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from 'media-chrome/react';
|
||||
import HlsVideo from 'hls-video-element/react';
|
||||
import { useSession } from '@/lib/providers/SessionProvider';
|
||||
import { MEDIAMTX_URL } from '@/lib/env';
|
||||
|
||||
export default function StreamPlayer() {
|
||||
const { username } = useParams();
|
||||
@@ -37,7 +38,7 @@ export default function StreamPlayer() {
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
video.src = `${process.env.NEXT_PUBLIC_MEDIAMTX_URL}/${username}/index.m3u8`;
|
||||
video.src = `${MEDIAMTX_URL}/${username}/index.m3u8`;
|
||||
}
|
||||
|
||||
return () => {
|
||||
|
||||
10
apps/web/src/lib/env.ts
Normal file
10
apps/web/src/lib/env.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export const getEnv = (key: string): string | undefined => {
|
||||
if (typeof window !== 'undefined') {
|
||||
// @ts-ignore
|
||||
return window.__ENV?.[key];
|
||||
}
|
||||
return process.env[key];
|
||||
};
|
||||
|
||||
export const MEDIAMTX_URL = getEnv('NEXT_PUBLIC_MEDIAMTX_URL');
|
||||
export const MEDIAMTX_INGEST_ROUTE = getEnv('NEXT_PUBLIC_MEDIAMTX_INGEST_ROUTE');
|
||||
@@ -3,6 +3,7 @@ import { getRedisConnection } from '@hctv/db';
|
||||
import { promisify } from 'node:util';
|
||||
import { existsSync } from 'node:fs';
|
||||
import { exec as execCallback } from 'node:child_process';
|
||||
import { MEDIAMTX_URL } from '@/lib/env';
|
||||
const pExec = promisify(execCallback);
|
||||
|
||||
const globalForWorker = global as unknown as {
|
||||
@@ -26,7 +27,7 @@ export async function registerThumbnailWorker(): Promise<void> {
|
||||
try {
|
||||
// this is totally unnecessary, but i'll keep it for security purposes.
|
||||
const name = job.data.name.replace(/[^a-zA-Z0-9]/g, '_');
|
||||
const m3u8location = `${process.env.NEXT_PUBLIC_MEDIAMTX_URL}/${name}/index.m3u8`;
|
||||
const m3u8location = `${MEDIAMTX_URL}/${name}/index.m3u8`;
|
||||
const thumbDir = '/dev/shm/hctv-thumb';
|
||||
|
||||
if (!existsSync(thumbDir)) {
|
||||
|
||||
Reference in New Issue
Block a user