27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
// 生成流地址
|
|
const generateStreamUrls = (streamKey, requestHost) => {
|
|
// 优先使用环境变量配置的公网地址
|
|
const host = process.env.PUBLIC_SRS_HOST || requestHost || 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 {
|
|
// 推流地址 (给主播用) - 完整路径包含 streamKey
|
|
rtmp: `rtmp://${host}:${rtmpPort}/live/${streamKey}`,
|
|
|
|
// 播放地址 (给观众用)
|
|
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 };
|