8ef43029d5
- generate-config.sh: add --with-nginx flag handling; when enabled, set NEXT_PUBLIC_API_URL empty to use same-origin /api and /socket.io; add BACKEND_INTERNAL_URL for SSR/internal fetch; adjust lan-tls HTTPS (8443) and TLS generation policy - deploy.sh: show only valid access URLs when Nginx is enabled (gateway URLs), avoid misleading :3002/:3001 entries - frontend (env/webrtc): return mutable transports [websocket,polling]; use empty signaling server for same-origin; comments in English - frontend (next.config): support NEXT_IMAGE_UNOPTIMIZED to turn off image optimization in Docker - frontend (health): prefer BACKEND_INTERNAL_URL for internal health checks, fallback to public URL/localhost - docker-compose + Dockerfile(frontend): pass NEXT_IMAGE_UNOPTIMIZED and BACKEND_INTERNAL_URL envs
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
import { ManagerOptions, SocketOptions } from "socket.io-client";
|
|
|
|
export const config = {
|
|
API_URL: process.env.NEXT_PUBLIC_API_URL!,
|
|
USE_HTTPS: process.env.NODE_ENV !== "development",
|
|
USE_CREDENTIALS: process.env.NODE_ENV !== "development",
|
|
|
|
// Optional: Self-hosted TURN server settings
|
|
// To enable, set NEXT_PUBLIC_TURN_HOST, NEXT_PUBLIC_TURN_USERNAME, and NEXT_PUBLIC_TURN_PASSWORD in your .env file
|
|
TURN_HOST: process.env.NEXT_PUBLIC_TURN_HOST,
|
|
TURN_USERNAME: process.env.NEXT_PUBLIC_TURN_USERNAME,
|
|
TURN_CREDENTIAL: process.env.NEXT_PUBLIC_TURN_PASSWORD,
|
|
};
|
|
|
|
export const getIceServers = () => {
|
|
const iceServers: RTCIceServer[] = [];
|
|
|
|
if (config.USE_HTTPS) {
|
|
// Check if TURN server configuration is complete
|
|
if (!config.TURN_HOST || !config.TURN_USERNAME || !config.TURN_CREDENTIAL) {
|
|
console.warn(
|
|
"TURN server configuration incomplete in HTTPS environment. " +
|
|
"Please set NEXT_PUBLIC_TURN_HOST, NEXT_PUBLIC_TURN_USERNAME, and NEXT_PUBLIC_TURN_PASSWORD " +
|
|
"environment variables for better connectivity. Falling back to Google STUN server."
|
|
);
|
|
|
|
// Fallback to Google STUN server
|
|
iceServers.push({
|
|
urls: "stun:stun.l.google.com:19302",
|
|
});
|
|
} else {
|
|
// Add self-hosted STUN and TURN servers
|
|
iceServers.push(
|
|
{
|
|
urls: `stun:${config.TURN_HOST}:3478`,
|
|
},
|
|
{
|
|
urls: `turns:${config.TURN_HOST}:443`,
|
|
username: config.TURN_USERNAME,
|
|
credential: config.TURN_CREDENTIAL,
|
|
},
|
|
{
|
|
urls: `turn:${config.TURN_HOST}:3478`,
|
|
username: config.TURN_USERNAME,
|
|
credential: config.TURN_CREDENTIAL,
|
|
}
|
|
);
|
|
}
|
|
} else {
|
|
// Development environment uses Google's public STUN server
|
|
iceServers.push({
|
|
urls: "stun:stun.l.google.com:19302",
|
|
});
|
|
}
|
|
|
|
return iceServers;
|
|
};
|
|
|
|
export const getSocketOptions = (): Partial<ManagerOptions & SocketOptions> => {
|
|
// Allow polling fallback; do not force "secure" here — protocol will be inferred
|
|
return {
|
|
path: "/socket.io/",
|
|
transports: ["websocket", "polling"],
|
|
};
|
|
};
|
|
|
|
export const getFetchOptions = (options: RequestInit = {}): RequestInit => {
|
|
const defaultOptions: RequestInit = {
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
...options,
|
|
};
|
|
|
|
if (config.USE_CREDENTIALS) {
|
|
defaultOptions.credentials = "include";
|
|
}
|
|
|
|
return defaultOptions;
|
|
};
|