zhibo/live-streaming/server/utils/streamUrl.js
2025-12-16 15:47:36 +08:00

26 lines
1.0 KiB
JavaScript

// 生成流地址
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 };