This repository has been archived on 2021-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
eltelive/eltelive-new/config/media_server.js

26 lines
837 B
JavaScript

const NodeMediaServer = require('node-media-server'),
config = require('./config');
const User = require('../model/user');
nms = new NodeMediaServer(config);
// Check if the stream key used to watch the stream exists in the database or not
nms.on('prePublish', async (id, StreamPath, args) => {
let stream_key = getStreamKeyFromStreamPath(StreamPath);
console.log('[NodeEvent on prePublish]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
User.findOne({stream_key: stream_key}, (err, user) => {
if (!err) {
if (!user) {
let session = nms.getSession(id);
session.reject();
}
}
});
});
const getStreamKeyFromStreamPath = (path) => {
let parts = path.split('/');
return parts[parts.length - 1];
};
module.exports = nms;