Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mp4Flags: '[movflags=faststart]'
});
}
config.trans = {
ffmpeg: conf.ffmpeg_path,
tasks
};
}
function getLastFile(dir) {
const files = fs.readdirSync(dir);
return files[files.length - 1];
}
const nms = new NodeMediaServer(config);
nms.run();
nms.on('prePublish', (id, StreamPath, args) => {
// eslint-disable-next-line no-console
console.log(
'[NodeEvent on prePublish]',
`id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`
);
});
nms.on('donePublish', (id, StreamPath, args) => {
// eslint-disable-next-line no-console
console.log(
'[NodeEvent on donePublish]',
`id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`
);
allow_origin: '*'
},
trans: {
ffmpeg: '/usr/local/bin/ffmpeg',
tasks: [
{
app: 'live',
ac: 'aac',
mp4: true,
mp4Flags: '[movflags=faststart]'
}
]
}
};
var nms = new NodeMediaServer(nodeMediaServerConfig);
nms.run();
nms.on('getFilePath', (streamPath, oupath, mp4Filename) => {
console.log('---------------- get file path ---------------');
console.log(streamPath);
console.log(oupath);
console.log(mp4Filename);
utils.setMp4FilePath(oupath + '/' + mp4Filename);
});
nms.on('preConnect', (id, args) => {
console.log(
'[NodeEvent on preConnect]',
`id=${id} args=${JSON.stringify(args)}`
);
// let session = nms.getSession(id);
if (conf.ffmpeg_path) {
config["trans"] = {
ffmpeg: conf.ffmpeg_path,
tasks: [
{
app: 'live',
ac: 'aac',
hls: true,
hlsFlags: '[hls_time=1:hls_list_size=2:hls_flags=delete_segments]',
}
]
};
}
const nmcs = new NodeMediaServer(config);
nmcs.run();
nmcs.on('prePublish', (id, StreamPath, args) => {
console.log('[NodeEvent on prePublish]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
});
nmcs.on('donePublish', (id, StreamPath, args) => {
console.log('[NodeEvent on donePublish]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
axios.get(`${config.knzklive.api_endpoint}publish.php?token=${args.token}&live=${StreamPath}&authorization=${config.knzklive.api_key}&mode=done_publish`).then(response => {
console.log('[donePublish]', response);
}).catch(error => {
console.log('[donePublish]', error);
})
});
nmcs.on('postPlay', (id, StreamPath, args) => {
if (sessions[sessionId]) {
console.info('Sending candidate');
var webRtcEndpoint = sessions[sessionId].webRtcEndpoint;
webRtcEndpoint.addIceCandidate(candidate);
}
else {
console.info('Queueing candidate');
if (!candidatesQueue[sessionId]) {
candidatesQueue[sessionId] = [];
}
candidatesQueue[sessionId].push(candidate);
}
}
app.use(express.static(path.join(__dirname, 'static')));
var nms = new NodeMediaServer(rtmp_server_config);
nms.run();
process.on('uncaughtException', function (error) {
console.log(error);
});
const { NodeMediaServer } = require('node-media-server');
const config = {
rtmp: {
port: 1935,
chunk_size: 128,
gop_cache: true,
ping: 60,
ping_timeout: 30
}
};
var nms = new NodeMediaServer(config)
nms.run();