【发布时间】:2014-04-28 22:41:52
【问题描述】:
我正在使用 Node JS 开发一个服务器,我在其中创建多个使用 chrome 打开 html 的子节点。
app.post('/exeVideo', function(req,res) {
child = child_process.spawn('chromium-browser', ['RaspMediaVideos.html']);
child.on('exit', function() {
res.writeHead(200,"0K",{'Content-Type': 'text/plain'});
res.end();
});
});
这个 Html 有一个与服务器的 socket.io 通信:
io.on("connection", function ( socket ){
app.post('/playVideo', function(req,res) {
socket.emit("playvideo");
res.writeHead(200,"0K",{'Content-Type': 'text/plain'});
res.end();
});
app.post('/pauseVideo', function(req,res) {
socket.emit("pausevideo");
res.writeHead(200,"0K",{'Content-Type': 'text/plain'});
res.end();
});
我的问题是,如果我使用上面显示的代码创建 2 个 childs_process,两个 chrome 窗口都可以正常执行,但只有第一个窗口正在处理 socket.io 事件(效果很好)。第二个不响应任何事件:S 我怎样才能让所有孩子都捕获 socket.io 事件?
这里是html处理事件的脚本:
var socket = io.connect('http://localhost:3434');
socket.on("pausevideo", function() {
player.pause();
});
socket.on("playvideo", function() {
player.play();
});
感谢您的宝贵时间。
【问题讨论】: