diff --git a/packages/server/src/controllers/StreamingController/endpoints/getStreamingProfiles.js b/packages/server/src/controllers/StreamingController/endpoints/getStreamingProfiles.js index e829379e..a4ab3c78 100644 --- a/packages/server/src/controllers/StreamingController/endpoints/getStreamingProfiles.js +++ b/packages/server/src/controllers/StreamingController/endpoints/getStreamingProfiles.js @@ -1,5 +1,6 @@ import { StreamingProfile } from "@models" import NewStreamingProfile from "@services/newStreamingProfile" +import composeStreamingSources from "@utils/compose-streaming-sources" export default { method: "GET", @@ -39,12 +40,7 @@ export default { }) profiles = profiles.map((profile) => { - profile.addresses = { - ingest: process.env.STREAMING_INGEST_SERVER, - hls: `${process.env.STREAMING_API_SERVER}/live/${req.user.username}:${profile._id}/src.m3u8`, - flv: `${process.env.STREAMING_API_SERVER}/live/${req.user.username}:${profile._id}/src.flv`, - aac: `${process.env.STREAMING_API_SERVER}/radio/${req.user.username}:${profile._id}/src.aac`, - } + profile.addresses = composeStreamingSources(req.user.username, profile._id) return profile }) diff --git a/packages/server/src/services/fetchRemoteStreams/index.js b/packages/server/src/services/fetchRemoteStreams/index.js index f94dbff4..6e90c0fd 100644 --- a/packages/server/src/services/fetchRemoteStreams/index.js +++ b/packages/server/src/services/fetchRemoteStreams/index.js @@ -2,8 +2,10 @@ import axios from "axios" import { StreamingCategory, StreamingProfile, User } from "@models" -const streamingServerAPIAddress = process.env.STREAMING_API_SERVER ?? "" +import composeStreamingSources from "@utils/compose-streaming-sources" +import lodash from "lodash" +const streamingServerAPIAddress = process.env.STREAMING_API_SERVER ?? "" const streamingServerAPIUri = `${streamingServerAPIAddress.startsWith("https") ? "https" : "http"}://${streamingServerAPIAddress.split("://")[1]}` export default async (stream_id) => { @@ -55,6 +57,8 @@ export default async (stream_id) => { user = user.toObject() + const sources = composeStreamingSources(user.username, profile._id) + return { profile_id: profile._id, info: profile.info, @@ -64,11 +68,7 @@ export default async (stream_id) => { video, audio, connectedClients: clients ?? 0, - sources: { - hls: `${streamingServerAPIUri}/stream/${user.username}:${profile._id}/src.m3u8`, - flv: `${streamingServerAPIUri}/stream/${user.username}:${profile._id}/src.flv`, - aac: `${streamingServerAPIUri}/stream/${user.username}:${profile._id}/src.aac`, - } + sources: lodash.pick(sources, ["rtmp", "hls", "flv", "aac"]), } }) diff --git a/packages/server/src/utils/compose-streaming-sources/index.js b/packages/server/src/utils/compose-streaming-sources/index.js new file mode 100644 index 00000000..c9e87d28 --- /dev/null +++ b/packages/server/src/utils/compose-streaming-sources/index.js @@ -0,0 +1,15 @@ +const streamingServerAPIAddress = process.env.STREAMING_API_SERVER ?? "" + +const streamingServerAPIUri = `${streamingServerAPIAddress.startsWith("https") ? "https" : "http"}://${streamingServerAPIAddress.split("://")[1]}` + +export default (username, profile_id) => { + const streamId = `${username}${profile_id ? `:${profile_id}` : ""}` + + return { + ingest: process.env.STREAMING_INGEST_SERVER, + rtmp: `${streamingServerAPIUri}/${streamId}`, + hls: `${streamingServerAPIUri}/stream/${streamId}/src.m3u8`, + flv: `${streamingServerAPIUri}/stream/${streamId}/src.flv`, + aac: `${streamingServerAPIUri}/stream/${streamId}/src.aac`, + } +} \ No newline at end of file