2017-05-27 2 views
0

カメラモジュールから連続してカメラ画像をストリーミングしようとしています。前回のスポーンが終了したら、別のスポーンを起動する方法を知っていますか? 現在、「exit」イベントが子プロセスによって実行されると、「startCamera」関数が見つからないというエラーが発生しています。エクスポートからループでnodejsを生成する方法

var spawn = require('child_process').spawn; 
module.exports = { 
cameraProcess: null, 
startCamera: function() { 
    var isWin = /^win/.test(process.platform); 
    var path = require('path'); 
    if (isWin) { 
     this.cameraProcess = spawn(path.join(__dirname, 'vfwgrab', 'VFWGrab.exe')); 
    } else { 
     var args = ["-w", "640", "-h", "480", "-o", "./public/stream/stream.jpg", "-t", "999999999", "-tl", "2000"]; 
     this.cameraProcess = spawn('raspistill', args); 
    } 
    this.cameraProcess.on('exit', this.loopCamera); 
}, 
loopCamera: function (code) { 
    this.startCamera(); //start the next spawn once the previous finished 
} 
}; 

答えて

0

今のところ私は、エクスポートから機能を移動し、エクスポートでそれらを参照することでこれを解決しました。これが推奨される方法であれば教えてください。

var spawn = require('child_process').spawn; 
var cameraProcess = null; 
var startCamera = function() { 
    var isWin = /^win/.test(process.platform); 
    var path = require('path'); 
    if (isWin) { 
    this.cameraProcess = spawn(path.join(__dirname, 'vfwgrab', 'VFWGrab.exe')); 
    } else { 
    var args = ["-w", "640", "-h", "480", "-o", "./public/stream/stream.jpg", "-t", "999999999", "-tl", "2000"]; 
    this.cameraProcess = spawn('raspistill', args); 
    } 
    this.cameraProcess.on('exit', loopCamera); 
} 
var loopCamera = function (code) { 
    startCamera(); 
} 
module.exports = { 
    startCamera: startCamera, 
}; 
関連する問題