diff --git a/README.md b/README.md index b6be7af..27e612b 100644 --- a/README.md +++ b/README.md @@ -55,14 +55,14 @@ Bonob will now auto-register itself with sonos on startup, updating the registra item | default value | description ---- | ------------- | ----------- BONOB_PORT | 4534 | Default http port for bonob to listen on -BONOB_WEB_ADDRESS | http://localhost:4534 | URL for bonob so that sonos devices can communicate +BONOB_WEB_ADDRESS | http://$(hostname):4534 | URL for bonob so that sonos devices can communicate. **This must be either the public IP or DNS entry of the bonob instance so that the sonos devices can communicate with it.** BONOB_SECRET | bonob | secret used for encrypting credentials BONOB_SONOS_AUTO_REGISTER | false | Whether or not to try and auto-register on startup BONOB_SONOS_DEVICE_DISCOVERY | true | whether or not sonos device discovery should be enabled BONOB_SONOS_SEED_HOST | undefined | sonos device seed host for discovery, or ommitted for for auto-discovery BONOB_SONOS_SERVICE_NAME | bonob | service name for sonos BONOB_SONOS_SERVICE_ID | 246 | service id for sonos -BONOB_NAVIDROME_URL | http://localhost:4533 | URL for navidrome +BONOB_NAVIDROME_URL | http://$(hostname):4533 | URL for navidrome BONOB_NAVIDROME_CUSTOM_CLIENTS | undefined | Comma delimeted mime types for custom navidrome clients when streaming. ie. "audio/flac,audio/ogg" would use client = 'bonob+audio/flac' for flacs, and 'bonob+audio/ogg' for oggs. ## Initialising service within sonos app diff --git a/package.json b/package.json index c11f69d..ce9f54a 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ }, "scripts": { "build": "tsc", - "dev": "BONOB_PORT=4000 BONOB_WEB_ADDRESS=http://$(hostname):4000 nodemon ./src/app.ts", + "dev": "BONOB_PORT=4000 nodemon ./src/app.ts", "test": "jest", "client-test": "ts-node tests/bonob_client.ts" } diff --git a/src/app.ts b/src/app.ts index 07a1490..07c01b4 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,3 +1,4 @@ +import { hostname } from "os"; import sonos, { bonobService } from "./sonos"; import server from "./server"; import logger from "./logger"; @@ -8,7 +9,12 @@ import { InMemoryLinkCodes } from "./link_codes"; const PORT = +(process.env["BONOB_PORT"] || 4534); const WEB_ADDRESS = - process.env["BONOB_WEB_ADDRESS"] || `http://localhost:${PORT}`; + process.env["BONOB_WEB_ADDRESS"] || `http://${hostname()}:${PORT}`; + +if (WEB_ADDRESS.match("localhost")) { + logger.error("BONOB_WEB_ADDRESS containing localhost is almost certainly incorrect, sonos devices will not be able to communicate with bonob using localhost, please specify either public IP or DNS entry"); + process.exit(1); +} const SONOS_DEVICE_DISCOVERY = (process.env["BONOB_SONOS_DEVICE_DISCOVERY"] || "true") == "true"; @@ -42,7 +48,7 @@ const app = server( bonob, WEB_ADDRESS, new Navidrome( - process.env["BONOB_NAVIDROME_URL"] || "http://localhost:4533", + process.env["BONOB_NAVIDROME_URL"] || `http://${hostname()}:4533`, encryption(secret), streamUserAgent ),