Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dynamic modification of universes the server listens on #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ server.on('packet', function (packet) {
});
```

Universes to listen for can be added and droppped at any time by calling `addUniverse(universes)` or `dropUniverse(universes)`, respectively. The argument for these methods is an array of universe numbers.

## E1.31 (sACN) Packet Class

The E1.31 Packet class contains a number of useful setter methods:
Expand Down
18 changes: 18 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ Server.prototype.close = function close() {
this._socket.close();
};

Server.prototype.addUniverses = function(universes) {
universes.forEach(universe => {
if (this.universes.includes(universe)) return;
this.universes.push(universe);
this._lastSequenceNumber[universe] = 0;
this._socket.addMembership(e131.getMulticastGroup(universe));
});
};

Server.prototype.dropUniverses = function(universes) {
universes.forEach(universe => {
if (!this.universes.includes(universe)) return;
this.universes.splice(this.universes.indexOf(universe), 1);
delete this._lastSequenceNumber[universe];
this._socket.dropMembership(e131.getMulticastGroup(universe));
});
};

// server object inherits from EventEmitter
util.inherits(Server, EventEmitter);

Expand Down