-
Notifications
You must be signed in to change notification settings - Fork 0
/
srs.cjs
82 lines (68 loc) · 2.43 KB
/
srs.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const axios = require('axios');
const _ = require('lodash');
const RTMP_STAT_UPDATE_INTERVAL_MS = 2000
module.exports.SrsManager = class {
srsHost = null;
streams = [];
streamListMsg = "None";
#rtmpInterval = null;
#priorityUpdateCallback = null;
#srsApiUrl = null;
#updateRtmpStreams() {
axios.get(this.#srsApiUrl)
.then(
(response) => {
if (!response.data || !response.data.streams) {
return;
}
let streams = [];
for (const stream of response.data.streams) {
if (stream.publish.active !== false) {
streams.push({
app: stream.app,
key: stream.name,
link: `https://aniclover.com/vlc?url=rtmp://lb.aniclover.com/${stream.app}/${stream.name}`,
// conns: stream.clients,
// recv: stream.kbps.recv_30s+"kb/s",
// video: (stream.video ? `${stream.video.codec}/${stream.video.profile}${stream.video.level}/${stream.video.width}x${stream.video.height}` : ''),
// audio: (stream.audio ? `${stream.audio.codec}/${stream.audio.sample_rate}/${stream.audio.channel}ch/${stream.audio.profile}` : ''),
// id: stream.id
});
}
}
streams = streams.sort(function (a,b) {
return a.app - b.app;
});
if (_.isEqual(streams, this.streams)) {
// Response is the same as what we last processed, so don't do anything
return
}
this.streams = streams;
if (this.streams.length < 1) {
this.streamListMsg = "None"
} else {
this.streamListMsg = ""
for (const stream of this.streams) {
this.streamListMsg += `[${stream.app}/${stream.key}](${stream.link})\n`
}
}
this.#priorityUpdate();
},
(error) => {
console.log("Error connecting to SRS RTMP server at "+this.#srsApiUrl)
}
)
}
#priorityUpdate() {
if (this.#priorityUpdateCallback === null) {
return;
}
this.#priorityUpdateCallback()
}
constructor(srsHost, priorityUpdateFunc) {
this.srsHost = srsHost;
this.#priorityUpdateCallback = priorityUpdateFunc
this.#srsApiUrl = `http://${srsHost}/api/v1/streams/`
this.#rtmpInterval = setInterval( () => { this.#updateRtmpStreams() }, RTMP_STAT_UPDATE_INTERVAL_MS)
}
}