rtsp client connection

This commit is contained in:
Hemanth 2025-06-26 23:43:39 +05:30
parent 10fd6ede1e
commit aaaeec1efd
3 changed files with 59 additions and 0 deletions

View file

@ -133,6 +133,7 @@
"qs": "~6.10.4", "qs": "~6.10.4",
"redbean-node": "~0.3.0", "redbean-node": "~0.3.0",
"redis": "~4.5.1", "redis": "~4.5.1",
"rtsp-client": "^1.4.5",
"semver": "~7.5.4", "semver": "~7.5.4",
"socket.io": "~4.8.0", "socket.io": "~4.8.0",
"socket.io-client": "~4.8.0", "socket.io-client": "~4.8.0",

View file

@ -0,0 +1,56 @@
const RTSPClient = require("rtsp-client");
const { log, UP, DOWN } = require("../../src/util");
class RtspMonitorType {
name = "rtsp";
/**
* @param {Object} monitor - monitor config containing rtspUrl and timeout
* @param {Object} heartbeat - object to update with status and message
*/
async check(monitor, heartbeat) {
const url = monitor.rtspUrl;
const timeoutMs = (monitor.timeout || 10) * 1000;
heartbeat.status = DOWN;
heartbeat.msg = "Starting RTSP stream check...";
if (!url || !url.startsWith("rtsp://")) {
heartbeat.status = DOWN;
heartbeat.msg = "Invalid RTSP URL";
return;
}
const client = new RTSPClient();
// Timeout promise to kill hanging connections
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error("RTSP connection timed out")), timeoutMs)
);
try {
// Use Promise.race to enforce timeout
await Promise.race([
(async () => {
await client.connect(url);
const describe = await client.describe();
await client.close();
heartbeat.status = UP;
heartbeat.msg = "RTSP stream is accessible";
})(),
timeoutPromise,
]);
} catch (error) {
heartbeat.status = DOWN;
heartbeat.msg = `Error: ${error.message}`;
log.debug("monitor", `[${monitor.name}] RTSP check failed: ${error.message}`);
try {
await client.close();
} catch {}
}
}
}
module.exports = {
RtspMonitorType,
};

View file

@ -119,6 +119,7 @@ class UptimeKumaServer {
UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType(); UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType();
UptimeKumaServer.monitorTypeList["rabbitmq"] = new RabbitMqMonitorType(); UptimeKumaServer.monitorTypeList["rabbitmq"] = new RabbitMqMonitorType();
UptimeKumaServer.monitorTypeList["manual"] = new ManualMonitorType(); UptimeKumaServer.monitorTypeList["manual"] = new ManualMonitorType();
UptimeKumaServer.monitorTypeList["rtsp"] = new RtspMonitorType();
// Allow all CORS origins (polling) in development // Allow all CORS origins (polling) in development
let cors = undefined; let cors = undefined;
@ -560,4 +561,5 @@ const { SNMPMonitorType } = require("./monitor-types/snmp");
const { MongodbMonitorType } = require("./monitor-types/mongodb"); const { MongodbMonitorType } = require("./monitor-types/mongodb");
const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq"); const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq");
const { ManualMonitorType } = require("./monitor-types/manual"); const { ManualMonitorType } = require("./monitor-types/manual");
const {RtspMonitorType}= require("./monitor-types/RtspMonitorType")
const Monitor = require("./model/monitor"); const Monitor = require("./model/monitor");