Closed chandrashekar-nallamilli closed 1 year ago
Hi @chandrashekar-nallamilli
As I see it, you create a connection to the vMix instance every second.. This is not desired! Since the library runs a TCP tunnel to the vMix instance, the best practice is to use just one connection.
So instead of your code:
setInterval(async () => {
const vMixConn = new ConnectionTCP('localhost', { debug: true, autoReconnect: true, });
vMixConn.on('connect', (err: any) => { if (err) { console.error(err); return; } console.log('Connected!'); vMixConn.send('XML'); }); vMixConn.on('xml', async (data) => { const xmlDocument = vMixXmlApi.DataParser.parse(data); const xmlInputs = vMixXmlApi.Inputs.extractInputsFromXML(xmlDocument); const inputs = sanitize(vMixXmlApi.Inputs.map(xmlInputs)); console.log(inputs) }); }, 1000);
I would move all the logic out of the setInterval, and inside the on('connect') have the setInterval, which calls vMixConn.send('XML'):
const vMixConn = new ConnectionTCP('localhost', { debug: true, autoReconnect: true, });
vMixConn.on('connect', (err: any) => {
if (err) {
console.error(err);
return;
}
console.log('Connected!');
setInterval(async () => {
vMixConn.send('XML');
}, 1000);
});
vMixConn.on('xml', async (data) => {
const xmlDocument = vMixXmlApi.DataParser.parse(data);
const xmlInputs = vMixXmlApi.Inputs.extractInputsFromXML(xmlDocument);
const inputs = sanitize(vMixXmlApi.Inputs.map(xmlInputs));
console.log(inputs)
});
Thank you it worked 👍🏽
@chandrashekar-nallamilli ?? You reopened the issue. Did you experience any problems??
Hi @jensstigaard is there way to close the connection . Currently i am using ClearAllListners and Shutdown functions. is there a better way to clear ?. I tried off function but never got it going The usecase is when user logged out of the server we should clear all the active connections
What do you mean by "all the active connections"? You should really just have one TCP connection. The function .shutdown() closes the connection.
Hi Yes, I moved the logic to have one connection for the entire application. Closing the issue. thanks for the help
I am trying to get the input state every second , How ever i am not successful in doing so as the socket connection is getting closed. Is there a better way to do this ?
setInterval(async () => { const vMixConn = new ConnectionTCP('localhost', { debug: true, autoReconnect: true, }); vMixConn.on('connect', (err: any) => { if (err) { console.error(err); return; } console.log('Connected!'); vMixConn.send('XML'); }); vMixConn.on('xml', async (data) => { const xmlDocument = vMixXmlApi.DataParser.parse(data); const xmlInputs = vMixXmlApi.Inputs.extractInputsFromXML(xmlDocument); const inputs = sanitize(vMixXmlApi.Inputs.map(xmlInputs)); console.log(inputs) }); }, 1000);
This is the log
[node-vmix] Socket connection closed [node-vmix] Initialising reconnecting procedure...