-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ws stream. Adaptive for use as linux service. Create Farm class for many records.
- Loading branch information
Showing
7 changed files
with
191 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Created by Shoom on 04.12.15. | ||
*/ | ||
|
||
(function(){ | ||
var child_process = require('child_process'); | ||
|
||
/** | ||
* Farm of recorders | ||
* @param childFile {string} path to file with child process start | ||
* @param cameras {object} array of cameras configs | ||
* @constructor | ||
*/ | ||
var Farm = function(childFile, cameras){ | ||
var self = this; | ||
this.collection = {}; | ||
|
||
/** | ||
* Spawn child proccess with recorder | ||
* @param conf {object} recorder configuration | ||
* @param name {string} name of recorder | ||
* @param restart {boolean} is restart spawn | ||
*/ | ||
this.spawnChild = function(conf, name, restart){ | ||
var old = this.collection[name]; | ||
if(old){ | ||
if(old.connected){ | ||
old.kill(); | ||
old.disconnect(); | ||
} | ||
delete self.collection[name]; | ||
} | ||
|
||
var child = child_process.spawn("node", | ||
[childFile, name, JSON.stringify(conf)], | ||
{detached: false} | ||
); | ||
|
||
child.stdout.on('data', function (data) { | ||
console.log(name+': ' + data); | ||
}); | ||
|
||
child.stderr.on('data', function (data) { | ||
console.log(name+' ERROR: ' + data); | ||
}); | ||
|
||
child.on('close', function (code) { | ||
console.log(name+' closed: ' + code); | ||
//Restart proccess when him close | ||
self.spawnChild(conf, name, 1); | ||
}); | ||
|
||
if(restart){ | ||
console.log(name+ ' REstarted!'); | ||
}else{ | ||
console.log(name+ ' started!'); | ||
} | ||
|
||
self.collection[name] = child; | ||
}; | ||
|
||
/** | ||
* Initialization | ||
*/ | ||
this.initialize = function(){ | ||
//run | ||
for(var _name in cameras){ | ||
if(cameras.hasOwnProperty(_name)){ | ||
this.spawnChild(cameras[_name], _name); | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
module.exports = Farm; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"front": { | ||
"url": "rtsp://admin:[email protected]/11", | ||
"timeLimit": 60, | ||
"folder": "videos/", | ||
"prefix": "f", | ||
"movieWidth": 1280, | ||
"movieHeight": 720, | ||
"maxDirSize": 20480, | ||
"maxTryReconnect": 15, | ||
"wsPort": 8001 | ||
}, | ||
"back": { | ||
"url": "rtsp://admin:[email protected]/11", | ||
"timeLimit": 60, | ||
"folder": "videos/", | ||
"prefix": "b", | ||
"movieWidth": 1280, | ||
"movieHeight": 720, | ||
"maxDirSize": 20480, | ||
"maxTryReconnect": 15, | ||
"wsPort": 8002 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,31 @@ | |
* Created by Shoom on 02.12.15. | ||
*/ | ||
|
||
var Recorder = require('./../RTSPRecorder'); | ||
var oneCamera = false; | ||
|
||
var rec = new Recorder({ | ||
url: 'rtsp://login:[email protected]/path', | ||
timeLimit: 10, | ||
folder: 'videos/', | ||
prefix: 'vid-', | ||
movieWidth: 1280, | ||
movieHeight: 720, | ||
maxDirSize: 1024*20, | ||
maxTryReconnect: 15 | ||
if(oneCamera){ | ||
var Recorder = require('./../RTSPRecorder'); | ||
|
||
}); | ||
var rec = new Recorder({ | ||
url: 'rtsp://admin:[email protected]/11', | ||
timeLimit: 10, | ||
folder: 'videos/', | ||
prefix: 'vid-', | ||
movieWidth: 1280, | ||
movieHeight: 720, | ||
maxDirSize: 1024*20, | ||
maxTryReconnect: 15 | ||
|
||
rec.initialize().wsStream(8001); | ||
}); | ||
|
||
rec.initialize().wsStream(8001); | ||
}else{ | ||
var RecorderFarm = require('./../RecorderFarm'); | ||
|
||
var farm = new RecorderFarm( | ||
'example/runCamera.js', | ||
require('./cameras.json') | ||
); | ||
|
||
farm.initialize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Created by Shoom on 04.12.15. | ||
*/ | ||
|
||
var Recorder = require('./../RTSPRecorder'); | ||
|
||
var conf = JSON.parse(process.argv[3]); | ||
|
||
new Recorder(conf, process.argv[2]).initialize().wsStream(conf.wsPort); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters