k-yle / sACN

💡 🎭 Send & Receive sACN data (DMX over IP) in node.js
https://npm.im/sacn
Apache License 2.0
31 stars 13 forks source link

Listen to single universes doesn't work #19

Closed schw4rzlicht closed 4 years ago

schw4rzlicht commented 4 years ago

Although I define universes to listen to in the constructor of Receiver, Receiver.on("packet", ...) is called for all received universes.

Is this expected behaviour?

k-yle commented 4 years ago

The universes you specify in the constructor will be the only ones that the Receiver listens to.

Let me know if it is still an issue with the latest version - the integration tests suggest that it is working correctly.

schw4rzlicht commented 4 years ago

Unless I don't understand how it should work, it still does it with 2.3.1. In my understanding the packet event should only be emitted for universes I set in the constructor? Or am I wrong there?

k-yle commented 4 years ago

In my understanding the packet event should only be emitted for universes I set in the constructor? Or am I wrong there?

You are correct.

It worked when I tested it: The lighting console broadcasted to universes 1 and 2, but in the constructor I only specified universe 1. Therefore, the packet event was only emitted for universe 1.

schw4rzlicht commented 4 years ago

Unfortunately it doesn't work for me. Using this sample code:

const { Receiver} = require('sacn');

const receiver = new Receiver({
    universes: [1, 2]
});

receiver.on("packet", (packet) => {
    console.log(`Received universe: ${packet.universe}`);
});

It doesn't matter which universes I send, the event is emitted for every single universe received.

EDIT Which makes total sense since you are not filtering packets in the message handler:

https://github.com/k-yle/sACN/blob/c60d835905d20fc6ee22b844f1b8d04ce2597839/src/main.ts#L47-L62

k-yle commented 4 years ago

I'm interested in what lighting console you're using -

We don't need to filter the received packets, because we only listen to specific multicast addresses. There is one adress for each universe, for example, universe 1 is 239.255.0.1, universe 2 is 239.255.0.2. So all packets sent to 239.255.0.1 should be universe 1.

If you specify universes: [1, 2], then it was listen to 239.255.0.1 and 239.255.0.2.

However, you are correct, I think we should add a filter. It's included in version 3.1.0

schw4rzlicht commented 4 years ago

We don't need to filter the received packets, because we only listen to specific multicast addresses.

Of course when using multicast. That's what I just figured, it failed for me because I'm using unicast.

However, you are correct, I think we should add a filter. It's included in version 3.1.0

And that fixed it! Thank you :)