Skip to content

Commit

Permalink
simplify example
Browse files Browse the repository at this point in the history
  • Loading branch information
jensstigaard committed Mar 25, 2024
1 parent 831d510 commit f49bc0f
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions examples/connection-tcp/auto-reconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,24 @@
// Import modules from the package
// Note when using as npm dep: swap in: 'node-vmix' instead of '../index'
import { ConnectionTCP } from '../../dist/index'
import { XmlApi } from 'vmix-js-utils'

// Set up vMix connection
const connection = new ConnectionTCP('localhost', { debug: true, autoReconnect: true })

// Register callback on 'xml'-events
// When data is fetched, what to do with it?
// Parse it into easy usable array of objects with input
connection.on('xml', (xmlData: string) => {
// Parse xml content
const xmlContent = XmlApi.DataParser.parse(xmlData)

// Extract input data and
// manipulate to desired format
const inputsRawData = XmlApi.Inputs.extractInputsFromXML(xmlContent)
const inputs = XmlApi.Inputs.map(inputsRawData)

// Now you have a list of inputs
console.log(inputs)
})

// Add on connect listener
connection.on('connect', () => {
console.log('Connected')
console.log('Received connected event clean', connection.connected())
setTimeout(() => {
console.log('Received connected event wrapped', connection.connected())
}, 0)

// As soon as connected, then send request to receive XML state data
connection.send('XML')
})

setInterval(() => {
if(connection.connected()) {
console.log('Connection state now changed to connected')
process.exit(0)
}
}, 100)

0 comments on commit f49bc0f

Please sign in to comment.