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

add option to specify the network interface ip #7

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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ var server = new e131.Server([universes], [port]);
```

The `universes` argument can be an array (for joining multiple universes) or a single integer for joining a single universe. If `universes` is omitted, a single value of `1` is assumed. If `port` is omitted, the default E1.31 port `5568` is used.

or

```javascript
var e131 = require('e131');
var server = new e131.Server({
universes: [universes], // Multiple universes
// universe: universe, // Single universe
port: 5568,
ip: '192.168.1.12' // IP of the network interface
});
```

All options are optional. Use either `universes` or `universe` but not both. The `ip` option is required when more than one network interface is present.

The server will join the corresponding Multicast groups for each provided universe automatically and starts listening as soon as it is created.
The server performs basic out-of-order detection on received packets. If an out-of-order packet is received, it is discarded.

Expand Down
24 changes: 19 additions & 5 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ function Server(universes, port) {
}
EventEmitter.call(this);

if (universes !== undefined && !Array.isArray(universes)) {
universes = [universes];
if (Object.prototype.toString.call(universes) === '[object Object]') {
var options = universes;
this.universes = options.universes || [options.universe] || [0x01];
this.port = options.port || e131.DEFAULT_PORT;
this.ip = options.ip;
} else {
if (universes !== undefined && !Array.isArray(universes)) {
universes = [universes];
}

this.universes = universes || [0x01];
this.port = port || e131.DEFAULT_PORT;
}
this.universes = universes || [0x01];
this.port = port || e131.DEFAULT_PORT;

this._socket = dgram.createSocket('udp4');
this._lastSequenceNumber = 0;

Expand Down Expand Up @@ -67,7 +76,12 @@ function Server(universes, port) {
this._socket.bind(this.port, function onListening() {
self.universes.forEach(function (universe) {
var multicastGroup = e131.getMulticastGroup(universe);
self._socket.addMembership(multicastGroup);

if (this.ip) {
self._socket.addMembership(multicastGroup, this.ip);
} else {
self._socket.addMembership(multicastGroup);
}
});
});
}
Expand Down