Code Monkey home page Code Monkey logo

node-vmix's Introduction

node-vmix

Node.js vMix API utility to enable easy setup to communicate with vMix instance via TCP socket or HTTP alternatively.

It is recommended to use TCP, however, there is currently not implemented feedback/response. It is possible to implement this yourself if necessary, by analysing the responses, but it is not supported out of the box.

package json version npm version npm downloads

NPM Badge

This code previously were found in the vmix-js-utils but are now branched out in its own package to enable usage of the vmix-js-utils to be used in a clean frontend environment (non-Node.js), and also to give a better experience for the users. Are you looking for vMix utility for your js frontend? Take a look at vmix-js-utils for more info. Both packages are available with npm - see my npm profile.

Purpose

node-vmix consists of two modules - one for TCP connection, one for HTTP. Each can be used on its own, but usually it makes more sense to make it interplay with some of the other modules. The modules are coded as classes, meaning that they are constructed with specific parameters, e.g. that the instanciation of a connection needs a host and a port.

Quick start

const { ConnectionTCP } = require('node-vmix')

const connection = new ConnectionTCP('localhost')

// Listener for xml state data
connection.on('xml', xmlData => {
 // Your logic here!
 // See example to parse the XML correctly
})

// Listener for tally
connection.on('tally', tally => {
 // Your logic here!
})

// Listener for data such as tally
connection.on('data', data => {
 // Your logic here!
})

connection.on('connect', () => {
  // Request vMix API XML state by sending message 'XML'
  connection.send('XML')

  // Request vMix tally info by sending message 'TALLY'
  connection.send('TALLY')
})

Note: One should check whether the connection is actually established before attempting sending message to the socket.

Documentation

Please visit the documentation here: https://jensstigaard.github.io/node-vmix/.

The documentation includes definition and description of classes and type.

Installation and use

The utilities are published at npmjs as a package for Node.js, meaning that you can easily add the utilities as a dependency in your project using npm.

npm install node-vmix --save
# or 'yarn add node-vmix'

In your code the simplest way to import the modules is the following:

const { Connection } = require('node-vmix')
// or ES6 import syntax:  import { Connection } from 'node-vmix'

const connection1 = new Connection('localhost')
const connection2 = new Connection('192.168.1.50')

connection1.send({ Function: 'Cut' })
connection2.send({ Function: 'Merge' })

You are also able to import all of the modules as a gathered variable, less elegant way:

const vMix = require('node-vmix')

const connection1 = new vMix.Connection('localhost')
const connection2 = new vMix.Connection('192.168.1.50')

connection1.send({ Function: 'Cut' })
connection2.send({ Function: 'Merge' })

Examples and use

Electron example

Looking for a full blown example project? See the repositories:

These apps are using this library for vMix connection. They are built with ElectronJS and can be compiled for both Windows, Mac or Linux platforms.

Code snippet examples

Here are some basic example of how to use the library

Connection TCP

Legacy:

Contribution

You are more than welcome to contribute to the repository. Please read the CONTRIBUTION guide

Contributors

Multiple individuals have contributed to the project - thanks to you all!

Roadmap

  • TCP command sender: feedback/responses on commands sent
  • More tests
  • Perhaps more functionality

node-vmix's People

Contributors

cyraxx avatar dependabot[bot] avatar gamerxp avatar grray avatar ianshade avatar jensstigaard avatar jmhernandez-blizz avatar splat1 avatar stjernholmco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-vmix's Issues

acts event is never called

When register listener for event acts it will never been called.

Testing with

connection.send('ACTS Input')

connection.on('acts', console.log); // This will never been called

After some digging I've found vMix 24 will Reply with ACTS not ACTIVATORS but this module seem only expecting ACTIVATORS

`vMix.connected()` returns `false` in `connect` listener callback

Hi @jensstigaard,
Thanks for this library. It makes interfacing with vMix very easy.
I did find a small bug though:

