I am trying to send update to the client from my server side function using node js (express). I have a function that converts an mp4 file to flac. I want to send two updates to the client. 1. when the conversion start (send "blah blah blah") 2. when the file has been converted(send "blah blah blah")
The first code is my function (convertYoutubeVideo.js) and the second code is (app.js). Please help.
function convertToFlac(videoId) {
var proc = ffmpeg(videoId + '.mp4')
.format('flac')
.audioFrequency(16000)
.save(videoId + '.flac')
.on('start', function (err) {
console.log("Converting video to flac");
//Code to send Notification to user
})
.on('error', function (err) {
console.log("Error Wile Converting Video");
//Code to send Notification to user
})
.on('end', function () {
console.log("Video has been converted to .flac");
//Code to send Notification to user
});
}
module.exports.convertToFlac = convertToFlac;
var youtube = require('./downloadYoutubeVideo');
var convert = require('./convertYoutubeVideo');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
app.post('/form', function (req, res) {
convert.convertToFlac("some file name")
res.send("Thank you we will update you on the Progress");
res.end();
});
via Kev
No comments:
Post a Comment