// 生成流地址 const generateStreamUrls = (streamKey, requestHost) => { const host = requestHost || process.env.PUBLIC_SRS_HOST || process.env.SRS_HOST || 'localhost'; const rtmpPort = process.env.PUBLIC_SRS_RTMP_PORT || process.env.SRS_RTMP_PORT || 1935; const httpPort = process.env.PUBLIC_SRS_HTTP_PORT || process.env.SRS_HTTP_PORT || 8080; const ffmpegPath = process.env.FFMPEG_PATH; const embeddedEnabledRaw = process.env.EMBEDDED_MEDIA_SERVER; const embeddedEnabled = embeddedEnabledRaw == null ? true : !['0', 'false', 'off', 'no'].includes(String(embeddedEnabledRaw).toLowerCase()); return { // 推流地址 (给主播用) rtmp: `rtmp://${host}:${rtmpPort}/live`, // 播放地址 (给观众用) flv: `http://${host}:${httpPort}/live/${streamKey}.flv`, hls: embeddedEnabled ? (ffmpegPath ? `http://${host}:${httpPort}/live/${streamKey}/index.m3u8` : null) : `http://${host}:${httpPort}/live/${streamKey}.m3u8` }; }; module.exports = { generateStreamUrls };