nrkno / sofie-emberplus-connection

Ember+ Connection: A Part of the Sofie TV Studio Automation System
https://github.com/nrkno/Sofie-TV-automation/
MIT License
20 stars 15 forks source link

Provider #16

Closed mint-dewit closed 4 years ago

mint-dewit commented 4 years ago

This PR adds a provider / server class to the emberplus-connection library.

Usage:

const { EmberServer } = require('emberplus-connection')

const s = new EmberServer(9000) // start server on port 9000

s.onInvocation = (emberFunction, invocation) => {
    // handle function invocations
    return { id: invocation.contents.invocation.id, success: true }
}
s.onSetValue = async (node, value) => {
    // handle setting values
    s.update(node, { value })

    return true
}
s.onMatrixOperation = (matrix, connections) => {
    // handle matrix operations
    for (const connection of Object.values(connections)) {
        s.updateMatrixConnection(matrix, connection)
    }
}

const tree = {
    // create a tree for the provider, see also readme
    ...
}

s.init(tree) // initiate the provider with the tree