extend get/streams with internal api details

This commit is contained in:
srgooglo 2022-05-12 16:24:46 +02:00
parent 618f951aa2
commit 3acc8cca8b

View File

@ -1,4 +1,5 @@
const ffmpeg = require("@ffmpeg-installer/ffmpeg") const ffmpeg = require("@ffmpeg-installer/ffmpeg")
import lodash from "lodash"
import { Server } from "linebridge/dist/server" import { Server } from "linebridge/dist/server"
import MediaServer from "node-media-server" import MediaServer from "node-media-server"
@ -26,18 +27,20 @@ const MediaServerConfig = {
port: 1000, port: 1000,
allow_origin: '*' allow_origin: '*'
}, },
// trans: { trans: {
// ffmpeg: ffmpeg.path, ffmpeg: ffmpeg.path,
// tasks: [ tasks: [
// { {
// app: "live", app: "live",
// hls: true, hls: true,
// hlsFlags: "[hls_time=2:hls_list_size=3:hls_flags=delete_segments]", hlsFlags: "[hls_time=2:hls_list_size=3:hls_flags=delete_segments]",
// } }
// ] ]
// } }
} }
const internalMediaServerURI = `http://127.0.0.1:${MediaServerConfig.http.port}`
class StreamingServer { class StreamingServer {
IHTTPServer = new Server(HTTPServerConfig) IHTTPServer = new Server(HTTPServerConfig)
@ -139,7 +142,37 @@ class StreamingServer {
return res.json(streams) return res.json(streams)
} }
return res.json(this.Sessions.getPublicStreams()) let streams = this.Sessions.getPublicStreams()
// retrieve streams details from internal media server api
let streamsListDetails = await axios.get(`${internalMediaServerURI}/api/streams`)
streamsListDetails = streamsListDetails.data.live ?? {}
// return only publisher details
streamsListDetails = Object.keys(streamsListDetails).map((streamKey) => {
return {
// filter unwanted properties
...lodash.omit(streamsListDetails[streamKey].publisher, ["stream", "ip"])
}
})
// reduce as an object
streamsListDetails = streamsListDetails.reduce((acc, cur) => {
acc[cur.clientId] = cur
return acc
}, {})
// merge with public streams
streams = streams.map((stream) => {
return {
...stream,
...streamsListDetails[stream.id]
}
})
return res.json(streams)
} }
}, },
"/stream/:mode/:username": { "/stream/:mode/:username": {
@ -163,7 +196,7 @@ class StreamingServer {
switch (mode) { switch (mode) {
case "flv": { case "flv": {
const streamingFLVUri = `http://localhost:${MediaServerConfig.http.port}/live/${streamKey}.flv` const streamingFLVUri = `${internalMediaServerURI}/live/${streamKey}.flv`
// create a stream pipe response using media server api with axios // create a stream pipe response using media server api with axios
const request = await axios.get(streamingFLVUri, { const request = await axios.get(streamingFLVUri, {
@ -185,7 +218,7 @@ class StreamingServer {
} }
case "hls": { case "hls": {
const streamingHLSUri = `http://localhost:${MediaServerConfig.http.port}/live/${streamKey}.m3u8` const streamingHLSUri = `${internalMediaServerURI}/live/${streamKey}.m3u8`
// create a stream pipe response using media server api with axios // create a stream pipe response using media server api with axios
const request = await axios.get(streamingHLSUri, { const request = await axios.get(streamingHLSUri, {