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

Subscribe to value changes #26

Open Nico96R opened 1 year ago

Nico96R commented 1 year ago

I've experienced a problem with the subscription to a specific node with a leaf. I've use the following code, slightly adapted from your example.

I do get the node and its child leaf, but when I change the value of the leaf I do not get an update. Am I doing something wrong or is there an error in the implementation. Most likely I'm wrong and forgot something. I've had the same results on the user labels of Lawos PowerCore Sources and on Matrix Labels by Riedels Mediornet. On the Riedel Matrizes the following code worked perfectly. Looking forward to your solution.

import {EmberClient} from "emberplus-connection";
import {FieldFlags} from "emberplus-connection/dist/model/Command";

const client = new EmberClient(IP, 9000);

const initember = async (): Promise<any> => {
    client.on("error", e => {
        console.log(e);
    });
    await client.connect()
// Get Root info
    const req = await client.getDirectory(client.tree)

    return await req.response
}

const testMethod = async (path: string): Promise<any> => {

    const testNode = await client.getElementByPath(path).then(async (node) => {
        console.log("Get Node: \n")
        console.log(await node)
        return (
          await client.getDirectory(await node, FieldFlags.All, (update) => {
                console.log(update)
            }
          )
        ).response
    }).catch(() => console.log(path + ": Node does not exist."))
    return testNode
}

//Riedels Matrix label
initember().then((x) =>
    testMethod("1.2.0.1.1.0").then((x => console.log(x))))
mint-dewit commented 1 year ago

Hi,

I've tried to reproduce against the provider from this library but await client.getElementByPath('1.1.1', (v) => console.log(v.contents.value)) works perfectly fine for me. AfaIk we also use subscriptions in production with a lawo mc2 and a powercore.

Can you provide a pcap file with the socket communication?

Nico96R commented 1 year ago

Thanks for the tip with the callback on a specific leaf with the getElementByPath function. That worked for PowerCore, unfortunately not on Riedels Mediornet. I can send a pcap file on Thursday.

Nico96R commented 1 year ago

I captured the traffic to the "Riedel MicroN" with wireshark. Hopefully that might help you solve my problem. I still get no updates on value changes Ember-Communication-Riedel-Mediornet.pcapng.zip

Nico96R commented 1 year ago

I also caputured the Traffic to "Lawo's PowerCore". The callback in this case works. The used source code now implements your (@baltedewit) recommendation.

import {EmberClient} from "emberplus-connection";

const client = new EmberClient("10.20.33.62", 9001);

const initember = async (): Promise<any> => {
    client.on("error", e => {
        console.log(e);
    });
    await client.connect()
// Get Root info
    const req = await client.getDirectory(client.tree)

    return await req.response
}

const testMethod = async (path: string): Promise<any> => {

    return await client.getElementByPath(path, (v) => console.log("value" in v.contents ? v.contents.value :"not existent"))
}

// Get user label 1 of Source
initember().then(() =>
  testMethod("1.1.2.9.1.1").then((x => console.log(x))))

Ember-Communication-Lawo-Powercore.pcapng.zip

Nico96R commented 1 year ago

@baltedewit did my provided pcap files help you find my error? If not i can try to produce another one. Thanks a lot!

Nico96R commented 1 year ago

Made further tests with the original Lawo implementation in C. There does the GetDirectory work for value changes of the labels.

Nico96R commented 1 year ago

And I still have troubles querying the PowerCore Matrix. I get the following error: error.txt used this source code:

import {EmberClient} from "emberplus-connection";

const client = new EmberClient("10.20.33.62", 9001);

const initember = async (): Promise<any> => {
    client.on("error", e => {
        console.log(e);
    });
    await client.connect()
// Get Root info
    const req = await client.getDirectory(client.tree)

    return await req.response
}

const testMethod = async (path: string): Promise<any> => {

    return await client.getElementByPath(path, (v) => console.log(v)).then( node => {
        client.subscribe(node, n => console.log(n))
    })
}

//Path to PowerCore Matrix
initember().then(() =>
  testMethod("1.3.1").then((x => console.log(x))))

could you verify this behavior in your environment?

mint-dewit commented 1 year ago

Sorry, I haven't been able to look at this yet. Hopefully soon! There has been some changes in the master regarding communication with the riedel stuff on the master branch, perhaps these may be related?

boristian commented 11 months ago

Hi, with a build from latest master i am getting the same error when trying to access a matrix node on a DHD device:

Error (InvalidAsn1Error]: Expected Oxa0: got 0x0
at newInvalidAsn1Error (/.../node_modules/asni/lib/ber/errors.js:7:13)
at Reader. readSequence (/.../node_modules/asn1/lib/ber/reader.js:188:11)
at decodeMatrixContents (/.../node_modules/emberplus-connection/dist/encodings/ber/decoder/Matrix.js:142:28)
at decodeMatrix (/.../node_modules/emberplus-connection/dist/encodings/ber/decoder/Matrix.js:36:61)
at decodeGenericElement (/.../node_modules/emberplus-connection/dist/encodings/ber/decoder/Tree.js:46:42)
at decodeRootElements (/.../node_modules/emberplus-connection/dist/encodings/ber/decoder/Tree.js:164:24.
at berDecode (/.../node_modules/emberplus-connection/dist/encodings/ber/index.js:59:52)
at S101Codec.<anonymous> (/.../node_modules/emberplus-connection/dist/Ember/Socket/S101Socket.js:32:48)
at S101Codec.emit (node: events: 513:28)
at S101Codec.handleEmberPacket (/.../node_modules /emberplus-connection/dist/S101/S101Codec.js:151:14)
Nico96R commented 9 months ago

i have the same problem with LAWO vpro8, Riedel micron and still with LAWO PowerCore

mint-dewit commented 9 months ago

@Nico96R is the error you're seeing the same as with the DHD device? (i.e. Expected 0xa0: got 0x0)

NRK is not currently using subscriptions on matrices so that explains why we haven't seen this. I'm not sure if I can get this prioritised, and I'm also not very familiar with the workings of the asn1 library we use so I'm not sure how hard it is to fix.

Nico96R commented 9 months ago

Yes it is the same error. The error hasn’t changed since last year.

And I still have troubles querying the PowerCore Matrix. I get the following error: error.txt used this source code:

import {EmberClient} from "emberplus-connection";

const client = new EmberClient("10.20.33.62", 9001);

const initember = async (): Promise<any> => {
    client.on("error", e => {
        console.log(e);
    });
    await client.connect()
// Get Root info
    const req = await client.getDirectory(client.tree)

    return await req.response
}

const testMethod = async (path: string): Promise<any> => {

    return await client.getElementByPath(path, (v) => console.log(v)).then( node => {
        client.subscribe(node, n => console.log(n))
    })
}

//Path to PowerCore Matrix
initember().then(() =>
  testMethod("1.3.1").then((x => console.log(x))))

could you verify this behavior in your environment?

mint-dewit commented 9 months ago

Unfortunately NRK currently does not have the capacity to look at this issue further, as always we are more than happy to accept pull requests regarding this issue.

lukirs95 commented 1 month ago

I think #39 should fix this problem. It did for me. The problem is, that the current release doesn't send the "Get Directory" request down until the parameter. It only requests the parent of the of the last given path element.

If you requested path "1.2.3.4.5" and 5 is the parameter, the last "getDirectory()" was for node 4 instead of 5.