Comparing version 0.0.4 to 0.0.5
156
handlers.js
@@ -1,4 +0,4 @@ | ||
// 2013, Muaz Khan - www.MuazKhan.com | ||
// MIT License - www.WebRTC-Experiment.com/licence | ||
// Experiments - github.com/muaz-khan/WebRTC-Experiment | ||
// Muaz Khan - www.MuazKhan.com | ||
// MIT License - www.WebRTC-Experiment.com/licence | ||
// Experiments - github.com/muaz-khan/WebRTC-Experiment | ||
@@ -36,74 +36,5 @@ var config = require('./config'), | ||
if (isWin) { | ||
// following command tries to merge wav/webm files using ffmpeg | ||
var merger = __dirname + '\\merger.bat'; | ||
var audioFile = __dirname + '\\uploads\\' + files.audio.name; | ||
var videoFile = __dirname + '\\uploads\\' + files.video.name; | ||
var mergedFile = __dirname + '\\uploads\\' + files.audio.name.split('.')[0] + '-merged.webm'; | ||
// if a "directory" has space in its name; below command will fail | ||
// e.g. "c:\\dir name\\uploads" will fail. | ||
// it must be like this: "c:\\dir-name\\uploads" | ||
var command = merger + ', ' + videoFile + " " + audioFile + " " + mergedFile + ''; | ||
var cmd = exec(command, function(error, stdout, stderr) { | ||
if (error) { | ||
console.log(error.stack); | ||
console.log('Error code: ' + error.code); | ||
console.log('Signal received: ' + error.signal); | ||
response.statusCode = 404; | ||
response.end(); | ||
} else { | ||
response.statusCode = 200; | ||
response.writeHead(200, { 'Content-Type': 'application/json' }); | ||
response.end(files.audio.name.split('.')[0] + '-merged.webm'); | ||
// removing audio/video files | ||
fs.unlink(audioFile); | ||
fs.unlink(videoFile); | ||
// auto delete file after 1-minute | ||
setTimeout(function() { | ||
fs.unlink(mergedFile); | ||
}, 60 * 1000); | ||
} | ||
}); | ||
} else { // its probably *nix, assume ffmpeg is available | ||
var audioFile = __dirname + '/uploads/' + files.audio.name; | ||
var videoFile = __dirname + '/uploads/' + files.video.name; | ||
var mergedFile = __dirname + '/uploads/' + files.audio.name.split('.')[0] + '-merged.webm'; | ||
var util = require('util'), | ||
exec = require('child_process').exec; | ||
//child_process = require('child_process'); | ||
var command = "ffmpeg -i " + videoFile + " -i " + audioFile + " -map 0:0 -map 1:0 " + mergedFile; | ||
var child = exec(command, function(error, stdout, stderr){ | ||
stdout ? util.print('stdout: ' + stdout) : null; | ||
stderr ? util.print('stderr: ' + stderr) : null; | ||
if (error) { | ||
console.log('exec error: ' + error); | ||
response.statusCode = 404; | ||
response.end(); | ||
} else { | ||
response.statusCode = 200; | ||
response.writeHead(200, { 'Content-Type': 'application/json' }); | ||
response.end(files.audio.name.split('.')[0] + '-merged.webm'); | ||
// removing audio/video files | ||
fs.unlink(audioFile); | ||
fs.unlink(videoFile); | ||
// auto delete file after 1-minute | ||
setTimeout(function() { | ||
fs.unlink(mergedFile); | ||
}, 60 * 1000); | ||
} | ||
}); | ||
ifWin(response, files); | ||
} else { | ||
ifMac(response, files); | ||
} | ||
@@ -159,4 +90,79 @@ } | ||
function ifWin(response, files) { | ||
// following command tries to merge wav/webm files using ffmpeg | ||
var merger = __dirname + '\\merger.bat'; | ||
var audioFile = __dirname + '\\uploads\\' + files.audio.name; | ||
var videoFile = __dirname + '\\uploads\\' + files.video.name; | ||
var mergedFile = __dirname + '\\uploads\\' + files.audio.name.split('.')[0] + '-merged.webm'; | ||
// if a "directory" has space in its name; below command will fail | ||
// e.g. "c:\\dir name\\uploads" will fail. | ||
// it must be like this: "c:\\dir-name\\uploads" | ||
var command = merger + ', ' + videoFile + " " + audioFile + " " + mergedFile + ''; | ||
var cmd = exec(command, function(error, stdout, stderr) { | ||
if (error) { | ||
console.log(error.stack); | ||
console.log('Error code: ' + error.code); | ||
console.log('Signal received: ' + error.signal); | ||
} else { | ||
response.statusCode = 200; | ||
response.writeHead(200, { 'Content-Type': 'application/json' }); | ||
response.end(files.audio.name.split('.')[0] + '-merged.webm'); | ||
// removing audio/video files | ||
fs.unlink(audioFile); | ||
fs.unlink(videoFile); | ||
// auto delete file after 1-minute | ||
setTimeout(function() { | ||
fs.unlink(mergedFile); | ||
}, 60 * 1000); | ||
} | ||
}); | ||
} | ||
function ifMac(response, files) { | ||
// its probably *nix, assume ffmpeg is available | ||
var audioFile = __dirname + '/uploads/' + files.audio.name; | ||
var videoFile = __dirname + '/uploads/' + files.video.name; | ||
var mergedFile = __dirname + '/uploads/' + files.audio.name.split('.')[0] + '-merged.webm'; | ||
var util = require('util'), | ||
exec = require('child_process').exec; | ||
//child_process = require('child_process'); | ||
var command = "ffmpeg -i " + videoFile + " -i " + audioFile + " -map 0:0 -map 1:0 " + mergedFile; | ||
var child = exec(command, function(error, stdout, stderr){ | ||
stdout ? util.print('stdout: ' + stdout) : null; | ||
stderr ? util.print('stderr: ' + stderr) : null; | ||
if (error) { | ||
console.log('exec error: ' + error); | ||
response.statusCode = 404; | ||
response.end(); | ||
} else { | ||
response.statusCode = 200; | ||
response.writeHead(200, { 'Content-Type': 'application/json' }); | ||
response.end(files.audio.name.split('.')[0] + '-merged.webm'); | ||
// removing audio/video files | ||
fs.unlink(audioFile); | ||
fs.unlink(videoFile); | ||
// auto delete file after 1-minute | ||
setTimeout(function() { | ||
fs.unlink(mergedFile); | ||
}, 60 * 1000); | ||
} | ||
}); | ||
} | ||
exports.home = home; | ||
exports.upload = upload; | ||
exports.serveStatic = serveStatic; |
{ | ||
"name": "recordrtc", | ||
"preferGlobal": true, | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"author": { | ||
@@ -30,3 +30,9 @@ "name": "Muaz Khan", | ||
"ffmpeg", | ||
"audio/video recording" | ||
"audio-recording", | ||
"video-recording", | ||
"gif-recording", | ||
"audio/video recording", | ||
"webp", | ||
"webm", | ||
"wav" | ||
], | ||
@@ -43,4 +49,4 @@ "analyze": false, | ||
"homepage": "https://github.com/muaz-khan/WebRTC-Experiment", | ||
"_id": "recordrtc@0.0.4", | ||
"_id": "recordrtc@0.0.5", | ||
"_from": "recordrtc@" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92680
1270
4