Skip to content

Commit

Permalink
Fixing SSDP discovery firewall problem due to port not bound
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalopitz committed Dec 8, 2016
1 parent c348c2b commit 7fca0b0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ This might require some additional binaries, like graphicsMagick and icnsutils,

You will need to whitelist these if you run Ubuntu firewall for example:

- UDP 1900
- UDP 1901
- TCP 3400
- TCP 1400
- TCP 1400 outgoing
- TCP 3400 incoming
- UDP 1900 outgoing
- UDP 1905 incoming

##Thanks to other projects

Expand Down
2 changes: 2 additions & 0 deletions src/ui/services/SonosService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import _ from 'lodash';
import bb from 'bluebird';
import xml2json from 'jquery-xml2json';

import Services from '../sonos/helpers/Services';

import Search from '../sonos/Search';
import Listener from '../sonos/events/listener';

Expand Down
16 changes: 10 additions & 6 deletions src/ui/sonos/Search.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
import Sonos from './Sonos';
import dgram from 'dgram';

import ip from './helpers/ip';

const SONOS_UPNP_BROADCAST_IP = '239.255.255.250';
const SONOS_UPNP_BROADCAST_PORT = 1900;
const SONOS_UPNP_RECEIVE_PORT = 1905;

class Search {

constructor (discoveryCallback, options={}) {
constructor (discoveryCallback, options={ port: SONOS_UPNP_RECEIVE_PORT }) {

var self = this;

this.foundSonosDevices = {};

var PLAYER_SEARCH = new Buffer(['M-SEARCH * HTTP/1.1',
'HOST: 239.255.255.250:reservedSSDPport',
'HOST: ' + SONOS_UPNP_BROADCAST_IP + ':reservedSSDPport',
'MAN: ssdp:discover',
'MX: 1',
'ST: urn:schemas-upnp-org:device:ZonePlayer:1'].join('\r\n'));


var sendDiscover = function () {
['239.255.255.250', '255.255.255.255'].map(function (addr) {
[SONOS_UPNP_BROADCAST_IP, '255.255.255.255'].map(function (addr) {
self.socket.send(PLAYER_SEARCH, 0, PLAYER_SEARCH.length, SONOS_UPNP_BROADCAST_PORT, addr);
});
// Periodically send discover packet to find newly added devices
self.pollTimer = setTimeout(sendDiscover, 10000)
self.pollTimer = setTimeout(sendDiscover, 10000);
}

this.socket = dgram.createSocket('udp4', function (buffer, rinfo) {
Expand All @@ -50,7 +48,13 @@ class Search {
});

this.socket.bind(options, function () {

// From: https://github.com/jishi/node-sonos-discovery/blob/94504305526f70b88a38e0e57b5be897a2b376dd/lib/sonos-ssdp.js
// This allows discovery through one router hop in a vlan environment
self.socket.setMulticastTTL(2);
// We set this in order to send 255.255.255.255 discovery requests. Doesn't matter for SSDP endpoint
self.socket.setBroadcast(true);

sendDiscover();
});

Expand Down
2 changes: 0 additions & 2 deletions src/ui/sonos/Sonos.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import Services from './helpers/Services';

const SONOS_PLAYER_DEFAULT_PORT = 1400;

window.Services = Services;

/**
* Constants
*/
Expand Down

0 comments on commit 7fca0b0

Please sign in to comment.