respectTheCode / node-caspar-cg

CasparCG interface for node.js
MIT License
46 stars 28 forks source link

Multiple instances of the CasparCG object seems to collide. #15

Open coral opened 11 years ago

coral commented 11 years ago

Recently did a project where I had to use multiple servers. The node library seems to collide when setting up multiple objects with different configs. It only uses the last set object and writes everything to that.

Will post code later today.

respectTheCode commented 11 years ago

Looks like the net client is scoped incorrectly. I only have one box at the moment so I hadn't noticed. Should be an easy fix. I'll take a look.

coral commented 11 years ago

Ah! I am trying to find the bug right now in the code.

respectTheCode commented 11 years ago

I wrote a fix but haven't had a chance to test it. The problem is that the net client is not part of the instance and opening a second connection replaces the first one. The first connection is still open but nothing is referencing it.

coral commented 11 years ago

I can test the fix tomorrow for you!

coral commented 11 years ago

I am getting the following after a while:

/var/www/node/node_modules/caspar-cg/lib/connection.js:151 this.client.write(commandQueue[0].cmd); ^ TypeError: Cannot call method 'write' of undefined at finishedCommand (/var/www/node/node_modules/caspar-cg/lib/connection.js:151:16) at Socket. (/var/www/node/node_modules/caspar-cg/lib/connection.js:222:4) at Socket.EventEmitter.emit (events.js:95:17) at Socket. (_streamreadable.js:699:14) at Socket.EventEmitter.emit (events.js:92:17) at emitReadable (_stream_readable.js:382:10) at emitReadable (_stream_readable.js:377:5) at readableAddChunk (_stream_readable.js:142:7) at Socket.Readable.push (_stream_readable.js:112:10) at TCP.onread (net.js:511:21)

respectTheCode commented 11 years ago

I looked over the code and found a couple of places that were using this instead of self. None of them should have caused a problem though. I just pushed a commit that fixes those.

If you turn on the debug option it will log most everything that happens. Can you post what is logged when this happens?

coral commented 11 years ago

Seems to work with the new commit by some reason??? I don't get the error after fetching it.

coral commented 11 years ago

Did this simple test and doesn't seem to work :(

var CasparCG = require("caspar-cg"); var async = require("async"); var io = require('socket.io').listen(3000);

ccg = new CasparCG({ host: "10.76.255.25", port: 5250, debug: true });

ccg_asd = new CasparCG({ host: "10.76.255.181", port: 5250, debug: true });

io.sockets.on('connection', function (socket) {

ccg.connect(function () {
    socket.emit('control');

});

ccg_asd.connect(function () {
    socket.emit('control2');

});

socket.on('key', function (data) {

    var data = "<templateData>" +
    "<componentData id=\\\"keyCode\\\"><data id=\\\"number\\\" value=\\\"" + data.code + "\\\" /></componentData>"+
    "</templateData>";
    ccg.updateTemplateData("1-1", data);
    ccg_svt.updateTemplateData("1-1", data);

});

});

Both connect to 181.