this.vMix = new ConnectionTCP(this.settings?.ip || "localhost", { autoReconnect: true });
this.vMix.on("connect", () => { 
    console.log(this.vMix.connected())
}

prints false. The reason I found this is that I do some initialization stuff once vMix is connected. Everything I send to vMix goes through a custom send function which does some logging, then checks whether it is actually connected to vMix and if yes, sends the data.
However, I need to skip this check when I'm inside the callback because the connected() method returns false there.

Best regards

NPM package broken

The version 1.3.3 and 1.3.2 as published to NPM seems to be missing the correct build step before publishing.

First time using the package, I could not get simple commands to work using latest vMix version and a fresh npm install node-vmix

Using debug option on node-vmix and diving in to the code in the build directory, there is a bug which prevents the function name to be passed into the final command string using TCP connection. This part of the code seems to already be completely rewritten, so I have not bothered to look further.

Running the NPM build script seems to resolve everything, so I would conclude that the code in the build directory in the NPM package is not actually a current build.

Need to be able to remove listeners

My use-case requires adding and removing listeners in order to resolve/reject promises. Without the ability to remove listeners, I end up with a memory leak.

`disconnect` event is never called

CUSTOM_LISTENER_TYPES in connection-tcp.ts includes an event type disconnect.

This event doesn't seem to ever be called. I'm not sure what the intention behind the event was but I suspect it might not be actually needed as the socket's close event can be used instead.

Seems like ApiDataParser and InputMapper is absent in repository?

Hi! I'm trying to run examples/read-state-basic.js, and getting an error

const xmlContent = ApiDataParser.parse(xmlData);
                                   ^

TypeError: Cannot read property 'parse' of undefined

Seems like ApiDataParser and InputMapper were not added to repository.
I did import like this
const { ApiDataParser, ConnectionTCP, InputMapper } = require('node-vmix').default;

Is it possible to poll for the inputs

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...

Not connecting to vMix

I can't get my app to connect to vMix over ConnectionTCP class.
I copied the code from the Quick Start section, but no events are getting executed.

When turning on debug mode I get the following output:

[node-vmix] Instanciating TCP socket to vMix instance localhost
[node-vmix] Received host localhost
[node-vmix] Received options {
  debug: true,
  debugBuffers: true
}
[node-vmix] -----
[node-vmix] Attempting to establish TCP socket connection to vMix instance localhost:8099
[node-vmix] TCP socket connection to vMix instance was already established... localhost:8099

It says that the connection is established, but non of the events are getting fired. It gives the same output even when vMix is closed.

If I try to send a command like connection.send({ Function: 'Cut' }) the following error occurs:

Error [ERR_SOCKET_CLOSED]: Socket is closed
    at Socket._writeGeneric (net.js:775:8)
    at Socket._write (net.js:797:8)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at Socket.Writable.write (internal/streams/writable.js:303:10)
    at ConnectionTCP._sendMessageToSocket (.\node_modules\node-vmix\src\modules\connection-tcp.ts:697:22)
    at ConnectionTCP.send (.\node_modules\node-vmix\src\modules\connection-tcp.ts:769:21)
    at Object.<anonymous> (.\src\index.ts:39:12)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Module.m._compile (.\node_modules\ts-node\src\index.ts:1056:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

Happened when using Typescript and also when using Javascript as language.

Of course I checked that vMix is up & running. Had no issues trying to connect to vMix with ncat client.
OS: Win10

MaxListenersExceededWarning: Possible EventEmitter memory leak detected.

Hi @jensstigaard,
I think I found another small bug: The autoReconnect option seems to add a new connect listener every time it tries to open the socket.
It is quite simple to reproduce: Just create a vMix instance like so:

this.vMix = new ConnectionTCP("localhost", { autoReconnect: true, debug: false, debugBuffers: false });

but don't start vMix on your machine.

After about a minute or two, you get

node:22384) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connect listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)

and if node was started with the --trace-warnings flag, you get

(node:21584) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connect listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:465:17)
    at Socket.addListener (node:events:487:10)
    at Socket.Readable.on (node:internal/streams/readable:876:35)
    at Socket.once (node:events:531:8)
    at Socket.connect (node:net:976:10)
    at ConnectionTCP.connect (A:\_Source\GLUE\packages\Glue\node_modules\node-vmix\src\modules\connection-tcp.ts:757:22)
    at Timeout._onTimeout (A:\_Source\GLUE\packages\Glue\node_modules\node-vmix\src\modules\connection-tcp.ts:249:22)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

If you need more info or are unable to reproduce this, just let me know.

Best regards

Myserious Log Entries 1200001

Hello!

First let me say thank you for this amazing module, it has helped me immensely!

I do have a question for you. One unusual behavior I am seeing is that when I sent a tally request using connection.send('TALLY'), my console logs the number 1200001

, even though i do not have any console.log() statement attached to my connection.on('tally) or connection.on('data) functions. Any idea where this might be generating from? I am polling tally frequently and am cluttering my logs a bit. Code is below

Thanks again for this great contribution to the Vmix community!

Best,
Justin

async getTally() { return new Promise((resolve, reject) => { this.connection.on("error", (error) => { console.error("Error", error); reject(error); }); this.connection.on("tally", (tally) => { this.pgmTally = tally.program[0]; // array of program inputs counts overlays, so only taking first entry. resolve(this.pgmTally); }); this.connection.send("TALLY"); }); }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.