From 7fca0b09d7c771089479a8cce4c3dcf8f05d5af7 Mon Sep 17 00:00:00 2001 From: Pascal Opitz Date: Thu, 8 Dec 2016 18:46:40 +1030 Subject: [PATCH] Fixing SSDP discovery firewall problem due to port not bound --- README.md | 8 ++++---- src/ui/services/SonosService.js | 2 ++ src/ui/sonos/Search.js | 16 ++++++++++------ src/ui/sonos/Sonos.js | 2 -- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4bc03dc..04d56c2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/ui/services/SonosService.js b/src/ui/services/SonosService.js index 19045b7..c628208 100644 --- a/src/ui/services/SonosService.js +++ b/src/ui/services/SonosService.js @@ -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'; diff --git a/src/ui/sonos/Search.js b/src/ui/sonos/Search.js index 58d432d..a73b89f 100644 --- a/src/ui/sonos/Search.js +++ b/src/ui/sonos/Search.js @@ -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) { @@ -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(); }); diff --git a/src/ui/sonos/Sonos.js b/src/ui/sonos/Sonos.js index 1a07896..8b9a743 100644 --- a/src/ui/sonos/Sonos.js +++ b/src/ui/sonos/Sonos.js @@ -10,8 +10,6 @@ import Services from './helpers/Services'; const SONOS_PLAYER_DEFAULT_PORT = 1400; -window.Services = Services; - /** * Constants */