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

Device not found on deployed site using node-sonos #520

Open
felixdasgupta opened this issue Dec 23, 2021 · 11 comments
Open

Device not found on deployed site using node-sonos #520

felixdasgupta opened this issue Dec 23, 2021 · 11 comments

Comments

@felixdasgupta
Copy link

felixdasgupta commented Dec 23, 2021

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

@felixdasgupta felixdasgupta changed the title Device not found on product site Device not found on deployed site using node-sonos Dec 23, 2021
@felixdasgupta
Copy link
Author

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.

@pascalopitz
Copy link
Contributor

pascalopitz commented Dec 31, 2021 via email

@felixdasgupta
Copy link
Author

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?

@felixdasgupta
Copy link
Author

Thanks in advance! @pascalopitz

@pascalopitz
Copy link
Contributor

pascalopitz commented Dec 31, 2021 via email

@felixdasgupta
Copy link
Author

felixdasgupta commented Dec 31, 2021

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.

@pascalopitz
Copy link
Contributor

pascalopitz commented Dec 31, 2021

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 () {

@felixdasgupta
Copy link
Author

@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?

@pascalopitz
Copy link
Contributor

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

@svrooij
Copy link
Collaborator

svrooij commented Jan 4, 2022

  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

@felixdasgupta
Copy link
Author

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants