Make streaming work & much more elegant

This commit is contained in:
2022-04-17 10:12:50 -04:00
parent 76c8876bd8
commit 507d4232f0
14 changed files with 2373 additions and 214 deletions

View File

@@ -10,7 +10,6 @@ router.get('/', getById);
router.put('/', update);
router.delete('/', _delete);
router.post('/osd', _osd);
router.post('/stream', _stream);
module.exports = router;
@@ -49,10 +48,3 @@ function _osd(req, res, next) {
.then((socket) => res.json(socket))
.catch(err => next(err));
}
function _stream(req, res, next) {
console.log("Stream Requester ip: " + req.ip);
cameraService.stream(req.body)
.then((streamPort) => res.json(streamPort))
.catch(err => next(err));
}

View File

@@ -1,6 +1,5 @@
/*jshint esversion: 6 */
const path = require('path');
const Stream = require('../stream/videoStream');
const db = require(path.resolve(__dirname, '../_helpers/db.js'));
const mongoose = require('mongoose');
const cameraHelper = require(path.resolve(__dirname, '../_helpers/cameraHelper.js'));
@@ -13,8 +12,7 @@ module.exports = {
getById: _getById,
update: _update,
delete: _delete,
osd: _osd,
stream: _stream
osd: _osd
};
async function _getAll() {
@@ -101,27 +99,3 @@ async function _osd({id, option}) {
}
return await socket.sendCmd(id, osdHex);
}
async function _stream({id, width = 1920, height = 1080}) {
const camera = await Camera.findById(id).lean();
// In case a seperate user wants to reach same camera stream
let inUse;
try {
inUse = await cameraHelper.checkPortUse(camera.streamPort);
} catch(err) {
throw err;
}
if (!inUse) {
const stream = new Stream({
name: camera.name || "stream: " + camera.rtsp,
url: 'rtsp://' + camera.rtsp,
port: camera.streamPort,
width: width,
height: height
});
stream.start();
}
return camera.streamPort;
}