bencevans / node-sonos

🔈 Sonos Media Player Interface/Client

Home Page:https://www.npmjs.com/package/sonos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Device not found on deployed site using node-sonos

felixdasgupta opened this issue · comments

commented

DeviceDiscovery doesn't work for a deployed web application. No Sonos Device is found on the network.

Expected Behavior

A Device should be discovered when searching for the Device in this instance using DeviceDiscovery.

Current Behavior

Currently works in my local environment, but I've deployed my application. When I run this on a chrome browser the device is never discovered.

My application uses a Next.JS + React stack with express.

Possible Solution

Not 100% clear on how this works and I am definitely new to this. Do I need to set an environment variable here? How would I configure the production version to properly discover devices connected to an account etc.

This is more of a question, not a proposed solution, but I would appreciate all the help I can get here. Not clear on how DeviceDiscovery is actually working without being tied to any account or auth.

Sample code or executed example

This piece of code never works in the production instance.

const findDevice = DeviceDiscovery({ timeout });

findDevice.on("DeviceAvailable", async sonosDevice => {
      ....
})

Versions (and Environment)

Node version: "14.x"
node-sonos version: "^1.14.1"
OS: MacOS

commented

Just following up here, any idea on how I could better discover devices on a hosted application that uses node-sonos?

It seems to be searching for devices but it never seems to discover it properly and I don't see any kind of error message.
Would greatly appreciate some advice on this.

commented

It is running on the same wifi network yes, but still having issues discovering the device. It keeps searching but never finds it.

Any idea on how to force a discover on the same network using a groupId for a specific device potentially?

commented

Thanks in advance! @pascalopitz

commented

Does that mean passing an IP Address and a port on DeviceDiscovery({ port: PUBLIC_IP_ADDRESS + ":80" })?

Would greatly appreciate a code snippet or a link... this is an express + next.js project, but not quite clear on how to leverage the IP Address to find the device manually.

No, it would basically be the same as adding a known device:

const { Sonos } = require('sonos')

const device = new Sonos('192.168.1.56');

From there on you can query the topology etc

On the alpha release, see:

async getAllGroups () {

commented

@pascalopitz Appreciate the help so far! But having some issues getting this to work...

This is what my code looks like:

const device = new Sonos(address);
const zonesArray = await device.getAllGroups();

And this is the error I am getting when it's run:

error - unhandledRejection: Error: connect ECONNREFUSED {{address}}:1400
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)

Unfortunately it seems like the connection is being refused... not sure how to get around this. Have you ever encountered anything like this?

That is very much depending on your individual network topology, so can't comment

  1. the browser running your web application doesn't support UDP sockets. So multicast won't work for discovery
  2. The Sonos speakers don't support cors so you'll need to make a "backend" application, that is responsible on receiving messages from your website and the forwarding it to the Sonos devices

Something like:

react app talks to http server (to build) which talks to sonos.
@pascalopitz did something similar for his Linux Sonos app

commented

@svrooij Unfortunately I am using a backend server/app to try and connect to the Sonos Network using node.js/express.

Will try and debug, appreciate the help guys!